Skip to main content

pgwrapper

A simple, fast way to access postgresql in python.

Description

  • It is a postgresql python connection pool at lower layer.

  • It is a mongo-like query formula system upper layer.

  • It is a new version to access postgresql in python3.

Install

pip install pgwrapper

Usage

>>> import pgwrapper
>>> pg = pgwrapper.PGWrapper(
        dbname='postgres',
        user='postgres',
        password='',
        host='127.0.0.1',
        port=5432)
>>> r = pg.select('company', 'id, name', 'address is not null', 'limit 2')
>>> print(r)

[(12, 'sun'), (34, 'moon')]
select
    >>> select('hospital', 'id, city', control='limit 1')
    select id, city from hospital limit 1;


    >>> select('hospital', 'id', 'address is null')
    select id from hospital where address is null;
update
    >>> update('dept', {'name': 'design', 'quantity': 3}, {'id': 'we4d'})
    update dept set name='design', quantity=3 where id='we4d';

    >>> update('dept', {'name': 'design', 'quantity': 3}, 'introduction is null')
    update dept set name='design', quantity=3 where introduction is null;

    >>> update('physician', {'$inc': {'status': -10}, 'present': 0}, {'id': 'someid'})
    update physician set status=status+-10, present=0 where id='someid';
insert
    >>> insert('hospital', {'id': '12de3wrv', 'province': 'shanghai'})
    insert into hospital (id, province) values ('12de3wrv', 'shanghai');

insert use list way:

    >>> insert_list('hospital', ['id', 'province'], ['12de3wrv', 'shanghai'])
    insert into hospital (id, province) values ('12de3wrv', 'shanghai');

insert if the record not in the table:

    >>> insert_inexistence('hospital', {'id': '12de3wrv', 'province': 'shanghai'}, {'id': '12de3wrv'})
    insert into hospital (id, province) select '12de3wrv', 'shanghai' where not exists (select 1 from hospital where id='12de3wrv' limit 1);
delete
    >>> delete('hospital', {'id': '12de3wrv'})
    delete from hospital where id='12de3wrv';

join

comman join

    >>> joint('user', 'name, id_number', 'medical_card', 'number', 'id', 'user_id', 'inner_join')
    select u.name, u.id_number, v.number from user as u inner join medical_card as v on u.id=v.user_id;

left join

    >>> select_join('hospital', 'id', 'department', 'hospid')
    select hospital.id from hospital left join department on hospital.id=department.hospid where department.hospid is null;

Issue

Error: pg_config executable not found. If you meet this following error when installing psycopg2, you may need to install extra library.

In Ubuntu: sudo apt install libpq-dev

In macOs: brew install postgresql

Release files for pgwrapper 0.3.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pgwrapper 0.3.5
File Size Uploaded
pgwrapper-0.3.5.tar.gz 17.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pgwrapper 0.3.5
File Interpreter ABI Platform
pgwrapper-0.3.5-py3-none-any.whl Python 3 none any Details

Total release size: 36.2 kB

Release files / pgwrapper-0.3.5.tar.gz

Download URL pgwrapper-0.3.5.tar.gz
Size 17.6 kB
Tags Source
SHA-256 checksum
How to use checksums
dab17c2f684f99270662dea2135097192e0660f820de698243a45b6ee0c2459b
BLAKE2b-256 checksum
How to use checksums
269ac2e71e14c9826f4bab9c38e7eae9b3abf78cd8f592abd055810b2f9f6e9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Release files / pgwrapper-0.3.5-py3-none-any.whl

Download URL pgwrapper-0.3.5-py3-none-any.whl
Size 18.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1dffbbd1439192e98d663b6c8d37d3345c7f0bba073c13de99aaad0c16ceaf5a
BLAKE2b-256 checksum
How to use checksums
e33912c10c364f2b93cd201fa6a46363b19f4f74b6746fd076afd32cf46ba430
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Release history Release notifications | RSS feed

This release

0.3.5 This release

2 release files

0.3.1

2 release files

0.2.0

1 release file

0.1.7

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page