Introduction to Djaq
Djaq - pronounced “Jack” - is an alternative to the Django QuerySet API.
What sets it apart:
No need to import models
Clearer, more natural query syntax
More powerful expressions for output
More powerful, easier-to-write filter expressions
More consistent query syntax without resorting to hacks like
F()
expressions,annotate()
,aggregate()
Column expressions are entirely evaluated in the database
Extensible: you can write your own functions
Pandas: Easily turn a query into a Pandas Dataframe
There is also a JSON representation of queries, so you can send queries from a client. It’s an instant API to your data. No need to write backend classes and serializers.
Djaq queries are strings. A query string for our example dataset might look like this:
DQ("Book", "name as title, publisher.name as publisher").go()
This retrieves a list of book titles with book publisher. But you can formulate far more sophisticated queries; see below. You can send Djaq queries from any language, Java, Javascript, golang, etc. to a Django application and get results as JSON. In contrast to REST frameworks, you have natural access to the Django ORM from the client.
Djaq sits on top of the Django ORM. It can happily be used alongside QuerySets.
Contents:
- Installation
- Settings
- Query usage guide
- API Reference
- context(context: Dict) -> DjaqQuery
- conditions(node: B) -> DjaqQuery
- count() -> int
- csv()
- get(pk_value: any) -> Model
- go()
- distinct()
- dicts()
- json()
- limit(limit: int) -> DjaqQuery
- objs()
- offset(offset: int) -> DjaqQuery
- map(result_type: Union[callable, dataclasses.dataclass], data=None)
- order_by() -> DjaqQuery
- qs() -> QuerySet
- rewind() -> DjaqQuery
- schema -> Dict
- schema_all(connection=None) -> Dict
- sql() -> str
- tuples()
- update_object(pk_value: any, update_function: callable, data: Dict, save=True)
- value()
- where(node: Union[str, B]) -> DjaqQuery
- Djaq Management Command
- Result Formats
- Pandas DataFrame
- Conditions
- Functions
- Column expressions
- Subqueries and
in
Clause - Order by
- TRUE, FALSE, NULL, Empty
- Datetimes
- Count
- Offset, Limit, Paging, Slicing
- Schema
- Comparing to Django QuerySets
- Parameters and Validator
- Query UI
- Remote API
- Limitations
- Performance
- Sample Bookshop Project