SQL Query Builder inspired on django ORM Syntax
Project description
SQL Query Builder based on django ORM
=====================================
What's that?
-----------
Is a library that you can use to build sql queries if your are accustomed to use Django ORM
How to use
----------
There are 4 main objects Q, F, QuerySet and SQLModel.
Using it
---------------
.. code-block:: python
from sqlquerybuilder import SQLModel, Queryset, Q, F
class Client(SQLModel):
table = "clients"
Client.objects.filter(name="Jhon").exclude(lastname="Doe").group_by("family")
sql = Queryset("clients").filter(name="Jhon").exclude(lastname="Doe").group_by("family")
sql = Client.objects.filter(Q(name="John") & ~Q(lastname="Doe"))
sql.group_by("family")
sql = Queryset("users")\
.filter(nombre="jose")\
.order_by( "nombre", "-fecha")\
.filter(fecha__lte=F("now()"))[:10]
"SELECT * FROM users WHERE ((nombre='jose') AND (fecha<=now())) ORDER BY nombre, fecha DESC LIMIT 10"
Queryset("usuarios").values("name").extra({'select': 'count(*) as total'})
"SELECT name , count(*) as total FROM usuarios"
=====================================
What's that?
-----------
Is a library that you can use to build sql queries if your are accustomed to use Django ORM
How to use
----------
There are 4 main objects Q, F, QuerySet and SQLModel.
Using it
---------------
.. code-block:: python
from sqlquerybuilder import SQLModel, Queryset, Q, F
class Client(SQLModel):
table = "clients"
Client.objects.filter(name="Jhon").exclude(lastname="Doe").group_by("family")
sql = Queryset("clients").filter(name="Jhon").exclude(lastname="Doe").group_by("family")
sql = Client.objects.filter(Q(name="John") & ~Q(lastname="Doe"))
sql.group_by("family")
sql = Queryset("users")\
.filter(nombre="jose")\
.order_by( "nombre", "-fecha")\
.filter(fecha__lte=F("now()"))[:10]
"SELECT * FROM users WHERE ((nombre='jose') AND (fecha<=now())) ORDER BY nombre, fecha DESC LIMIT 10"
Queryset("usuarios").values("name").extra({'select': 'count(*) as total'})
"SELECT name , count(*) as total FROM usuarios"
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file sqlquerybuilder-0.0.13.tar.gz
.
File metadata
- Download URL: sqlquerybuilder-0.0.13.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 461c2b70aa867ca81a7f61bc19884b8cb3344e5070180f97c9580d28a202f4ae |
|
MD5 | 1fa9454e092966d24cb03ddc6790cffd |
|
BLAKE2b-256 | 1ae411ad634b1cde1ffc2ba10909dd3e33439c3bd2063254bd7d9a9334929c22 |