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
Built Distribution
Close
Hashes for sqlalchemy-query-helper-0.0.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a20a90a6e1b93e929a33ca82913cac15ac792365f20046e23bb8fbee4da7722 |
|
MD5 | 19dca5cc00fbd3fc44da08f7c386ca32 |
|
BLAKE2b-256 | 7fdd9d2fc6809ffd1ecd2c26809960ef14892953d3287eb6ce9ac2f6f7fb0e25 |
Close
Hashes for sqlalchemy_query_helper-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1dcd74c490974b8f5fe4fd2c9cfa40946c19299487256397cee8a24fe70c811e |
|
MD5 | 30da0cbd165e29ecc61ec633daaf6eee |
|
BLAKE2b-256 | fa2a4c27f2b7957f33770505ecae430138b0902c44177d1058dccc8fa2b8a605 |