Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tulayang/asyncmysql
Asynchronous MySQL connector written in pure Nim.
https://github.com/tulayang/asyncmysql
Last synced: 3 months ago
JSON representation
Asynchronous MySQL connector written in pure Nim.
- Host: GitHub
- URL: https://github.com/tulayang/asyncmysql
- Owner: tulayang
- License: mit
- Created: 2017-07-08T08:42:13.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-10-10T02:48:50.000Z (about 4 years ago)
- Last Synced: 2024-05-18T14:34:20.710Z (6 months ago)
- Language: Nim
- Size: 176 KB
- Stars: 11
- Watchers: 3
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-nim - asyncmysql - Asynchronous MySQL connector written in pure Nim. (Data / Database)
README
# AsyncMysql [![Build Status](https://travis-ci.org/tulayang/asyncmysql.svg?branch=master)](https://travis-ci.org/tulayang/asyncmysql)
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
```nim
type
Replies = seq[tuple[packet: ResultPacket, rows: seq[string]]]proc execMyQuery(pool: AsyncMysqlPool, q: SqlQuery): Future[Replies] =
var retFuture = newFuture[void]("execMyQuery")
result = retFutureproc 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 = rpkOkecho ">> select host, user from user where user = ?;"
assert replies[1].packet.kind = rpkResultSet
echo replies[1].rowsecho ">> select user from user;"
assert replies[2].packet.kind = rpkResultSet
echo replies[2].rowsecho ">> commit;"
assert replies[3].packet.kind = rpkOkpool.close()
```[API Documentation](http://tulayang.github.io/asyncmysql/index.html)