Pairity/src/Contracts/ConnectionInterface.php
Funky Waddle 68f3c05868
Some checks are pending
CI / test (8.2) (push) Waiting to run
CI / test (8.3) (push) Waiting to run
Cache and some other things
2026-01-06 10:56:40 -06:00

54 lines
1.4 KiB
PHP

<?php
namespace Pairity\Contracts;
interface ConnectionInterface
{
/**
* Execute a SELECT (or any returning) statement and fetch all rows as associative arrays.
*
* @param string $sql
* @param array<string, mixed> $params
* @return array<int, array<string, mixed>>
*/
public function query(string $sql, array $params = []): array;
/**
* Execute a non-SELECT statement (INSERT/UPDATE/DELETE).
*
* @param string $sql
* @param array<string, mixed> $params
* @return int affected rows
*/
public function execute(string $sql, array $params = []): int;
/**
* Run a callback within a transaction.
* Rolls back on throwable and rethrows it.
*
* @template T
* @param callable($this):T $callback
* @return mixed
*/
public function transaction(callable $callback): mixed;
/**
* Return the underlying driver connection (e.g., PDO).
* @return mixed
*/
public function getNative(): mixed;
/**
* Get last inserted ID if supported.
*/
public function lastInsertId(): ?string;
/**
* Run a callback without performing any persistent changes, returning the logged SQL.
*
* @param callable($this):void $callback
* @return array<int, array{sql: string, params: array<string, mixed>}>
*/
public function pretend(callable $callback): array;
}