5
use Upside\Db\SQL\Insert;
6
use Upside\Db\SQL\InsertStatement;
7
use Upside\Db\SQL\Query;
8
use Upside\Db\SQL\Update;
12
protected Connection $connection;
13
protected ?Schema $schema = null;
15
public function __construct(Connection $connection)
17
$this->connection = $connection;
20
public function get_connection(): Connection
22
return $this->connection;
26
* Returns the query log for this database.
28
public function get_log(): array
30
return $this->connection->get_log();
34
* Execute a query in order to fetch or to delete records.
36
* @param array|string $tables Table name or an array of tables
38
public function from(array|string $tables): Query
40
return new Query($this->connection, $tables);
44
* Insert new records into a table.
46
* @param array $values An array of values.
48
public function insert(array $values): InsertStatement
50
return (new Insert($this->connection))->insert($values);
56
* @param string $table Table name
58
public function update(string $table): Update
60
return new Update($this->connection, $table);
64
* The associated schema instance.
66
public function schema(): Schema
68
if ($this->schema === null) {
69
$this->schema = $this->connection->get_schema();
76
* Performs a transaction
78
public function transaction(callable $query, mixed $default = null): mixed
80
return $this->connection->transaction($query, $this, $default);