Centralize database access
Project description
Schemapy allows you to generate objects for centralized database access. You define the schema for your API, the code that needs to be executed, then the validation part is dealt with for you. Everything is then encapsulated in a single object.
Schemapy relies on PyDAL for schema definition but is not tied to it.
See documentation for more informations.
Installation
pip install schemapy
Usage
Using PyDAL:
from schemapy import API, DAL, Field
from datetime import datetime, timedelta
db = DAL('sqlite:memory')
db.define_table(
'users',
Field('name', type='string', required=True),
Field('created_on', type='date')
)
db.define_table(
'posts',
Field('subject', type='string', required=True),
Field('author', type='reference users', required=True),
Field('created_on', type='date'),
Field('content', type='text', required=True)
)
api = API(db)
@api.as_action(
type='read',
request=[
Field('begin', type='date', required=True),
Field('end', type='date', required=True)
],
response=db.posts
)
def select_posts_by_date(db, req, action):
query = (db.posts.created_on >= req.begin) | (db.posts.created_on <= req.end)
return db(query).select()
now = datetime.now()
result = api.select_posts_by_date(
begin=now - timedelta(days=1),
end=now
)
print(list(result))
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
schemapy-0.2.1.tar.gz
(15.6 kB
view details)
Built Distribution
File details
Details for the file schemapy-0.2.1.tar.gz
.
File metadata
- Download URL: schemapy-0.2.1.tar.gz
- Upload date:
- Size: 15.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b9abd994a88b97f4a3ced57793cdc34f987f74cc5bcadfda073101260053170 |
|
MD5 | 23463f8b7a8ea2d167aefb372ef135e2 |
|
BLAKE2b-256 | 3cf8f02badcfcef6be5c84c2b3e146891911e0e5c125bdcf13f658c9e1cf1353 |
File details
Details for the file schemapy-0.2.1-py2.py3-none-any.whl
.
File metadata
- Download URL: schemapy-0.2.1-py2.py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5123e070dc58b1163496eae8ccf4814a489a11fcef03d85de0400ab0c8af994a |
|
MD5 | 1064a7c227aae39bb1f5c84814dd2920 |
|
BLAKE2b-256 | b7b7191b4863e7da00c979c4c35e5b605e8f9041e2ea05ebc9dd915d2c091f3b |