Skip to main content

Module for working with PostgreSQL via asyncpg

Project description

https://img.shields.io/pypi/v/aioworkers-pg.svg https://github.com/aioworkers/aioworkers-pg/workflows/Tests/badge.svg Coverage Code style: ruff Code style: black Code style: Mypy Documentation Status Python versions https://img.shields.io/pypi/dm/aioworkers-pg.svg Hatch project

Asyncpg plugin for aioworkers.

Usage

Connection

Add this to aioworkers config.yaml:

db:
  cls: aioworkers_pg.base.Connector
  dsn: postgresql:///test

You can get access to postgres anywhere via context:

await context.db.execute("CREATE TABLE users(id serial PRIMARY KEY, name text)")
await context.db.execute(users.insert().values(name="Bob"))

Connection additional

db:
  cls: aioworkers_pg.base.Connector
  dsn: postgresql:///test
  pool:
    min_size: 1
    max_size: 100
  connection:  # optional
    init: mymodule.connection_init
    setup: mymodule.connection_setup
    class: mymodule.Connection

Storage

storage:
  cls: aioworkers_pg.storage.RoStorage
  dsn: postgresql:///test
  table: mytable  # optional instead custom sql
  key: id
  get: SELECT * FROM mytable WHERE id = :id  # optional custom sql
  format: dict  # or row

Development

Check code:

hatch run lint:all

Format code:

hatch run lint:fmt

Run postgres:

docker run --rm -p 5432:5432 --name postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=test -d postgres

Run tests:

hatch run pytest

Run tests with coverage:

hatch run cov

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

aioworkers_pg-0.4.0a1.tar.gz (10.2 kB view hashes)

Uploaded Source

Built Distribution

aioworkers_pg-0.4.0a1-py3-none-any.whl (11.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page