asyncpg_simpleorm.statements package¶
Submodules¶
asyncpg_simpleorm.statements.abstract module¶
-
class
asyncpg_simpleorm.statements.abstract.SimpleDescriptor[source]¶ Bases:
objectSimple transparent descriptor that uses a
weakref.WeakKeyDictionaryto store instance values.
-
class
asyncpg_simpleorm.statements.abstract.StatementABC[source]¶ Bases:
objectAbstract 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
asyncpgquery. The first value should be thequery_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]
-
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.StatementABCImplementation 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_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
selffor 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.SimpleDescriptorSpecialized descriptor for use with the
StatementValuesclass. This will raise an error if another statement is already set on an instance.
-
class
asyncpg_simpleorm.statements.base_statement.StatementValues[source]¶ Bases:
objectContainer 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
StatementValuesclass. This will raise an error if another statement is already set on an instance.
-
from_¶
-
insert¶ Specialized descriptor for use with the
StatementValuesclass. This will raise an error if another statement is already set on an instance.
-
query_string(sep='\n')[source]¶ Return a string that can be used in a database query.
This combines the
statementsandclausesinto 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
StatementValuesclass. 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
StatementValuesclass. This will raise an error if another statement is already set on an instance.
-
where¶
-
classmethod
Module contents¶
-
class
asyncpg_simpleorm.statements.BaseStatement(model, kwargs={}, arg_count: int = 1)[source]¶ Bases:
asyncpg_simpleorm.statements.abstract.StatementABCImplementation 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_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
selffor method chaining.Return type: BaseStatement
-
-
class
asyncpg_simpleorm.statements.StatementABC[source]¶ Bases:
objectAbstract 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
asyncpgquery. The first value should be thequery_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]
-
-
class
asyncpg_simpleorm.statements.Statement(model, kwargs={}, arg_count: int = 1)[source]¶ Bases:
asyncpg_simpleorm.statements.base_statement.BaseStatementExtends the
BaseStatementclass. 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
DELETEstatement. This will automatically set awherestatement, using the primary keys.
-
insert(**kwargs)[source]¶ Set’s the statement as an
INSERTstatement.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 ModelABCfor the column names and values.
-
kwargs¶
-
update(**kwargs)[source]¶ Set’s the statement as an
UPDATEstatement. This will automatically set awherestatement, 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 ModelABCfor 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
wherestring to the statement.Parameters: - primary_keys – If
True, only parse primary keys for thewherestring 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
kwargsset on the instance include an invalid key. - TypeError – If nothing was able to be parsed.
- primary_keys – If
-
-
asyncpg_simpleorm.statements.select(model)[source]¶ Select statement factory.
Parameters: model – A ModelABCsubclass to create the statement for.
-
asyncpg_simpleorm.statements.update(model=None, **kwargs)[source]¶ Update statement factory.
Parameters: - model – A
ModelABCsubclass instance to create the statement for. - kwargs – Used for instance values, if the statement is created with a class, not an instance.
- model – A