Skip to main content

Small and partial Obejct mapper on top of sqlalchemy for async

Project description

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.2.0

  • Fix bug on column.defaults

0.1.9

  • Added Column default and onupdate on update and add (only for scalar values and callables)
  • Added small proxy method 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asyncom-0.2.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

asyncom-0.2.0-py2.py3-none-any.whl (6.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file asyncom-0.2.0.tar.gz.

File metadata

  • Download URL: asyncom-0.2.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0

File hashes

Hashes for asyncom-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9c19d7eb0e95d70643882d076d2fe803b5b3af09130f368571fc2c891ab6b5d3
MD5 6cc4bee7dc83597fd018d6fd099d0f06
BLAKE2b-256 b911466baf63262dc2f4551d97eba0d22541242e63e2ed2d14ee43af49457527

See more details on using hashes here.

File details

Details for the file asyncom-0.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: asyncom-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0

File hashes

Hashes for asyncom-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 6e5d00465a7afa8fdbeb491dfcb5a911bd3dcd7e59b1c814b6a5999b20347cb5
MD5 37d815304c2be437fa686314c1dd416b
BLAKE2b-256 e7f488b0761bf7cf785071eb966c7da2d4c43290375dfda0f8a969063e876a8d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page