-
Notifications
You must be signed in to change notification settings - Fork 0
/
PersistenceInterface.php
72 lines (63 loc) · 1.65 KB
/
PersistenceInterface.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php declare(strict_types=1);
namespace DataAccessKit;
interface PersistenceInterface
{
/**
* Run SELECT $sql with $parameters and return an iterable of objects of type $className.
*
* @template T
* @param class-string<T> $className
* @param string $sql
* @param array<int, mixed>|array<string, mixed> $parameters
* @return iterable<T>
*/
public function select(string $className, string $sql, array $parameters = []): iterable;
/**
* Run SELECT $sql with $parameters and return a scalar value.
*
* @param string $sql
* @param array $parameters
* @return scalar
*/
public function selectScalar(string $sql, array $parameters = []): mixed;
/**
* Run INSERT, UPDATE, or DELETE $sql with $parameters and return the number of affected rows.
*
* @param string $sql
* @param array $parameters
* @return int
*/
public function execute(string $sql, array $parameters = []): int;
/**
* Insert data into the database.
*
* @template T
* @param T|T[] $data
*/
public function insert(object|array $data): void;
/**
* Insert or update data in the database.
*
* @template T
* @param T|T[] $data
*/
public function upsert(object|array $data, ?array $columns = null): void;
/**
* Update data in the database based on its primary key.
*/
public function update(object $data, ?array $columns = null): void;
/**
* Delete data from the database based on its primary key.
*
* @template T
* @param T|T[] $data
*/
public function delete(object|array $data): void;
/**
* Convert $object to an associative array.
*
* @param object $object
* @return array
*/
public function toRow(object $object): array;
}