ConnectionInterface.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\Database;
  12. use Closure;
  13. use Generator;
  14. use Hyperf\Database\Query\Builder;
  15. use Hyperf\Database\Query\Expression;
  16. use Throwable;
  17. interface ConnectionInterface
  18. {
  19. /**
  20. * Begin a fluent query against a database table.
  21. * @param Expression|string $table
  22. */
  23. public function table($table): Builder;
  24. /**
  25. * Get a new raw query expression.
  26. * @param mixed $value
  27. */
  28. public function raw($value): Expression;
  29. /**
  30. * Run a select statement and return a single result.
  31. */
  32. public function selectOne(string $query, array $bindings = [], bool $useReadPdo = true);
  33. /**
  34. * Run a select statement against the database.
  35. */
  36. public function select(string $query, array $bindings = [], bool $useReadPdo = true): array;
  37. /**
  38. * Run a select statement against the database and returns a generator.
  39. */
  40. public function cursor(string $query, array $bindings = [], bool $useReadPdo = true): Generator;
  41. /**
  42. * Run an insert statement against the database.
  43. */
  44. public function insert(string $query, array $bindings = []): bool;
  45. /**
  46. * Run an update statement against the database.
  47. */
  48. public function update(string $query, array $bindings = []): int;
  49. /**
  50. * Run a delete statement against the database.
  51. */
  52. public function delete(string $query, array $bindings = []): int;
  53. /**
  54. * Execute an SQL statement and return the boolean result.
  55. */
  56. public function statement(string $query, array $bindings = []): bool;
  57. /**
  58. * Run an SQL statement and get the number of rows affected.
  59. */
  60. public function affectingStatement(string $query, array $bindings = []): int;
  61. /**
  62. * Run a raw, unprepared query against the PDO connection.
  63. */
  64. public function unprepared(string $query): bool;
  65. /**
  66. * Prepare the query bindings for execution.
  67. */
  68. public function prepareBindings(array $bindings): array;
  69. /**
  70. * Execute a Closure within a transaction.
  71. *
  72. * @throws Throwable
  73. */
  74. public function transaction(Closure $callback, int $attempts = 1);
  75. /**
  76. * Start a new database transaction.
  77. */
  78. public function beginTransaction(): void;
  79. /**
  80. * Commit the active database transaction.
  81. */
  82. public function commit(): void;
  83. /**
  84. * Rollback the active database transaction.
  85. */
  86. public function rollBack(): void;
  87. /**
  88. * Get the number of active transactions.
  89. */
  90. public function transactionLevel(): int;
  91. /**
  92. * Execute the given callback in "dry run" mode.
  93. */
  94. public function pretend(Closure $callback): array;
  95. }