Skip to main content

Python Sqlalchemy 2.0 based serverside processing for jQuery datatables.

Project description

sqlalchemy2-datatables

versions license Python package

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 sqlalchemy-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()

The output dictionary that can be serialized and returned to jQuery datatables.

{
    "start": 0,
    "length": 5,
    "draw": 1,
    "recordsTotal": 1000,
    "recordsFiltered": 1000,
    "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",
        },
    ],
}

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqlalchemy2_datatables-0.5.2.tar.gz (9.2 kB view details)

Uploaded Source

Built Distributions

sqlalchemy2_datatables-0.5.2-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

sqlalchemy2_datatables-0.5.2-py2.py3-none-any.whl (6.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file sqlalchemy2_datatables-0.5.2.tar.gz.

File metadata

  • Download URL: sqlalchemy2_datatables-0.5.2.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

Hashes for sqlalchemy2_datatables-0.5.2.tar.gz
Algorithm Hash digest
SHA256 391562761175e291c8fc99401ae15e11e620644ac9cb3224e19733906fb30c8c
MD5 a4b22c400f7c123a41a19ce6086576d3
BLAKE2b-256 4c1ef6b8e2e0f2c706afcfdd7b6b60ab179f6fba7d53bf32d1c1b93fd1d82673

See more details on using hashes here.

File details

Details for the file sqlalchemy2_datatables-0.5.2-py3-none-any.whl.

File metadata

File hashes

Hashes for sqlalchemy2_datatables-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cc5c29c1e21446ea162b6e89f0aac38deeb93b4b5e90a3fa92571efb690202c2
MD5 bac71840991b65049f8b703184545a16
BLAKE2b-256 2444a7a6224a3a9890789522656560988ab701b6bb4eec974dada042ace79459

See more details on using hashes here.

File details

Details for the file sqlalchemy2_datatables-0.5.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for sqlalchemy2_datatables-0.5.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 144d277f831f48d904fb2a55cce4cefbf68db87591142122e733a521e822b7cc
MD5 640882a7bd81f49cbee5295cd6cab7a2
BLAKE2b-256 462b380668a670365c2f63af735aebf95580c401c9183221985be0f07aee7a36

See more details on using hashes here.

Supported by

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