No description
Find a file
2020-10-10 10:48:49 +08:00
asyncmysql Add doc 2017-11-04 11:03:15 +08:00
doc New desc doc 2017-11-04 11:06:08 +08:00
test Add doc 2017-11-04 11:03:15 +08:00
.gitignore Add handshake auth 2017-07-15 15:31:02 +08:00
.travis.yml Add pool tools 2017-10-24 14:35:20 +08:00
asyncmysql.nim Add doc 2017-11-04 11:03:15 +08:00
asyncmysql.nimble New version 2017-11-04 11:10:58 +08:00
config.nims unblock https://github.com/nim-lang/Nim/pull/14887 2020-10-09 09:47:56 -07:00
LICENSE Add handshake auth 2017-07-15 15:31:02 +08:00
README.md New version 2017-11-04 11:10:58 +08:00
TODO.md Add more results check for query one 2017-08-11 20:10:46 +08:00

AsyncMysql Build Status

AsyncMysql is an asynchronous (None-Blocking) MySQL connector written in pure Nim.

Features

  • execute multiple SQL statements in a single query
  • streaming large result sets
  • commit and rollback transaction
  • connection pool

Examples


type
  Replies = seq[tuple[packet: ResultPacket, rows: seq[string]]]

proc execMyQuery(pool: AsyncMysqlPool, q: SqlQuery): Future[Replies] =
  var retFuture = newFuture[void]("execMyQuery")
  result = retFuture

  proc finishCb(err: ref Exception, replies: Replies) {.async.} =
    if err == nil:
      complete(retFuture, replies)
    else:
      fail(retFuture, err)

  execQuery(pool, q, finishCb)

proc main() {.async.} =
  let pool = await openMysqlPool(domain=AF_INET, 
                                 port=Port(3306), 
                                 host="127.0.0.1", 
                                 user="mysql", 
                                 password="123456", 
                                 database="mysql", 
                                 capacity=10)
  let query = sql("""
start transaction;
select host, user from user where user = ?;
select user from user;
commit;
""", "root")
  let replies = await pool.execMyQuery(query)

  echo ">> start transaction;"
  assert replies[0].packet.kind = rpkOk 

  echo ">> select host, user from user where user = ?;"
  assert replies[1].packet.kind = rpkResultSet
  echo replies[1].rows 

  echo ">> select user from user;"
  assert replies[2].packet.kind = rpkResultSet
  echo replies[2].rows 

  echo ">> commit;"
  assert replies[3].packet.kind = rpkOk

  pool.close()

API Documentation