Skip to content

adjunct.dbhelpers

Helpers for interacting with databases.

execute(con, sql, args=())

Execute an SQL statement.

Parameters:

Name Type Description Default
con _Connection

connection object

required
sql str

the statement to execute

required
args Sequence[Scalar]

arguments to interpolate into the statement

()

Returns:

Type Description
int | None

The value of lastrowid, usually an autogenerated primary key.

query(con, sql, args=())

Run an SQL query.

Parameters:

Name Type Description Default
con _Connection

connection object

required
sql str

the statement to execute

required
args Sequence[Scalar]

arguments to interpolate into the statement

()

Yields:

Type Description
Row

The rows of the result.

query_row(con, sql, args=(), *, default=None)

Run an SQL query expected to return a single row.

Parameters:

Name Type Description Default
con _Connection

connection object

required
sql str

the statement to execute

required
args Sequence[Scalar]

arguments to interpolate into the statement

()
default Row | None

value to return if no rows are returned by the query

None

Returns:

Type Description
Row | None

The matched row.

query_value(con, sql, args=(), *, default=None)

Run an SQL query expected to return a single value.

Parameters:

Name Type Description Default
con _Connection

connection object

required
sql str

the statement to execute

required
args Sequence[Scalar]

arguments to interpolate into the statement

()
default Scalar

value to return if no rows are returned by the query

None

Returns:

Type Description
Scalar

The first field of the matched row.