mirror of
https://codeberg.org/vlw/php-mysql.git
synced 2025-09-14 00:33:41 +02:00
feat: limit offset as second argument
This commit is contained in:
parent
d7e6a64415
commit
63baaf0793
1 changed files with 6 additions and 11 deletions
|
@ -17,7 +17,7 @@
|
|||
private ?string $order_by = null;
|
||||
private ?string $filter_sql = null;
|
||||
private array $filter_values = [];
|
||||
private int|string|null $limit = null;
|
||||
private ?string $limit = null;
|
||||
|
||||
// Pass constructor arguments to driver
|
||||
function __construct() {
|
||||
|
@ -151,25 +151,20 @@
|
|||
}
|
||||
|
||||
// Return SQL LIMIT string from integer or array of [offset => limit]
|
||||
public function limit(int|array|null $limit): self {
|
||||
public function limit(?int $limit, ?int $offset = null): self {
|
||||
// Unset row limit if null was passed
|
||||
if ($limit === null) {
|
||||
$this->limit = null;
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Set LIMIT without range directly as integer
|
||||
if (is_int($limit)) {
|
||||
$this->limit = $limit;
|
||||
// No offset defined, set limit property directly as string
|
||||
if (is_null($offset)) {
|
||||
$this->limit = (string) $limit;
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Use array key as LIMIT range start value
|
||||
$offset = (int) array_keys($limit)[0];
|
||||
// Use array value as LIMIT range end value
|
||||
$limit = (int) array_values($limit)[0];
|
||||
|
||||
// Set limit as SQL CSV
|
||||
// Set limit and offset as SQL CSV
|
||||
$this->limit = "{$offset},{$limit}";
|
||||
return $this;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue