Git Product home page Git Product logo

asyncpg's Introduction

asyncPG Build Status Build status

Asynchronous PostgreSQL driver for Nim Language http://www.nim-lang.org

Main features

  • Pure asynchronous implementation, based on LibPQ and Nim's async core
  • Support for many SQL statements/results in one request
  • Ability to send parameters separately from query, thus avoiding the need for tedious and error-prone quoting and escaping
  • Automatic type conversion for basic Nim types
  • Sending and receiving COPY data
  • ARRAYS and JSON/JSONB support
  • Asynchronous Notification

Installation

You can use Nim official package manager nimble to install asyncpg. The most recent version of the library can be installed via:

$ nimble install asyncpg

or directly from Github repository

$ nimble install https://github.com/cheatfate/asyncpg.git

Minimal requirements

  • PostgreSQL 9.x (if you want to have support for JSONB types, you need PostgreSQL 9.4 at least)
  • Nim language compiler 0.14.2

Documentation

You can find documentation in Wiki.

ToDo

  • Add objects to automatic type conversion
  • Add support for binary COPY data

asyncpg's People

Contributors

cheatfate avatar huaxk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

asyncpg's Issues

.rows() segfaults

.getRows(-1) works fine, but .rows() segfaults; am I using this correctly?

withConnection(dbPool, conn):
  var res = await conn.exec("select col, id from stuff limit 10")
  for row in res[0].rows():
     echo row
Traceback (most recent call last)
web.nim(18)              web
asyncdispatch.nim(1000)  runForever
asyncdispatch.nim(991)   poll
apg_core.nim(446)        cb
asyncfutures.nim(109)    complete
asyncmacro.nim(34)       cb
apg_core.nim(509)        matchIter
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

line 509 is calling setLen(r[col], 0) for a little more context.

cannot recieve notify from another connection.

Notify can only recieve when sendNotify is send through the same connection with the notify.

proc testConnectionNotify(conn, conn2: apgConnection): Future[bool] {.async.} =
  var r1 = false
  var r2 = false
  await conn.listenNotify("testChannel")
  var notifyFuture1 = conn.notify("testChannel")
  await conn2.sendNotify("testChannel", "payload")
  #await conn.sendNotify("testChannel", "payload")
  var sleepFuture1 = sleepAsync(100)
  await notifyFuture1 or sleepFuture1
  if notifyFuture1.finished:
    echo notifyFuture1.read.payload
    r1 = true
    return true
  else:
    echo "failed"
    return false

how can'I get message from notification listener

Sorry I'm a freshman of nim-lang, I'm tring to implement a postgresql client which can listen to the notification from server, and now I'm wondering how can I get the notify message from the listenNotify proc, I'm trying to use var result = listenNotify(dbConn, "test") but with compiler error

If making more requests then in a pool, odd errors happen.

Pool size of 10 works, pool size of 5 does not.

import asyncdispatch, asyncpg/asyncpg

const POOL_SIZE = 5
var pool = newPool(POOL_SIZE)

proc main() {.async.} =
  var start: float
  var connStr = "host=localhost port=5432 dbname=test user="
  await pool.connect(connStr)
  var futures = newSeq[Future[apgResult]]()
  for i in 0..<10:
    futures.add exec(pool, "SELECT $1, pg_sleep(1);", i)
  var results = await all(futures)
  for res in results:
    for item in res[0].rows():
      echo item, " "

waitFor main()

Starts 10 connections that sleep for 10 seconds. If pool size is less the number of connections strange error happens:

asyncpgtest.nim(18)      asyncpgtest
asyncdispatch.nim(1654)  waitFor
asyncdispatch.nim(1514)  poll
asyncdispatch.nim(1233)  runOnce
Error: unhandled exception: No handles or timers registered in dispatcher. [ValueError]

I think if connections are not available it should error out or wait some how. I think it just forgets to register no available connection case.

Nim Compiler Version 0.19.1 [MacOSX: amd64]
Compiled at 2018-10-22
Copyright (c) 2006-2018 by Andreas Rumpf

git hash: 16c3d4332fac56b275ca3c66dcf12573738bdc91
active boot switches: -d:release

Notify function on apgPool may not be correct.

Because the listen/notify connection must be the same, and using apgPool doesn't promise it, so it is not proper when using apgPool to listen and notify, because they will get the different connection.

Support for Nim stable version 1.x.x

With this issue I would like to ask if this repo is still being actively maintained. I see there is a PR to support Nim 0.19.0 which is already quite old.

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.