mirror of
https://codeberg.org/vlw/php-mysql.git
synced 2025-09-14 00:33:41 +02:00
Compare commits
2 commits
64c7bae3cf
...
c64eb96049
Author | SHA1 | Date | |
---|---|---|---|
c64eb96049 | |||
e65c74797b |
2 changed files with 22 additions and 8 deletions
|
@ -8,8 +8,10 @@
|
||||||
use mysqli_stmt;
|
use mysqli_stmt;
|
||||||
use mysqli_result;
|
use mysqli_result;
|
||||||
|
|
||||||
|
use vlw\MySQL\Order;
|
||||||
use vlw\MySQL\Operators;
|
use vlw\MySQL\Operators;
|
||||||
|
|
||||||
|
require_once "Order.php";
|
||||||
require_once "Operators.php";
|
require_once "Operators.php";
|
||||||
|
|
||||||
// Interface for MySQL_Driver with abstractions for data manipulation
|
// Interface for MySQL_Driver with abstractions for data manipulation
|
||||||
|
@ -50,7 +52,11 @@
|
||||||
|
|
||||||
// Convert all boolean type values to tinyints in array
|
// Convert all boolean type values to tinyints in array
|
||||||
private static function filter_booleans(array $values): array {
|
private static function filter_booleans(array $values): array {
|
||||||
return array_map(fn($v): mixed => gettype($v) === "boolean" ? self::filter_boolean($v) : $v, $values);
|
return array_map(fn(mixed $v): mixed => gettype($v) === "boolean" ? self::filter_boolean($v) : $v, $values);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function array_wrap_accents(array $input): array {
|
||||||
|
return array_map(fn(mixed $v): string => "`{$v}`", $input);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -174,12 +180,12 @@
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create CSV from columns
|
// Assign Order Enum entries from array of arrays<Order|string>
|
||||||
$sql = implode(",", array_keys($order_by));
|
$orders = array_map(fn(Order|string $order): Order => $order instanceof Order ? $order : Order::tryFrom($order), array_values($order_by));
|
||||||
// Create pipe DSV from values
|
// Create CSV string with Prepared Statement abbreviations from length of fields array.
|
||||||
$sql .= " " . implode("|", array_values($order_by));
|
$sql = array_map(fn(string $column, Order|string $order): string => "`{$column}` " . $order->value, array_keys($order_by), $orders);
|
||||||
|
|
||||||
$this->order_by = $sql;
|
$this->order_by = implode(",", $sql);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,7 +202,7 @@
|
||||||
$this->columns = is_array($columns) || is_null($columns) ? $columns : explode(",", $columns);
|
$this->columns = is_array($columns) || is_null($columns) ? $columns : explode(",", $columns);
|
||||||
|
|
||||||
// Create CSV from columns or default to SQL NULL as a string
|
// Create CSV from columns or default to SQL NULL as a string
|
||||||
$columns_sql = $this->columns ? implode(",", $this->columns) : "NULL";
|
$columns_sql = $this->columns ? implode(",", self::array_wrap_accents($this->columns)) : "NULL";
|
||||||
|
|
||||||
// Create LIMIT statement if argument is defined
|
// Create LIMIT statement if argument is defined
|
||||||
$limit_sql = !is_null($this->limit) ? " LIMIT {$this->limit}" : "";
|
$limit_sql = !is_null($this->limit) ? " LIMIT {$this->limit}" : "";
|
||||||
|
@ -218,7 +224,7 @@
|
||||||
$this->throw_if_no_table();
|
$this->throw_if_no_table();
|
||||||
|
|
||||||
// Create CSV string with Prepared Statement abbreviations from length of fields array.
|
// Create CSV string with Prepared Statement abbreviations from length of fields array.
|
||||||
$changes = array_map(fn($column) => "{$column} = ?", array_keys($entity));
|
$changes = array_map(fn($column) => "`{$column}` = ?", array_keys($entity));
|
||||||
$changes = implode(",", $changes);
|
$changes = implode(",", $changes);
|
||||||
|
|
||||||
// Get array of SQL WHERE string and filter values
|
// Get array of SQL WHERE string and filter values
|
||||||
|
|
8
src/Order.php
Normal file
8
src/Order.php
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace vlw\MySQL;
|
||||||
|
|
||||||
|
enum Order: string {
|
||||||
|
case ASC = "ASC";
|
||||||
|
case DESC = "DESC";
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue