Python Sqlalchemy 2.0 based serverside processing for jQuery datatables.
Project description
sqlalchemy2-datatables
Source Code: https://github.com/coding-doc/sqlalchemy2-datatables
Summary
sqlalchemy2-datatables is a framework agnostic library providing an SQLAlchemy integration of jQuery DataTables >= 1.10, and helping you manage server side requests in your application.
Inspiration
This project was inspired by sqlalchemyw-datatables developed by Michel Nemnom aka Pegase745.
Motivation
Given the sunstantial changes with SQLAlchemy 2.0 most of not all of the SQLAlchemy based datatables serverside solution will be outdated soon (labeit currently still supported in SQLAlchemy 1.4). Specifically deprecation of sqlalchemy.orm.Query will render those packages obsolete. SQLAlchemy2.0.
Installation
pip install sqlalchemy2-datatables
Examples
Generic CRUD style function:
from typing import Any
from sqlalchemy import Engine
from sqlalchemy import FromClause
from datatables import DataTable
from datatables.base import DTDataCallbacks
def get_datatable_result(
params: dict[str, Any],
table: FromClause,
column_names: list[str],
engine: Engine,
callbacks: DTDataCallbacks | None,
) -> dict[str, Any]:
"""
Get database results specifically formatted for a display via jQuery datatables.
:param params: dict - request parameters
:param table: FromClause - the sqlalchemy from clause
:param column_names - List of column names reflecting the table columns in the desired order
:param engine: Engine - the sqlalchemy engine
:param callbacks - datatables callbacks to populate jQuery datatables DT_* attributes
:return dict with DataTable output for the jQuery datatables in the frontend view
"""
datatable: DataTable = DataTable(
request_params=params, table=table, column_names=column_names, engine=engine, callbacks=callbacks
)
return datatable.output_result()
this will produce the dictionary that can be serialized and returned to jQuery datatables.
{
"start": 0,
"length": 5,
"draw": 1,
"recordsTotal": 1341,
"recordsFiltered": 1341,
"data": [
{
"id": 1,
"col1": "value",
"col2": "value",
"col3": "value",
"col4": "value",
},
{
"id": 2,
"col1": "value",
"col2": "value",
"col3": "value",
"col4": "value",
},
{
"id": 3,
"col1": "value",
"col2": "value",
"col3": "value",
"col4": "value",
},
{
"id": 4,
"col1": "value",
"col2": "value",
"col3": "value",
"col4": "value",
},
{
"id": 5,
"col1": "value",
"col2": "value",
"col3": "value",
"col4": "value",
},
],
}
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
Built Distribution
File details
Details for the file sqlalchemy2_datatables-0.5.1.tar.gz
.
File metadata
- Download URL: sqlalchemy2_datatables-0.5.1.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.10.8 Darwin/22.2.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1790162b8c2633f341b7b253d25bdf643894d5751feddc84312e4fe92cd5468e |
|
MD5 | 498e45ba615616049a32188ed8c5dc47 |
|
BLAKE2b-256 | 801b397535f8766e2d3f04e5414897c1bc142f79b860f20a6549e8c110042d04 |
File details
Details for the file sqlalchemy2_datatables-0.5.1-py3-none-any.whl
.
File metadata
- Download URL: sqlalchemy2_datatables-0.5.1-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.2 CPython/3.10.8 Darwin/22.2.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6bc1244b9353567fe4558d9268e8e16e3a029bc9928b4fd1d4822f2f6077db14 |
|
MD5 | f59ba49210f516e876dfc187e519b7b1 |
|
BLAKE2b-256 | d235faff52533510efceddbd392490fbb2b0aeb1a96cdd32e55fe3185790ee05 |