From 302d0cbad060176de114181a63a3a6d98d05fc26 Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Tue, 30 May 2023 12:55:56 +0200 Subject: [PATCH] feat: add static col and val constructors (#3) --- src/SQLite.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/SQLite.php b/src/SQLite.php index 93946f6..6e9653a 100644 --- a/src/SQLite.php +++ b/src/SQLite.php @@ -59,6 +59,27 @@ /* ---- */ + // Create comma separated list (CSV) from array + private static function csv(array $values): string { + return implode(",", $values); + } + + // Create CSV from columns + public static function columns(array|string $columns): string { + return is_array($columns) + ? (__CLASS__)::csv($columns) + : $columns; + } + + // Return CSV of '?' for use with prepared statements + public static function values(array|string $values): string { + return is_array($values) + ? (__CLASS__)::csv(array_fill(0, count($values), "?")) + : "?"; + } + + /* ---- */ + // Get result as column indexed array public function return_array(string $query, mixed $values = []): array { $result = $this->run_query($query, $values);