fastasyncpg 0.0.6__tar.gz → 0.0.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fastasyncpg-0.0.6/fastasyncpg.egg-info → fastasyncpg-0.0.8}/PKG-INFO +1 -1
- fastasyncpg-0.0.8/fastasyncpg/__init__.py +1 -0
- {fastasyncpg-0.0.6 → fastasyncpg-0.0.8}/fastasyncpg/_modidx.py +5 -0
- {fastasyncpg-0.0.6 → fastasyncpg-0.0.8}/fastasyncpg/core.py +50 -11
- {fastasyncpg-0.0.6 → fastasyncpg-0.0.8/fastasyncpg.egg-info}/PKG-INFO +1 -1
- {fastasyncpg-0.0.6 → fastasyncpg-0.0.8}/pyproject.toml +2 -0
- fastasyncpg-0.0.6/fastasyncpg/__init__.py +0 -1
- {fastasyncpg-0.0.6 → fastasyncpg-0.0.8}/LICENSE +0 -0
- {fastasyncpg-0.0.6 → fastasyncpg-0.0.8}/MANIFEST.in +0 -0
- {fastasyncpg-0.0.6 → fastasyncpg-0.0.8}/README.md +0 -0
- {fastasyncpg-0.0.6 → fastasyncpg-0.0.8}/fastasyncpg.egg-info/SOURCES.txt +0 -0
- {fastasyncpg-0.0.6 → fastasyncpg-0.0.8}/fastasyncpg.egg-info/dependency_links.txt +0 -0
- {fastasyncpg-0.0.6 → fastasyncpg-0.0.8}/fastasyncpg.egg-info/entry_points.txt +0 -0
- {fastasyncpg-0.0.6 → fastasyncpg-0.0.8}/fastasyncpg.egg-info/requires.txt +0 -0
- {fastasyncpg-0.0.6 → fastasyncpg-0.0.8}/fastasyncpg.egg-info/top_level.txt +0 -0
- {fastasyncpg-0.0.6 → fastasyncpg-0.0.8}/setup.cfg +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.0.8"
|
|
@@ -41,6 +41,8 @@ d = { 'settings': { 'branch': 'main',
|
|
|
41
41
|
'fastasyncpg.core.Table._rec': ('core.html#table._rec', 'fastasyncpg/core.py'),
|
|
42
42
|
'fastasyncpg.core.Table._recs': ('core.html#table._recs', 'fastasyncpg/core.py'),
|
|
43
43
|
'fastasyncpg.core.Table.c': ('core.html#table.c', 'fastasyncpg/core.py'),
|
|
44
|
+
'fastasyncpg.core.Table.claim': ('core.html#table.claim', 'fastasyncpg/core.py'),
|
|
45
|
+
'fastasyncpg.core.Table.claim_one': ('core.html#table.claim_one', 'fastasyncpg/core.py'),
|
|
44
46
|
'fastasyncpg.core.Table.cols': ('core.html#table.cols', 'fastasyncpg/core.py'),
|
|
45
47
|
'fastasyncpg.core.Table.count': ('core.html#table.count', 'fastasyncpg/core.py'),
|
|
46
48
|
'fastasyncpg.core.Table.count_where': ('core.html#table.count_where', 'fastasyncpg/core.py'),
|
|
@@ -61,6 +63,8 @@ d = { 'settings': { 'branch': 'main',
|
|
|
61
63
|
'fastasyncpg.core.Table.upsert': ('core.html#table.upsert', 'fastasyncpg/core.py'),
|
|
62
64
|
'fastasyncpg.core.Table.upserts': ('core.html#table.upserts', 'fastasyncpg/core.py'),
|
|
63
65
|
'fastasyncpg.core.Table.xtra': ('core.html#table.xtra', 'fastasyncpg/core.py'),
|
|
66
|
+
'fastasyncpg.core._ClaimCtx': ('core.html#_claimctx', 'fastasyncpg/core.py'),
|
|
67
|
+
'fastasyncpg.core._ClaimCtx.__init__': ('core.html#_claimctx.__init__', 'fastasyncpg/core.py'),
|
|
64
68
|
'fastasyncpg.core._Col': ('core.html#_col', 'fastasyncpg/core.py'),
|
|
65
69
|
'fastasyncpg.core._Col.__init__': ('core.html#_col.__init__', 'fastasyncpg/core.py'),
|
|
66
70
|
'fastasyncpg.core._Col.__iter__': ('core.html#_col.__iter__', 'fastasyncpg/core.py'),
|
|
@@ -92,6 +96,7 @@ d = { 'settings': { 'branch': 'main',
|
|
|
92
96
|
'fastasyncpg.core._pk_where': ('core.html#_pk_where', 'fastasyncpg/core.py'),
|
|
93
97
|
'fastasyncpg.core._prep_row': ('core.html#_prep_row', 'fastasyncpg/core.py'),
|
|
94
98
|
'fastasyncpg.core._process_row': ('core.html#_process_row', 'fastasyncpg/core.py'),
|
|
99
|
+
'fastasyncpg.core._select_sql': ('core.html#_select_sql', 'fastasyncpg/core.py'),
|
|
95
100
|
'fastasyncpg.core.all_dcs': ('core.html#all_dcs', 'fastasyncpg/core.py'),
|
|
96
101
|
'fastasyncpg.core.col_def': ('core.html#col_def', 'fastasyncpg/core.py'),
|
|
97
102
|
'fastasyncpg.core.columns_info': ('core.html#columns_info', 'fastasyncpg/core.py'),
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
"""Docs: https://AnswerDotAI.github.io/fastasyncpgcore.html.md"""
|
|
2
|
+
|
|
1
3
|
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_core.ipynb.
|
|
2
4
|
|
|
3
5
|
# %% auto #0
|
|
@@ -8,7 +10,7 @@ __all__ = ['pg_to_py', 'py_to_pg', 'Results', 'FRecord', 'table_names', 'view_na
|
|
|
8
10
|
# %% ../nbs/00_core.ipynb #222d751e
|
|
9
11
|
from fastcore.utils import *
|
|
10
12
|
from contextlib import asynccontextmanager
|
|
11
|
-
import asyncpg
|
|
13
|
+
import asyncpg,traceback
|
|
12
14
|
from asyncpg import connection,protocol
|
|
13
15
|
|
|
14
16
|
# %% ../nbs/00_core.ipynb #cdb9cd9e
|
|
@@ -325,17 +327,22 @@ async def get(self:Table, pk):
|
|
|
325
327
|
try: return await self[pk]
|
|
326
328
|
except NotFoundError: return None
|
|
327
329
|
|
|
328
|
-
# %% ../nbs/00_core.ipynb #
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
"Iterate over rows matching where clause"
|
|
333
|
-
where, args = _add_xtra(self, where, where_args or [])
|
|
334
|
-
sql = f'SELECT {select} FROM {self}'
|
|
330
|
+
# %% ../nbs/00_core.ipynb #19069c39
|
|
331
|
+
def _select_sql(tbl, where, where_args, order_by=None, select='*', limit=None, offset=None, suffix=''):
|
|
332
|
+
where, args = _add_xtra(tbl, where, where_args or [])
|
|
333
|
+
sql = f'SELECT {select} FROM {tbl}'
|
|
335
334
|
if where: sql += f' WHERE {where}'
|
|
336
335
|
if order_by: sql += f' ORDER BY {order_by}'
|
|
337
336
|
if limit: sql += f' LIMIT {limit}'
|
|
338
337
|
if offset: sql += f' OFFSET {offset}'
|
|
338
|
+
if suffix: sql += f' {suffix}'
|
|
339
|
+
return sql, args
|
|
340
|
+
|
|
341
|
+
# %% ../nbs/00_core.ipynb #fd2d38a2
|
|
342
|
+
@patch
|
|
343
|
+
async def rows_where(self:Table, where=None, where_args=None, order_by=None, select='*', limit=None, offset=None, as_cls=True, debug=False):
|
|
344
|
+
"Iterate over rows matching where clause"
|
|
345
|
+
sql, args = _select_sql(self, where, where_args, order_by, select, limit, offset)
|
|
339
346
|
if debug: print(sql)
|
|
340
347
|
if as_cls: return await self._recs(sql, *args)
|
|
341
348
|
return await self.db.q(sql, *args)
|
|
@@ -669,12 +676,14 @@ def from_meta(cls:Database, conn, db):
|
|
|
669
676
|
if hasattr(tbl, 'cls'): res.table(name).cls = tbl.cls
|
|
670
677
|
return res
|
|
671
678
|
|
|
672
|
-
# %% ../nbs/00_core.ipynb #
|
|
679
|
+
# %% ../nbs/00_core.ipynb #c6be6cb0
|
|
673
680
|
@patch
|
|
674
681
|
@asynccontextmanager
|
|
675
682
|
async def acquire(self:Database):
|
|
676
|
-
"Context manager yielding a Database on a single
|
|
677
|
-
|
|
683
|
+
"Context manager yielding a Database on a single connection"
|
|
684
|
+
if isinstance(self.conn, asyncpg.pool.Pool):
|
|
685
|
+
async with self.conn.acquire() as conn: yield Database.from_meta(conn, self)
|
|
686
|
+
else: yield self
|
|
678
687
|
|
|
679
688
|
# %% ../nbs/00_core.ipynb #f0b7826a
|
|
680
689
|
@patch
|
|
@@ -683,3 +692,33 @@ async def transaction(self:Database):
|
|
|
683
692
|
"Context manager yielding a transactional Database on a single connection"
|
|
684
693
|
async with self.acquire() as db:
|
|
685
694
|
async with db.conn.transaction(): yield db
|
|
695
|
+
|
|
696
|
+
# %% ../nbs/00_core.ipynb #de4c0d24
|
|
697
|
+
@patch
|
|
698
|
+
async def claim(self:Table, where=None, where_args=None, order_by=None, limit=1):
|
|
699
|
+
"Claim a row with SELECT ... FOR UPDATE SKIP LOCKED (use inside a transaction)"
|
|
700
|
+
sql, args = _select_sql(self, where, where_args, order_by, limit=limit, suffix='FOR UPDATE SKIP LOCKED')
|
|
701
|
+
return await self._rec(sql, *args)
|
|
702
|
+
|
|
703
|
+
# %% ../nbs/00_core.ipynb #b9695685
|
|
704
|
+
class _ClaimCtx:
|
|
705
|
+
def __init__(self):
|
|
706
|
+
self.evt = self.db = self.tb = self.exc = None
|
|
707
|
+
self.retry = self.failed = False
|
|
708
|
+
|
|
709
|
+
@patch
|
|
710
|
+
@asynccontextmanager
|
|
711
|
+
async def claim_one(self:Table, status_col='status', pending='pending', completed='completed', failed='failed', order_by=None):
|
|
712
|
+
"Claim a row and manage its status transitions"
|
|
713
|
+
p = _ClaimCtx()
|
|
714
|
+
async with self.db.transaction() as txn:
|
|
715
|
+
tbl = txn.t[self.name]
|
|
716
|
+
p.db = txn
|
|
717
|
+
p.evt = await tbl.claim(where=f'"{status_col}"=$1', where_args=[pending], order_by=order_by)
|
|
718
|
+
if p.evt is None: return
|
|
719
|
+
try: yield p
|
|
720
|
+
except Exception as e: p.failed, p.exc, p.tb = True, e, traceback.format_exc()
|
|
721
|
+
pk = self.pks[0]
|
|
722
|
+
new = failed if p.failed else (None if p.retry else completed)
|
|
723
|
+
stmt = f'UPDATE {self} SET "{status_col}"=$1 WHERE "{pk}"=$2'
|
|
724
|
+
if new: await txn.execute(stmt, new, get_field(p.evt, pk))
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.0.6"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|