The Engine class is a core component of the oRm framework, responsible for managing database connections and providing methods for interacting with the database. It supports both direct connections and connection pooling, offering flexibility in how database resources are managed.
Key features:
Manages database connections (single or pooled)
Provides methods for executing SQL queries and commands
Allows creation of TableModel objects for ORM operations
Supports persistent connections for improved performance
Public fields
conn_argsA list of arguments for establishing a connection
connActive database connection or pool
use_poolWhether to use connection pooling
persistWhether to keep connections open between operations
dialectDatabase dialect in use
schemaDefault schema applied to tables
Methods
Method new()
Create an Engine object
Arguments
...Additional arguments to be passed to DBI::dbConnect
conn_argsA list of arguments to be passed to DBI::dbConnect
.schemaCharacter. The default schema to apply to child TableModel objects
use_poolLogical. Whether or not to make use of the pool package for connections to this engine
persistLogical. Whether to keep the connection open after operations (default: FALSE) Get a connection to the database
Reapplies the configured schema on every connection retrieval to ensure consistency after reconnects.
Method set_schema()
Set the default schema for the engine and active connection
Method create_schema()
Explicitly create a schema in the database
Method check_schema_exists()
Check if a schema exists in the database
Method model()
Create a new TableModel object for the specified table
Usage
Engine$model(
tablename,
...,
.data = list(),
.schema = NULL,
.default_mode = "all"
)Arguments
tablenameName of the table
...Additional arguments passed to the TableModel constructor. Include `Column` objects here to define the table structure.
.dataA named list of the arguments for the TableModel constructor. `Column` objects in this list also define table structure.
.schemaCharacter. The default schema to apply to the TableModel object
.default_modeCharacter. Default read mode for the TableModel.
Method qualify()
Qualify a table name with a schema
Method print()
Print a concise summary of the engine, including the SQL dialect, default schema, and connection status.