Giter Site home page Giter Site logo

asyncmysql's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.