Skip to main content

A simple, fast way to access postgresql

Project description

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

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

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

pgwrapper-0.3.1.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

pgwrapper-0.3.1-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file pgwrapper-0.3.1.tar.gz.

File metadata

  • Download URL: pgwrapper-0.3.1.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.9.6 requests/2.28.2 setuptools/65.5.0 requests-toolbelt/0.10.1 tqdm/4.65.0 CPython/3.11.2

File hashes

Hashes for pgwrapper-0.3.1.tar.gz
Algorithm Hash digest
SHA256 c541833567e2854aee06cb77ab9978c0ad9677a898cffd1795f2477b66628a67
MD5 08446fee27e1df2d50b3e4d9191d24cc
BLAKE2b-256 984e4bf502b1a64ea2c616a77e57940dc4126b48a4fe2bbef0af46aadf87e04d

See more details on using hashes here.

File details

Details for the file pgwrapper-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: pgwrapper-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 18.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.9.6 requests/2.28.2 setuptools/65.5.0 requests-toolbelt/0.10.1 tqdm/4.65.0 CPython/3.11.2

File hashes

Hashes for pgwrapper-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d566ed5cc93397964ae49db410b4812a50697514a0cb893fadf3d283165a164a
MD5 c9de303002a3d27730ea9ef77e006d66
BLAKE2b-256 d7e13e8afb8569b09a0146a8201618ac740c178c018aef1e084390f2dcfa2115

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