Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
lsbardel committed Feb 10, 2020
1 parent 1a09225 commit 8abdce2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
11 changes: 9 additions & 2 deletions openapi/db/dbmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,26 @@
from sqlalchemy.sql import and_

from ..db.container import Database
from ..types import Records
from .compile import QueryType, Select, compile_query, count


class CrudDB(Database):
"""A :class:`.Database` with additional methods for CRUD operations"""

async def db_select(self, table: Table, filters: Dict, *, conn=None, consumer=None):
async def db_select(
self, table: Table, filters: Dict, *, conn=None, consumer=None
) -> Records:
"""Select rows from a given table"""
query = self.get_query(table, table.select(), consumer, filters)
sql, args = compile_query(query)
async with self.ensure_connection(conn) as conn:
return await conn.fetch(sql, *args)

async def db_delete(self, table: Table, filters: Dict, *, conn=None, consumer=None):
async def db_delete(
self, table: Table, filters: Dict, *, conn=None, consumer=None
) -> Records:
"""Delete rows from a given table"""
query = self.get_query(
table, table.delete().returning(*table.columns), consumer, filters
)
Expand Down
8 changes: 4 additions & 4 deletions openapi/db/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from ..data.pagination import PaginatedData, Pagination
from ..db.dbmodel import CrudDB
from ..spec.path import ApiPath
from ..types import DataType, SchemaTypeOrStr, StrDict
from ..types import DataType, Records, SchemaTypeOrStr, StrDict
from .compile import Select, Update, compile_query, count

unique_regex = re.compile(r"Key \((?P<column>(\w+,? ?)+)\)=\((?P<value>.+)\)")
Expand Down Expand Up @@ -207,8 +207,8 @@ async def delete_one(
table: Optional[sa.Table] = None,
query_schema: SchemaTypeOrStr = "query_schema",
conn: Optional[Connection] = None,
):
"""delete a single model
) -> Records:
"""Delete a single model
"""
table = table if table is not None else self.db_table
if filters is None:
Expand All @@ -225,7 +225,7 @@ async def delete_list(
query: Optional[StrDict] = None,
table: Optional[sa.Table] = None,
conn: Optional[Connection] = None,
):
) -> Records:
"""delete multiple models
"""
table = table if table is not None else self.db_table
Expand Down
3 changes: 3 additions & 0 deletions openapi/types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from typing import Any, Dict, List, Union

from asyncpg import Record
from multidict import MultiDict

PrimitiveType = Union[int, float, bool, str]
Expand All @@ -9,3 +11,4 @@
SchemaTypeOrStr = Union[str, SchemaType]
StrDict = Dict[str, Any]
QueryType = Union[StrDict, MultiDict]
Records = List[Record]

0 comments on commit 8abdce2

Please sign in to comment.