asyncpg_simpleorm.statements package

Submodules

asyncpg_simpleorm.statements.abstract module

class asyncpg_simpleorm.statements.abstract.SimpleDescriptor[source]

Bases: object

Simple transparent descriptor that uses a weakref.WeakKeyDictionary to store instance values.

class asyncpg_simpleorm.statements.abstract.StatementABC[source]

Bases: object

Abstract representation of a database query statement.

model

Return the model set on an instance.

abstractmethod query()[source]

Return an iterable that can be used in an asyncpg query. The first value should be the query_string, followed by the flattened query args.

Return type:Iterable[Any]
abstractmethod query_args()[source]

Return the query arguments set on an instance.

Return type:Iterable[Any]
abstractmethod query_string(sep='n')[source]

Return the query string set on an instance.

Return type:str
abstractmethod set_statement(*args, **kwargs)[source]

Set the statement on the instance.

asyncpg_simpleorm.statements.base_statement module

class asyncpg_simpleorm.statements.base_statement.BaseStatement(model, kwargs={}, arg_count: int = 1)[source]

Bases: asyncpg_simpleorm.statements.abstract.StatementABC

Implementation of the StatementABC.

count
kwargs
model

Return the database model set on an instance. And ensures that the model is derived from ModelABC.

Raises:.exceptions.InvalidModel – If trying to set an invalid model on an instance.
query()[source]

Returns the representation of the query set on the instance.

query_args()[source]

Get the query args set on the instance. This will return an empty tuple if no args have been set on the instance yet.

If args are set on the instance, then they will be returned in the order corresponding to their place holder in the query_string.

Return type:Iterable[Any]
query_string(sep='n')[source]

Get the query string set on the instance.

Parameters:sep – A seperator used to join the statement and the clauses. Defaults to ‘n’.
Raises:TypeError – If a statement has not yet been set on an instance.
Return type:str
set_count(count)[source]

Reset’s the counter for an instance.

Parameters:count (int) – The number to reset the counter to.
Return type:None
set_statement(key, query_string, args=None)[source]

Set the statement for an instance, and return self for method chaining.

Return type:BaseStatement
class asyncpg_simpleorm.statements.base_statement.ClauseDescriptor[source]

Bases: asyncpg_simpleorm.statements.abstract.SimpleDescriptor

class asyncpg_simpleorm.statements.base_statement.StatementDescriptor[source]

Bases: asyncpg_simpleorm.statements.abstract.SimpleDescriptor

Specialized descriptor for use with the StatementValues class. This will raise an error if another statement is already set on an instance.

class asyncpg_simpleorm.statements.base_statement.StatementValues[source]

Bases: object

Container that holds the values for a BaseStatement. This only allows a single statement to be set on an instance, avoiding errors with the argument count for the query args.

classmethod clauses()[source]

Returns the attribute names for the ClauseDescriptor’s

delete

Specialized descriptor for use with the StatementValues class. This will raise an error if another statement is already set on an instance.

from_
get_clauses()[source]

Return any clauses set on an instance.

get_statement(strict=False)[source]

Return the current statement set on the instance.

insert

Specialized descriptor for use with the StatementValues class. This will raise an error if another statement is already set on an instance.

query_args()[source]

Returns the query arguments set on the instance.

query_string(sep='\n')[source]

Return a string that can be used in a database query.

This combines the statements and clauses into a query.

Parameters:sep – The seperator to use to combine the statement and clauses. Defaults to ‘n’.
Raises:TypeError – If a statement has not yet been set on an instance.
select

Specialized descriptor for use with the StatementValues class. This will raise an error if another statement is already set on an instance.

classmethod statements()[source]

Returns the attribute names for the StatementDescriptor’s

update

Specialized descriptor for use with the StatementValues class. This will raise an error if another statement is already set on an instance.

where
for ... in asyncpg_simpleorm.statements.base_statement.counter(start=1)[source]

Simple counter generator, used to keep track of query args.

Parameters:start – The number to start out the counter with.

Module contents

class asyncpg_simpleorm.statements.BaseStatement(model, kwargs={}, arg_count: int = 1)[source]

Bases: asyncpg_simpleorm.statements.abstract.StatementABC

Implementation of the StatementABC.

count
kwargs
model

Return the database model set on an instance. And ensures that the model is derived from ModelABC.

Raises:.exceptions.InvalidModel – If trying to set an invalid model on an instance.
query()[source]

Returns the representation of the query set on the instance.

query_args()[source]

Get the query args set on the instance. This will return an empty tuple if no args have been set on the instance yet.

If args are set on the instance, then they will be returned in the order corresponding to their place holder in the query_string.

Return type:Iterable[Any]
query_string(sep='n')[source]

Get the query string set on the instance.

Parameters:sep – A seperator used to join the statement and the clauses. Defaults to ‘n’.
Raises:TypeError – If a statement has not yet been set on an instance.
Return type:str
set_count(count)[source]

Reset’s the counter for an instance.

Parameters:count (int) – The number to reset the counter to.
Return type:None
set_statement(key, query_string, args=None)[source]

Set the statement for an instance, and return self for method chaining.

Return type:BaseStatement
class asyncpg_simpleorm.statements.StatementABC[source]

Bases: object

Abstract representation of a database query statement.

model

Return the model set on an instance.

abstractmethod query()[source]

Return an iterable that can be used in an asyncpg query. The first value should be the query_string, followed by the flattened query args.

Return type:Iterable[Any]
abstractmethod query_args()[source]

Return the query arguments set on an instance.

Return type:Iterable[Any]
abstractmethod query_string(sep='n')[source]

Return the query string set on an instance.

Return type:str
abstractmethod set_statement(*args, **kwargs)[source]

Set the statement on the instance.

class asyncpg_simpleorm.statements.Statement(model, kwargs={}, arg_count: int = 1)[source]

Bases: asyncpg_simpleorm.statements.base_statement.BaseStatement

Extends the BaseStatement class. This class is normally not instantiated directly, but returned from one of the statement factory functions.

count
delete()[source]

Set’s the statement as a DELETE statement. This will automatically set a where statement, using the primary keys.

from_()[source]

Add’s the FROM clause string to the statement.

insert(**kwargs)[source]

Set’s the statement as an INSERT statement.

Parameters:kwargs – Values to use as (column names, query args) for the statement. These are probably not used much as you should normally just set the model to an instance of ModelABC for the column names and values.
kwargs
select()[source]

Set’s the statement as a SELECT statement.

update(**kwargs)[source]

Set’s the statement as an UPDATE statement. This will automatically set a where statement, using the primary keys.

Parameters:kwargs – Values to use as column names, query args for the statement. These are probably not used much as you should normally just set the model to an instance of ModelABC for the column names and values.
Raises:TypeError – If no args were able to be parsed for the statement.
where(primary_keys=False, safe_call=False, **kwargs)[source]

Add’s the where string to the statement.

Parameters:
  • primary_keys – If True, only parse primary keys for the where string and args. This is primarily an implementation detail used in conjunction with other statement callbacks, and typically not necessarily set by a caller.
  • safe_call – An optional boolean to suppress errors. Default is False.
  • kwargs – An optional mapping of column names and values to use for the where statement.
Raises:
  • ValueError – If not using the primary keys and the kwargs set on the instance include an invalid key.
  • TypeError – If nothing was able to be parsed.
asyncpg_simpleorm.statements.select(model)[source]

Select statement factory.

Parameters:model – A ModelABC subclass to create the statement for.
asyncpg_simpleorm.statements.update(model=None, **kwargs)[source]

Update statement factory.

Parameters:
  • model – A ModelABC subclass instance to create the statement for.
  • kwargs – Used for instance values, if the statement is created with a class, not an instance.
asyncpg_simpleorm.statements.insert(model=None, **kwargs)[source]

Insert statement factory.

Parameters:
  • model – A ModelABC subclass instance to create the statement for.
  • kwargs – Used for instance values, if the statement is created with a class, not an instance.
asyncpg_simpleorm.statements.delete(model, **kwargs)[source]

Delete statement factory.

Parameters:
  • model – A ModelABC subclass instance to create the statement for.
  • kwargs – Used for instance values, if the statement is created with a class, not an instance.