Skip to main content

A module that implements a more Django like interface for SQLAlchemy

Project description

sqlalchemy-django-query

tests black

A module that implements a more Django like interface for SQLAlchemy (currently < 1.4) query objects. It's still API compatible with the regular one but extends it with Djangoisms.

Example

class Base(object):
    @declared_attr
    def __tablename__(cls):
        return cls.__name__.lower()

    id = Column(Integer, primary_key=True)

Base = declarative_base(cls=Base)

class Blog(Base):
    name = Column(String)
    entries = relationship('Entry', backref='blog')

class Entry(Base):
    blog_id = Column(Integer, ForeignKey('blog.id'))
    pub_date = Column(Date)
    headline = Column(String)
    body = Column(String)


engine = create_engine('sqlite://')
Base.metadata.create_all(engine)

# session with our class
session = Session(engine, query_cls=DjangoQuery)
session.query(Blog).filter_by(name__exact='blog1').one()
session.query(Blog).filter_by(name__contains='blog').all()
session.query(Entry).filter_by(pub_date__year=2011).one()
session.query(Blog).filter_by(entries__headline__exact='b2 headline 2').one()

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

sqlalchemy-django-query-0.2.2.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

sqlalchemy_django_query-0.2.2-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file sqlalchemy-django-query-0.2.2.tar.gz.

File metadata

File hashes

Hashes for sqlalchemy-django-query-0.2.2.tar.gz
Algorithm Hash digest
SHA256 23a4b1e0c472dd6e4d3fae1ef68c7a6dd8d0c8ed3aede2207f297763c84dcc30
MD5 4f5360edc5e7783def6819c27df59205
BLAKE2b-256 7086917aa33b8365e54ae2aab746955300e93a61030c33e3ba7c98ea44bbbb61

See more details on using hashes here.

File details

Details for the file sqlalchemy_django_query-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for sqlalchemy_django_query-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 48e7782a411fdc00ce46c8b9f12dceccb1f17fa4cb4bd57150fe5dc7ef09a2f8
MD5 d98450f0c8039fa1ccb7cdbf215bd49f
BLAKE2b-256 d56f4c41d3978c0cdbe2b3f73fb79cc279b31d0ae01b605ab740e6ad487a5951

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