sqlgen.statement_executor package¶
Submodules¶
sqlgen.statement_executor.asynchronous module¶
- class sqlgen.statement_executor.asynchronous.AsyncStatementExecutor(session: AsyncSession)¶
Bases:
Generic
- async all(statement: Select) Sequence ¶
Get all results for the given SQL Select.
- Parameters:
statement – the SQL Select statement to execute
- Returns:
a sequence of the model(s)/property specified by the Select query
- async execute_statement(statement: Select) Result ¶
execute a SQL Select on the current session
- Parameters:
statement – the SQL Select statement to execute
- Returns:
the Result of the Select
- async one(statement: Select) T ¶
Get only one result for the given SQL Select or raise an exception if No result of more than one
- Parameters:
statement – the SQL Select statement to execute
- Returns:
an instance of the model(s)/property specified by the Select query
- async one_or_none(statement: Select) T | None ¶
Get one result or None for the given SQL Select, raise an exception if more than one result are returned by the query
- Parameters:
statement – the SQL Select statement to execute
- Returns:
an instance of the model(s)/property specified by the Select query or None if not found
- async restore()¶
restore Database state on the db objects (SQL rollback)
- async save()¶
save current object within the database
- async scalars(statement: Select) ScalarResult ¶
Execute a SQL Select query and return its scalars (automatically uniquify the result for joined loads to succeed, not sure if there is some side effect)
- Parameters:
statement – the SQL Select statement to execute
- Returns:
the scalars of the result
- store(obj: DeclarativeBase)¶
add an object to DB
- Parameters:
obj – the object to add to the database
- async synchronize()¶
synchronize current object with the database session (don’t save but flush == set id but rollback would remove the created object)
sqlgen.statement_executor.synchronous module¶
- class sqlgen.statement_executor.synchronous.SynchronousStatementExecutor(session: Session)¶
Bases:
Generic
- all(statement: Select) Sequence ¶
Get all results for the given SQL Select.
This method takes a SQL Select statement and executes it using the current database session. The result is then converted to a list of the model(s)/property specified by the Select query.
- Parameters:
statement – The SQL Select statement to execute.
- Returns:
A sequence of the model(s)/property specified by the Select query.
- execute_statement(statement: Select) Result ¶
Execute a SQL Select statement on the current session.
This method takes a SQL Select statement and executes it using the current database session.
- Parameters:
statement – The SQL Select statement to execute.
- Returns:
The Result of the executed Select statement.
- one(statement: Select) T ¶
Execute a SQL Select statement and return only one result.
This method executes the given SQL Select statement and returns exactly one result. If the query returns no results or more than one result, an exception is raised.
- Parameters:
statement – The SQL Select statement to execute.
- Returns:
An instance of the model(s)/property specified by the Select query.
- Raises:
NoResultFound – If the query returns no result.
MultipleResultsFound – If the query returns more than one result.
- one_or_none(statement: Select) T | None ¶
Execute a SQL Select statement and return one result or None.
This method executes the given SQL Select statement and returns one result if available. If the query returns more than one result, an exception is raised. If no result is found, None is returned.
- Parameters:
statement – The SQL Select statement to execute.
- Returns:
An instance of the model(s)/property specified by the Select query or None if not found.
- Raises:
MultipleResultsFound – If the query returns more than one result.
- restore()¶
Restore the database state to its previous state by rolling back the current transaction.
This method is the opposite of save(). It will undo all changes made to the database since the last commit.
- Returns:
None
- save()¶
Save the current object within the database.
This method commits the current transaction to the database, persisting all changes made to the objects in the session.
- scalars(statement: Select) ScalarResult ¶
Execute a SQL Select query and return its scalars (unique or not depending on the use case).
This method takes a SQL Select statement and executes it using the current database session. The result is then converted to a ScalarResult which is a special Result type that only contains the scalar values of the query (i.e. without the column names).
- Parameters:
statement – the SQL Select statement to execute
- Returns:
the scalars of the result
- store(obj: DeclarativeBase) None ¶
Add an object to the database.
This method adds the given object to the current session, which means it will be persisted to the database when the session is committed.
- Parameters:
obj – The object to add to the database.
- Returns:
None
- synchronize()¶
Synchronize the current object with the database session.
This method does not commit the changes to the database but instead flushes the session which means that the changes will be persisted to the database but the transaction will remain open. This is useful when you want to have the generated id of an object but don’t want to commit the changes to the database yet.
The object will be in the session but not yet in the database. A rollback of the session will remove the created object from the session and the database.