Skip to main content

Converts HTTP URL query string parameters to flask_sqlalchemy query results

Project description

Description

A simple decorator to speed up development using flask_sqlalchemy, place the decorator pass the model and done! it works!

Usage/Examples

Place the @filter_query passing the model as argument and enjoy!

Usage example on users endpoint with Users model:

@users.route('/users', methods=["GET"])
@filter_query(Users)
def get_users(*args, **kwargs):
    return make_response(jsonify(kwargs.get('data')), total=kwargs.get('total')), 200)

then you can make a http request passing arguments:

curl --location 'http://127.0.0.1:5000/users?email__like__=%gabriel%&id__eq__=2

response example:

{
    "data": [
        {
            "email": "gabriel.ligoski@gmail.com",
            "id": 2,
            "username": "ligoski"
        }
    ],
    "total": 1
}

currently supported filters:

  • gte
    • Example: curl --location 'http://127.0.0.1:5000/users?id__gte__=2
  • gt
    • Example: curl --location 'http://127.0.0.1:5000/users?id__gt__=2
  • lte
    • Example: curl --location 'http://127.0.0.1:5000/users?id__lte__=2
  • lt
    • Example: curl --location 'http://127.0.0.1:5000/users?id__lt__=2
  • like
    • Example: curl --location 'http://127.0.0.1:5000/users?email__like__=%gabriel%
  • in
    • Example: curl --location 'http://127.0.0.1:5000/users?email__in__=gabriel.ligoski@gmail.com,admin@gmail.com,teste@hotmail.com
  • eq
    • Example: curl --location 'http://127.0.0.1:5000/users?id__eq__=2

Project details


Download files

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

Source Distribution

flask_sqlalchemy_magic_query-0.1.2.tar.gz (3.5 kB view details)

Uploaded Source

File details

Details for the file flask_sqlalchemy_magic_query-0.1.2.tar.gz.

File metadata

File hashes

Hashes for flask_sqlalchemy_magic_query-0.1.2.tar.gz
Algorithm Hash digest
SHA256 8fb8014310454e7a5f8e2c4c39739fde363df78e6c781dd6a5ebb81b79a46df1
MD5 0d45863fed5a4a81d604eddccc359529
BLAKE2b-256 60ea6b47db48477a11fcdfeed8e2c9626dff9580baf83707fe80a1f3fb0090c5

See more details on using hashes here.

Supported by

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