Skip to main content

Flask wrapper for the SQL Records

Project description

Flask Records

PyPI - Python Version Build Status

Flask-Records is an extension that manuiplate the DB with the raw sql for the flask application using records.

Installation

pip install flask-records

Usage

Setup

Add the flask-records to your flask application.

from flask import Flask
from flask_records import FlaskRecords

raw_db = FlaskRecords(app)

or initialize the app in the way below:

from flask import Flask
from flask_records import FlaskRecords

raw_db = FlaskRecords()
raw_db.init_app(app)

Access DB With Flask Records

We have provided two decorators for easy using in the development:

query

The basic query decorator you can use in the flask records.

from flask_records.decorators import query

@query("INSERT INTO users VALUES(:id, :name, :age)")
def hello_flask_records(id, name, age):
    pass

# call the function: hello_flask_records(1, 'Leo', 27)

also, you can wrap all the parameters in a dictionary and pass it to the function.

from flask_records.decorators import query

@query( "INSERT INTO users VALUES(:id, :name, :age)")
def hello_flask_records(parameters):
    pass

# define a dict which contains the query parameters
# parameters = {
#     'id': 1,
#     'name': 'Leo', 
#     'age': 27
# }
# call the function: hello_flask_records(parameters)
query_by_page

This is the decorator which for the pagination.

from flask_records.decorators import query_by_page

@query_by_page("SELECT * FROM users", 2)
def hello_flask_records(page):
    pass

Extra Features

Flask-Records also provide the basic crud function, all you need to do is inherit the RecordsDao when you write the DAO layer classes.

from flask_records import RecordsDao

class UserDao(RecordsDao):

    def __init__(self):
        super(UserDao, self).__init__()

For detailed instructions on the features, please refer to the flask records documentation.

ChangeLog

Release 0.0.15

  • add a param converters in as_dict function, which means u can do the convertion according to your requirements. the format for this param is {'key': func}
  • add bulk_query decorator, so you can insert multiple rows to the db
  • add as_df function to the RecordCollection

Release 0.0.14

  • Fix the initialize issue in the way like FlaskRecords()
  • Modified the error in the Doc

Release 0.0.9

  • Support the default params in the function when do the query
  • Compatible with the Python2.7+ and 3.5+

Release 0.0.8

  • Support the decorators on the function or method in the class
  • Simplify the usage of the decorators
  • Provide the base crud operations
  • Add unit tests for the decorators, basic dao etc

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_records-0.0.15.tar.gz (6.2 kB view details)

Uploaded Source

File details

Details for the file flask_records-0.0.15.tar.gz.

File metadata

  • Download URL: flask_records-0.0.15.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for flask_records-0.0.15.tar.gz
Algorithm Hash digest
SHA256 de37abba933858ff0fb19112f3458343bfe5af33914850038a1410c263d6df6e
MD5 b209f45c4df7f012298412b7e4286d2d
BLAKE2b-256 fa1b81445ab36d2863f60f0c01b6520f33d3dc9b1b9e7a35a0163f5af4bcabb0

See more details on using hashes here.

Supported by

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