PostgreSQL¶
Some helper functions for connection pools in asyncpg
.
- class ezcord.sql.postgresql.QueryStatus(type, rowcount=0, inserts=0)[source]¶
A class to access the status of a
PGHandler.exec()
call.
- class ezcord.sql.postgresql.EzConnection(protocol, transport, loop, addr, config, params)[source]¶
A subclass of
asyncpg.Connection
that adds aliases to be compatible with the sqlite handler.- async fetchval(sql, *args, default=None, **kwargs)[source]¶
Run a query and return a value in the first row.
- Parameters:
- Returns:
The value of the specified column of the first record, or None if no records were returned by the query.
- class ezcord.sql.postgresql.PGHandler(*, custom_pool=None, auto_setup=True, **kwargs)[source]¶
A class that provides helper methods for PostgreSQL databases.
Note
It’s recommended to set the database connection parameters in the
.env
file.- Parameters:
- async one(sql, *args, default=None, **kwargs)[source]¶
Returns one result record. If no record is found,
None
is returned.- Parameters:
sql (
str
) – The SQL query to execute.*args – Arguments for the query.
default – When the query returns no results, this value will be returned instead of
None
.
- Return type:
The result record or
None
.
- async all(sql, *args, **kwargs)[source]¶
Returns all result records.
- Parameters:
sql (
str
) – The SQL query to execute.*args – Arguments for the query.
- Return type:
A list of result records.
- async fetchval(sql, *args, default=None, **kwargs)[source]¶
Returns one value.
- Parameters:
sql (
str
) – The SQL query to execute.*args – Arguments for the query.
default – When the query returns no results, this value will be returned instead of
None
.
- Return type:
The value or
None
.
- async exec(sql, *args, **kwargs)[source]¶
Executes a SQL query.
- Parameters:
sql (
str
) – The SQL query to execute.*args – Arguments for the query.
- Return type: