Skip to main content

Query helper for sql alchemy

Project description

SQLAlchemy query helper

Usage

class User(Base):
    id = Column(Integer, primary_key=True)
    name = Column(String)
    fullname = Column(String)
    nickname = Column(String)
    timestamp = Column(DateTime)
    addresses = relationship("Address")

class Address(Base):
    id = Column(Integer, primary_key=True)
    title = Column(String)
    description = Column(String)
    user_id = Column(Integer, ForeignKey("user.id"))

from sqlalchemy_query_helper.query_generator import generate_query

# it will return sql alchemy query object
query=generate_query(session,User,{
    "name":{"op":"eq","value":"john"},
    "addresses":{"title":{"op":"neq":"value":"new york city"}}
})
# this query is equivalent to below
"""
SELECT user.*,address.* from user
join address on address.user_id=user.id
where user.name='john' and address.title!='new york city'
"""
# notice that it will load joined table if it is in the query.
# There is no select option yet

Available operations

  • eq (equals)
  • neq (not equals)
  • gt (greater than)
  • gte (greater than equals)
  • lt (less than)
  • lte (less than equals)

More

  • Accepts date times as iso format and will convert to python datetime automatically.

Development

  • Install pipenv

  • make install

  • Make your changes and open PR

Test

  • Install sqllite3

  • make test

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-query-helper-0.0.5.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sqlalchemy_query_helper-0.0.5-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file sqlalchemy-query-helper-0.0.5.tar.gz.

File metadata

  • Download URL: sqlalchemy-query-helper-0.0.5.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.7

File hashes

Hashes for sqlalchemy-query-helper-0.0.5.tar.gz
Algorithm Hash digest
SHA256 f700bc3f9e99b9996363b5a64d4c45b2973fed3a64499f08d63371a562cc8a94
MD5 235ce08b77779a049bb2d778f7da3920
BLAKE2b-256 e55127607e0d3d28a3c11a0d9d0d96eff9fa35db7dd9d67db14d8b170f5943e5

See more details on using hashes here.

File details

Details for the file sqlalchemy_query_helper-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: sqlalchemy_query_helper-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.7

File hashes

Hashes for sqlalchemy_query_helper-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 315fe85e6251804734dcc08073b22a91e90c94906c84e1d8e41ff9c4cc3de47b
MD5 68baea8f8734fa1fb381f9aea6600a31
BLAKE2b-256 984567fce8b00b6cf3489166762356e710b69673fb56c0d47e619549f7124a32

See more details on using hashes here.

Supported by

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