Flask PostgreSQL Wrapper is a simple adapter for PostgreSQL with connection pooling.
Project description
Flask PostgreSQL Wrapper
Flask PostgreSQL Wrapper is a simple adapter for PostgreSQL with connection pooling.
Configuration
The configuration can be done through JSON file or by Dict following the pattern described below:
{
"database": "postgres",
"host": "localhost",
"max_connection": 10,
"password": "postgres",
"port": 5432,
"print_sql": true,
"username": "postgres"
}
Create the queries directory. This should contain all the .sql files that the library will use.
Usage
Flask PostgreSQL Wrapper usage description:
Delete
Delete with where
from flask_postgresql_wrapper import Database
with Database() as connection:
(
connection
.delete('test')
.where('id', 1)
.execute()
)
Delete with where condition
from flask_postgresql_wrapper import Database
with Database() as connection:
(
connection
.delete('test')
.where('description', 'Test%', operator='like')
.execute()
)
Execute
from flask_postgresql_wrapper import Database
with Database() as connection:
(
connection
.execute(
'''
create table if not exists test (
id bigserial not null,
name varchar(100),
description varchar(255),
constraint test_primary_key primary key (id)
)
''',
skip_load_query=True
)
)
Insert
from flask_postgresql_wrapper import Database
with Database() as connection:
(
connection
.insert('test')
.set('id', 1)
.set('name', 'Name')
.set('description', 'Description')
.execute()
)
Paging
Paging with where condition
from flask_postgresql_wrapper import Database
with Database() as connection:
(
connection
.select('test')
.fields('id', 'name', 'description')
.where('id', 1, operator='>')
.order_by('id')
.paging(0, 2)
)
Paging without where condition
from flask_postgresql_wrapper import Database
with Database() as connection:
(
connection
.select('test')
.paging(0, 10)
)
Select
Fetch all
from flask_postgresql_wrapper import Database
with Database() as connection:
(
connection
.select('test')
.execute()
.fetch_all()
)
Fetch many
from flask_postgresql_wrapper import Database
with Database() as connection:
(
connection
.select('test')
.execute()
.fetch_many(1)
)
Fetch one
from flask_postgresql_wrapper import Database
with Database() as connection:
(
connection
.select('test')
.execute()
.fetch_one()
)
Select by file
from flask_postgresql_wrapper import Database
with Database() as connection:
(
connection
.execute('find_by_id', {'id': 1})
.fetch_one()
)
Select by query
from flask_postgresql_wrapper import Database
with Database() as connection:
(
connection
.execute('select id, name, description from test where id = %(id)s', {'id': 1})
.fetch_one()
)
Update
Update with where
from flask_postgresql_wrapper import Database
with Database() as connection:
(
connection
.update('test')
.set('name', 'New Name')
.set('description', 'New Description')
.where('id', 1)
.execute()
)
Update with where all
from flask_postgresql_wrapper import Database
with Database() as connection:
(
connection
.update('test')
.set('name', 'New Name')
.set('description', 'New Description')
.where_all({'id': 1, 'name': 'Name', 'description': 'Description'})
.execute()
)
Using filters
SQL
select
id,
name,
description
from test
where 1 = 1
{{#id}}
and id = %(id)s
{{/id}}
{{#name}}
and name like %(name)s
{{/name}}
Select with filters
from flask_postgresql_wrapper import Database
with Database() as connection:
(
connection
.execute('test.find_all_with_filter', parameters={'id': 1, 'name': 'Name'})
.fetch_one()
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flask-postgresql-wrapper-1.0.1.tar.gz.
File metadata
- Download URL: flask-postgresql-wrapper-1.0.1.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fcb5fd02dc45ecd3e40936a90a30ab49ff5dd3f695fb9314401fc36f33657857
|
|
| MD5 |
ba46cd1cb7c2caf0e47cecff3c7bb4c5
|
|
| BLAKE2b-256 |
d66fbfd83dd7ef4d4f7ddb5b4b2053b221fbc919283bf7c5f6632fd0d47270b8
|
File details
Details for the file flask_postgresql_wrapper-1.0.1-py2.py3-none-any.whl.
File metadata
- Download URL: flask_postgresql_wrapper-1.0.1-py2.py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae1489104c53633f426bea7206732fd49e1e9fcc8ae78bb607113e1d995637ef
|
|
| MD5 |
e4c1b41c878cc8d304bc93005ba1a3ab
|
|
| BLAKE2b-256 |
89feb8d7ce0e859fffbc2058535b2fb7185aba35ac9e412a743394351de6f86e
|