Asyncpg plugin for aioworkers.
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"))
db:
cls: aioworkers_pg.base.Connector
dsn: postgresql:///test
host: localhost
port: 5432
database: test
username: postgres
password: postgres
pool:
min_size: 1
max_size: 100
connection: # optional
init: mymodule.connection_init
setup: mymodule.connection_setup
class: mymodule.Connection
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
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