Inheritance diagram for DB:Extends PDO and acts as a central access point for the schema.
Protected Properties | |
| Junction[] | $junctions = [] |
| callable | $logger |
| Notified whenever a query is executed or a statement is prepared. More... | |
| string | $migrations = 'migrations/default' |
| The migrations directory for this connection. More... | |
| Record[] | $records = [] |
| Schema | $schema |
| int | $transactions = 0 |
| The count of open transactions/savepoints. More... | |
Public Static Methods | |
| static self | fromConfig (string $connection='default', string $file='db.config.php') |
| Returns a new connection using a configuration file. More... | |
| static ExpressionInterface[] | marks (int $count) |
Returns an array of ? placeholder expressions. More... | |
| static string[] | slots (array $columns) |
Converts an array of columns to :named placeholders for prepared queries. More... | |
Public Methods | |
| __construct ($dsn, $username=null, $password=null, array $options=[]) | |
| Sets various attributes to streamline operations. More... | |
| true | beginTransaction () |
Allows nested transactions by using SAVEPOINT More... | |
| true | commit () |
Allows nested transactions by using RELEASE SAVEPOINT More... | |
| int | exec ($sql) |
| Notifies the logger and executes. More... | |
| mixed | factory (string $class,... $args) |
| Central point of object creation. More... | |
| string | getDriver () |
| The driver's name. More... | |
| Junction | getJunction (string $interface) |
| Returns a Junction access object based on an annotated interface. More... | |
| callable | getLogger () |
| Migrator | getMigrator () |
| Record | getRecord ($class) |
| Returns a Record access object based on an annotated class. More... | |
| Schema | getSchema () |
| bool | isMySQL () |
| bool | isPostgreSQL () |
| bool | isSQLite () |
| void | log (string $sql) |
| Transaction | newTransaction () |
| Returns a scoped transaction. More... | |
| bool | offsetExists ($table) |
| Whether a table exists. More... | |
| null Table | offsetGet ($table) |
| Returns a table by name. More... | |
| offsetSet ($offset, $value) | |
| Throws. More... | |
| offsetUnset ($offset) | |
| Throws. More... | |
| Statement | prepare ($sql, $options=[]) |
| Notifies the logger and prepares a statement. More... | |
| Statement | query ($sql, $mode=PDO::ATTR_DEFAULT_FETCH_MODE, $arg3=null, array $ctorargs=[]) |
| Notifies the logger and queries. More... | |
| string ExpressionInterface | quote ($value, $type=self::PARAM_STR) |
| Quotes a value, with special considerations. More... | |
| string[] | quoteArray (array $values) |
| Quotes an array of values. More... | |
| string | quoteList (array $values) |
| Returns a quoted, comma-separated list. More... | |
| true | rollBack () |
Allows nested transactions by using ROLLBACK TO SAVEPOINT More... | |
| $this | setLogger (callable $logger) |
| $this | setRecord (string $class, Record $record) |
| Installs a Record for a third-party class that cannot be annotated. More... | |
| void | sqliteCreateFunctions (array $callables, bool $deterministic=true) |
| Create multiple SQLite functions at a time. More... | |
| mixed | transact (callable $work) |
| Performs work within a scoped transaction. More... | |
Protected Methods | |
| void | __construct_mysql () |
| MySQL construction hook. More... | |
| void | __construct_sqlite () |
| SQLite construction hook. More... | |
|
protected |
Notified whenever a query is executed or a statement is prepared.
This is a stub-closure by default.
fn($sql): void
|
protected |
The migrations directory for this connection.
This can be set via class override, or configuration file (recommended).
When using DB::fromConfig(), this defaults to migrations/<CONNECTION NAME>
|
protected |
The count of open transactions/savepoints.
| __construct | ( | $dsn, | |
$username = null, |
|||
$password = null, |
|||
| array | $options = [] |
||
| ) |
Sets various attributes to streamline operations.
Registers missing SQLite functions.
| string | $dsn | |
| string | $username | |
| string | $password | |
| array | $options |
|
protected |
MySQL construction hook.
|
protected |
SQLite construction hook.
| true beginTransaction | ( | ) |
Allows nested transactions by using SAVEPOINT
Use DB::newTransaction() to work with Transaction instead.
| true commit | ( | ) |
Allows nested transactions by using RELEASE SAVEPOINT
Use DB::newTransaction() to work with Transaction instead.
| int exec | ( | $sql | ) |
Notifies the logger and executes.
| string | $sql |
| mixed factory | ( | string | $class, |
| $args | |||
| ) |
Central point of object creation.
Override this to override classes.
The only thing that calls this should be \Helix\DB\FactoryTrait
| string | $class | |
| mixed | ...$args |
|
static |
Returns a new connection using a configuration file.
See db.config.php in the test directory for an example.
| string | $connection | |
| string | $file |
|
final |
The driver's name.
| Junction getJunction | ( | string | $interface | ) |
|
final |
| Record getRecord | ( | $class | ) |
Returns a Record access object based on an annotated class.
| string | EntityInterface | $class |
|
final |
|
final |
|
final |
| void log | ( | string | $sql | ) |
| string | $sql |
|
static |
Returns an array of ? placeholder expressions.
| int | $count |
| Transaction newTransaction | ( | ) |
Returns a scoped transaction.
|
final |
Whether a table exists.
| string | $table |
| null Table offsetGet | ( | $table | ) |
Returns a table by name.
| string | $table |
|
final |
Throws.
| $offset | |
| $value |
| LogicException |
|
final |
Throws.
| $offset |
| LogicException |
| Statement prepare | ( | $sql, | |
$options = [] |
|||
| ) |
| Statement query | ( | $sql, | |
$mode = PDO::ATTR_DEFAULT_FETCH_MODE, |
|||
$arg3 = null, |
|||
| array | $ctorargs = [] |
||
| ) |
Notifies the logger and queries.
| string | $sql | |
| int | $mode | |
| mixed | $arg3 | |
| array | $ctorargs |
| string ExpressionInterface quote | ( | $value, | |
$type = self::PARAM_STR |
|||
| ) |
Quotes a value, with special considerations.
| bool | number | string | object | $value | |
| int | $type | Ignored. |
| string [] quoteArray | ( | array | $values | ) |
Quotes an array of values.
Keys are preserved.
| array | $values |
| string quoteList | ( | array | $values | ) |
Returns a quoted, comma-separated list.
| array | $values |
| true rollBack | ( | ) |
Allows nested transactions by using ROLLBACK TO SAVEPOINT
Use DB::newTransaction() to work with Transaction instead.
| $this setLogger | ( | callable | $logger | ) |
| callable | $logger |
| $this setRecord | ( | string | $class, |
| Record | $record | ||
| ) |
|
static |
Converts an array of columns to :named placeholders for prepared queries.
Qualified columns are slotted as qualifier__column (two underscores).
| string[] | $columns |
["column" => ":column"] | void sqliteCreateFunctions | ( | array | $callables, |
| bool | $deterministic = true |
||
| ) |
Create multiple SQLite functions at a time.
| callable[] | $callables | Keyed by function name. |
| bool | $deterministic | Whether the callables aren't random / are without side-effects. |
| mixed transact | ( | callable | $work | ) |
Performs work within a scoped transaction.
The work is rolled back if an exception is thrown.
| callable | $work | fn(DB $this): mixed |
$work