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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

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