Metadata-Version: 2.1
Name: aioworkers-pg
Version: 0.4.0a1
Summary: Module for working with PostgreSQL via asyncpg
Project-URL: Homepage, https://github.com/aioworkers/aioworkers-pg
Project-URL: Documentation, https://github.com/aioworkers/aioworkers-pg#readme
Project-URL: Issues, https://github.com/aioworkers/aioworkers-pg/issues
Project-URL: Source, https://github.com/aioworkers/aioworkers-pg
Author-email: Alexander Bogushov <abogushov@gmail.com>, Alexander Malev <aamalev@gmail.com>
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: aioworkers,asyncpg,pg,postgres,postgresql
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Python: >=3.7
Requires-Dist: aioworkers>=0.15
Requires-Dist: asyncpg>=0.22
Provides-Extra: dev-lint
Requires-Dist: black==23.7.0; extra == 'dev-lint'
Requires-Dist: isort==5.12.0; extra == 'dev-lint'
Requires-Dist: mypy==1.4.1; extra == 'dev-lint'
Requires-Dist: ruff==0.0.282; extra == 'dev-lint'
Provides-Extra: dev-test
Requires-Dist: aioworkers==0.26; extra == 'dev-test'
Requires-Dist: asyncpg==0.28.0; extra == 'dev-test'
Requires-Dist: asyncpgsa==0.27.1; extra == 'dev-test'
Requires-Dist: coverage[toml]==7.2.7; extra == 'dev-test'
Requires-Dist: pytest-aioworkers[asyncio]==0.4; extra == 'dev-test'
Requires-Dist: pytest-mock==3.11.1; extra == 'dev-test'
Requires-Dist: pytest-timeout; extra == 'dev-test'
Requires-Dist: pytest==7.4.0; extra == 'dev-test'
Requires-Dist: pyyaml==6.0.1; extra == 'dev-test'
Requires-Dist: sqlalchemy[asyncio]==2.0.19; extra == 'dev-test'
Provides-Extra: sa
Requires-Dist: sqlalchemy[asyncio]>2; extra == 'sa'
Description-Content-Type: text/x-rst

aioworkers-pg
=============

.. image:: https://img.shields.io/pypi/v/aioworkers-pg.svg
  :target: https://pypi.org/project/aioworkers-pg

.. image:: https://github.com/aioworkers/aioworkers-pg/workflows/Tests/badge.svg
  :target: https://github.com/aioworkers/aioworkers-pg/actions?query=workflow%3ATests

.. image:: https://codecov.io/gh/aioworkers/aioworkers-pg/branch/master/graph/badge.svg
  :target: https://codecov.io/gh/aioworkers/aioworkers-pg
  :alt: Coverage

.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v0.json
  :target: https://github.com/charliermarsh/ruff
  :alt: Code style: ruff

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
  :target: https://github.com/psf/black
  :alt: Code style: black

.. image:: https://img.shields.io/badge/types-Mypy-blue.svg
  :target: https://github.com/python/mypy
  :alt: Code style: Mypy

.. image:: https://readthedocs.org/projects/aioworkers-pg/badge/?version=latest
  :target: https://github.com/aioworkers/aioworkers-pg#readme
  :alt: Documentation Status

.. image:: https://img.shields.io/pypi/pyversions/aioworkers-pg.svg
  :target: https://pypi.org/project/aioworkers-pg
  :alt: Python versions

.. image:: https://img.shields.io/pypi/dm/aioworkers-pg.svg
  :target: https://pypi.org/project/aioworkers-pg

.. image:: https://img.shields.io/badge/%F0%9F%A5%9A-Hatch-4051b5.svg
  :alt: Hatch project
  :target: https://github.com/pypa/hatch


Asyncpg plugin for `aioworkers`.


Usage
-----

Connection
__________

Add this to aioworkers config.yaml:


.. code-block:: yaml

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

You can get access to postgres anywhere via context:

.. code-block:: python

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


Connection additional
_____________________

.. code-block:: yaml

  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
_______

.. code-block:: yaml

  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:

.. code-block:: shell

    hatch run lint:all


Format code:

.. code-block:: shell

    hatch run lint:fmt


Run postgres:

.. code-block:: shell

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


Run tests:

.. code-block:: shell

    hatch run pytest


Run tests with coverage:

.. code-block:: shell

    hatch run cov
