GINO 0.6 - asyncio ORM with SQLAlchemy core and asyncpg

249 views
Skip to first unread message

Fantix King

unread,
Mar 14, 2018, 7:11:57 AM3/14/18
to python-tulip
Hi,

I'm pleased to release a new big version (0.6) of GINO - a lightweight ORM built on top of SQLAlchemy core and asyncpg for asyncio.


* BSD license
* The motivation was to make life easier in a context where async DB access was essential
* [NEW] Async SQLAlchemy-alike engine and connection with async dialect API
* Async-friendly objective model for CRUD, a simplified ORM
* Support Sanic and Tornado
* Works with Alembic for migration management
* [NEW] Documentation and 96% test coverage

Code example:

from gino import Gino

db
= Gino()


class User(db.Model):
    __tablename__
= 'users'

    id
= db.Column(db.Integer(), primary_key=True)
    nickname
= db.Column(db.Unicode(), default='noname')


async
def main():
    async
with db.with_bind('asyncpg://localhost/gino'):

       
# Create tables
        await db
.gino.create_all()

       
# Create object, `id` is assigned by database
        u1
= await User.create(nickname='fantix')
       
print(u1.id, u1.nickname) # 1 fantix

       
# Execute complex statement and return command status
        status
, result = await User.update.values(
            nickname
='No.' + db.cast(User.id, db.Unicode),
       
).where(
           
User.id > 10,
       
).gino.status()
       
print(status) # UPDATE 8

       
# Iterate over the results of a large query in a transaction
        async
with db.transaction():
            async
for u in User.query.order_by(User.id).gino.iterate():
               
print(u.id, u.nickname)


Suggestions and comments are greatly welcome!

BR,
Fantix
Reply all
Reply to author
Forward
0 new messages