The main Database object. This is the “database interface” to the actual DB server.
Classes
DatabaseInterface (dsn: str = None, *, …) |
The “database interface” to your database. |
asyncqlio.db.
DatabaseInterface
(dsn: str = None, *, loop: asyncio.events.AbstractEventLoop = None)[source]¶Bases: object
The “database interface” to your database. This provides the actual connection to the DB server, including things such as querying, inserting, updating, et cetera.
Creating a new database object is simple:
# pass the DSN in the constructor
dsn = "postgresql://postgres:B07_L1v3s_M4tt3r_T00@127.0.0.1/mydb"
my_database = DatabaseInterface(dsn)
# or provide it in the `.connect()` call
await my_database.connect(dsn)
Parameters: | dsn – The Data Source Name <http://whatis.techtarget.com/definition/data-source-name-DSN>_ to connect to the database on. |
---|
connector
= None¶The current connector instance.
dialect
= None¶The current Dialect instance.
connected
¶Checks if this DB is connected.
bind_tables
(md: asyncqlio.orm.schema.table.TableMetadata)[source]¶Binds tables to this DB instance.
connect
(dsn: str = None, **kwargs) → asyncqlio.backends.base.BaseConnector[source]¶Connects the interface to the database server.
Note
For SQLite3 connections, this will just open the database for reading.
Parameters: | dsn – The Data Source Name to connect to, if it was not specified in the constructor. |
---|---|
Returns: | The BaseConnector established. |
emit_param
(name: str) → str[source]¶Emits a param in the format that the DB driver specifies.
Parameters: | name – The name of the parameter to emit. |
---|---|
Returns: | A str representing the emitted param. |
get_transaction
(**kwargs) → asyncqlio.backends.base.BaseTransaction[source]¶Gets a low-level BaseTransaction
.
async with db.get_transaction() as transaction:
results = await transaction.cursor("SELECT 1;")