
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
add asyncio sqlalchemy support
pip install async-sqlalchemy
import asyncio
from sqlalchemy import Integer, Column, String, ForeignKey
from async_sqlalchemy.manager.async_pg import PostgresManager
from async_sqlalchemy.model.mixin import Mixin
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from sqlalchemy.sql import select
dsn = "postgres://postgres:test@localhost:2345/test"
conf = {'dsn': dsn}
Base = declarative_base()
Manager = PostgresManager(conf=conf)
class User(Mixin, Base):
_manager = Manager
__tablename__ = 'test'
id = Column(Integer, autoincrement=True, primary_key=True)
name = Column(String(50))
def __repr__(self):
return "<User(name='%s', id='%s')>" % (
self.name, self.id)
class Parent(Mixin, Base):
__tablename__ = 'parent'
_manager = Manager
id = Column(Integer, primary_key=True)
child = relationship("Child", lazy='joined')
class Child(Mixin, Base):
_manager = Manager
__tablename__ = 'child'
id = Column(Integer, primary_key=True)
parent_id = Column(Integer, ForeignKey('parent.id'))
parent = relationship("Parent", back_populates="child")
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(Manager.connect())
result = loop.run_until_complete(Manager.get(
User.objects([User.id]).join(
Parent.__table__,
Parent.id == User.id)))
print(result)
# result = loop.run_until_complete(Child.create_table())
# print(result)
# u = loop.run_until_complete(User.create(name='test'))
# print('create', u)
# print('get', loop.run_until_complete(User.get(name='test')))
# print('all', loop.run_until_complete(User.all()))
# u.name = 'aaa'
# print('save', loop.run_until_complete(u.save()))
The asyncnsq is offered under MIT license.
FAQs
asyncio sqlalchemy support
We found that async-sqlalchemy demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.