Skip to content

A query building extensions for sqlalchemy with encode/databases to apply pagination, filter, search and sorting to query

License

Notifications You must be signed in to change notification settings

chapagainmanoj/databases-extensions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

databases-query-extensions

An query building extensions for sqlalchey with encode/databases to apply pagination, filter, search and sorting to query

Installation

pip install databases-extensions

Example

Construct page params

page_params = PaginationParams.construct(
      first=3, filter={"completed.is_true": ""}
  )

apply cursor pagination and get results

  from extensions import CursorPagination
  ...
  query = example.select()
  pagination = CursorPagination(database, query)
  paginated = await pagination.page(page_params)

apply filters, search, sorting or pagination and get query

    from extensions import query_builder
    ...
    query = example.select()
    cursor_column="created_date"
    query = query_builder(query, page_params, cursor_column)

A complete query params example

{
    "first": 100,
    "after": <cursor>,
    "afterWith": <cursor>,
    "search": {
      "columns": ["col1", "col2"],
      "value": "new"
    },
    "filter": {
      "status.eq": "Pending"
    },
    "sort": "createdAt",
    "order": "asc"
  }

About

A query building extensions for sqlalchemy with encode/databases to apply pagination, filter, search and sorting to query

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages