Skip to main content

AsyncOM

Async OM it's a super basic Object mapper based almost all on sqlalchemy ORM layer.

We use the declarative extension for building the classes, and also, factor instances of them on querys. (*Limited support)

There is still no support for relations.

Depens on encode/databases dependency.

Motivation

I don't like the asyncpgsa approach where they are just using, the core layer, to build run the sqlgenerator. I like to build, around the declarative layer of sqlachemy, and later found that I can patch some of the methods on the session.query, to use it's own sql generator, and turn async the query system.

Object persistent is minimal, and needs some love.

Usage

from sqlalchemy.ext.declarative import declarative_base
import sqlalchemy as sa
from databases import DatabaseURL

Base = declarative_base()


class OrmTest(Base):
    __tablename__ = 'orm_test'

    id = sa.Column(sa.Integer, primary_key=True)
    name = sa.Column(sa.String(100), index=True)
    value = sa.Column(sa.Text)

# Instead of usign Database from databases, you can use:
db = OMDatabase(DatabaseURL('postgres://root@postgres:{port}/guillotina'))

# instances of the object can be created with:
test = OrmTest(name='xx', value='yy')
await db.add(test)

print(test.id)  # pk column is correct set

# get an instance
ins = await db.query(OrmTest).get(1)

total = await db.query(OrmTest).count()
assert total == 1

# remove it
await db.delete(ins)

# filter them
res = await db.query(OrmTest).filter(
    OrmTest.name.like('xx')).all()

# Or just iterate over the results with a cursor:
async for row in db.query(OrmTest).filter(OrmTest.name.like('xx')):
    print(f'Row {row.name}: {row.value}')


# There is basic support for table inheritance query OneToOne


# Look at tests

Changelog

0.3.3

  • Fix collections import for Python 3.10

0.3.2

  • Support query multiple primary keys

0.3.1

  • Be able to provide mapper_factory to OMQuery [vangheem]

0.3.0

  • Fix bug with om.delete an inherited objects

0.2.3

  • Fix boolean expr on adding prods. Allowing to add values with 0

0.2.1

  • Small fix when checking none on json fields arrays

0.1.9

  • Added Column default and onupdate on update and add (only for scalar values and callables)
  • Added small proxy prop on OMDatabaes, to raw asyncpg connection

0.1.8

  • Yaml data importer

0.1.7

  • Support adding basic inherited models

0.1.6

  • query should be an async iterator

0.1.5

  • Load inherited models.

0.1.4

  • query(Object).get should return None if not found

0.1.3

  • Fixes and improvements. Lay out basic API

0.1.0 (2019-04-07)

  • First release on PyPI.

Release files for asyncom 0.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for asyncom 0.3.3
File Size Uploaded
asyncom-0.3.3.tar.gz 11.5 kB Details

Release files / asyncom-0.3.3.tar.gz

Download URL asyncom-0.3.3.tar.gz
Size 11.5 kB
Tags Source
SHA-256 checksum
How to use checksums
4857b40accf54097a60cfb86dcfc721ae62dd88c683809c1a2733caec0b45cac
BLAKE2b-256 checksum
How to use checksums
5e2d90aa17b48290edae53e98395fbf1862c4d3d8be0fdafcb89b08e875175e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.1

Release history Release notifications | RSS feed

This release

0.3.3 This release

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.6

1 release file

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page