Skip to main content

(SQLAlchemy - ORM) + Twisted = win

Project description

alchimia lets you use most of the SQLAlchemy-core API with Twisted, it does not allow you to use the ORM.

Getting started

from alchimia import TWISTED_STRATEGY

from sqlalchemy import (
    create_engine, MetaData, Table, Column, Integer, String
)
from sqlalchemy.schema import CreateTable

from twisted.internet.defer import inlineCallbacks
from twisted.internet.task import react


@inlineCallbacks
def main(reactor):
    engine = create_engine(
        "sqlite://", reactor=reactor, strategy=TWISTED_STRATEGY
    )

    metadata = MetaData()
    users = Table("users", metadata,
        Column("id", Integer(), primary_key=True),
        Column("name", String()),
    )

    # Create the table
    yield engine.execute(CreateTable(users))

    # Insert some users
    yield engine.execute(users.insert().values(name="Jeremy Goodwin"))
    yield engine.execute(users.insert().values(name="Natalie Hurley"))
    yield engine.execute(users.insert().values(name="Dan Rydell"))
    yield engine.execute(users.insert().values(name="Casey McCall"))
    yield engine.execute(users.insert().values(name="Dana Whitaker"))

    result = yield engine.execute(users.select(users.c.name.startswith("D")))
    d_users = yield result.fetchall()
    # Print out the users
    for user in d_users:
        print "Username: %s" % user[users.c.name]

if __name__ == "__main__":
    react(main, [])

Limitations

There are some limitations to alchimia's ability to expose the SQLAlchemy API.

  • Some methods simply haven’t been implemented yet. If you file a bug, we’ll implement them! See CONTRIBUTING.rst for more info.

  • Some methods in SQLAlchemy either have no return value, or don’t have a return value we can control. Since most of the alchimia API is predicated on returning Deferred instances which fire with the underlying SQLAlchemy instances, it is impossible for us to wrap these methods in a useful way. Luckily, many of these methods have alternate spelling. The docs call these out in more detail.

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

alchimia-0.2-dev.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

alchimia-0.2_dev-py2.py3-none-any.whl (5.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file alchimia-0.2-dev.tar.gz.

File metadata

  • Download URL: alchimia-0.2-dev.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for alchimia-0.2-dev.tar.gz
Algorithm Hash digest
SHA256 544d3d23871495ed24638cd37e714e97cb601842d64476b9596db49aeaaa6385
MD5 6de51d022d45d649f4d3c5e7d4aba96a
BLAKE2b-256 b2ff14818eef6550449f0a41f1a3eec7af4e81f2deac42ee442b874a6de6f31f

See more details on using hashes here.

Provenance

File details

Details for the file alchimia-0.2_dev-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for alchimia-0.2_dev-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8216b9a65c63555d2cb78514bddaae3bfbda7ac7448f3d9c952b3baf3f5814ac
MD5 7967439f58c7d21855b4fdc45730345c
BLAKE2b-256 0db9a346be42d50cb9d63665b596262c08cf4608ead62349b9295c87a758f2ae

See more details on using hashes here.

Provenance

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