Skip to main content

Utilities for Asyncpg

Project description

TravisCI Build Status Coverage Status Requirements Status

Utilities for Asyncpg.

How to install

pip install asyncpg-utils

How to Use

Python code:

import asyncio
from datetime import date

from asyncpg_utils.databases import Database

loop = asyncio.get_event_loop()
database = Database('postgresql://postgres:postgres@localhost/asyncpg-utils')

async def create_table():
    conn = await database.get_connection()
    await conn.execute(
            id serial PRIMARY KEY,
            name text,
            dob date
    await conn.close()
    return True

async def insert_row(data):
    return await database.insert('users', data)

async def query_all():
    return await database.query(
        SELECT * FROM users

async def query_one():
    return await database.query_one(
        SELECT * FROM users
        WHERE name = $1
        'Jane Doe'

async def main():
    print('create_table users, {!r}'.format(await create_table()))
    print('insert row, {!r}'.format(await insert_row({'name': 'John Doe', 'dob': date(2000, 1, 1)})))
    print('insert row, {!r}'.format(await insert_row({'name': 'Jane Doe', 'dob': date(2000, 1, 1)})))
    print('query all results, {!r}'.format(await query_all()))
    print('query one result, {!r}'.format(await query_one()))


Code executed:

create_table users, True
insert row, <Record id=1 name='John Doe', 1, 1)>
insert row, <Record id=2 name='Jane Doe', 1, 1)>
query all results, [<Record id=1 name='John Doe', 1, 1)>, <Record id=2 name='Jane Doe', 1, 1)>]
query one result, <Record id=2 name='Jane Doe', 1, 1)>

Check for more code examples.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for asyncpg-utils, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size asyncpg_utils-0.1.0-py3-none-any.whl (4.8 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size asyncpg-utils-0.1.0.tar.gz (4.0 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page