DB::Connection
Inherits DB::BeginTransaction < DB::SessionMethods < DB::QueryMethods < DB::Disposable < Reference < Object
Database driver implementors must subclass Connection.
Represents one active connection to a database.
Users should never instantiate a Connection manually. Use DB#open or Database#connection.
Refer to QueryMethods for documentation about querying the database through this connection.
Note to implementors
The connection must be initialized in #initialize and closed in #do_close.
Override #build_prepared_statement method in order to return a prepared Statement to allow querying.
Override #build_unprepared_statement method in order to return a unprepared Statement to allow querying.
See also Statement to define how the statements are executed.
Override #driver_name to return the name the driver is registered with.
Override #server_name and #server_version to expose what the server reports about itself.
If at any give moment the connection is lost a DB::ConnectionLost should be raised. This will allow the connection pool to try to reconnect or use another connection if available.
Constructors
Instance methods
Creates a transaction from the current context.
If is expected that either Transaction#commit or Transaction#rollback
are called explicitly to release the context.
Returns the canonical name of the driver backing this connection.
The value is always one of the names the driver registers with DB.register_driver (e.g. "postgres", "mysql", "sqlite3").
return this connection to the pool
managed by the database. Should be used
only if the connection was obtained by Database#checkout.
Returns the product name the server identifies as (e.g. "PostgreSQL", "MariaDB"), or nil if the driver can't tell.
Returns the version string as reported by the server, unparsed (e.g. "8.4.9", "12.2.2-MariaDB-ubu2404"), or nil if the driver can't tell.
The format is server-specific.