aboutsummaryrefslogtreecommitdiffstats
path: root/visitors.php
diff options
context:
space:
mode:
authoralyx <alyx@aleteoryx.me>2024-05-24 23:25:32 -0400
committeralyx <alyx@aleteoryx.me>2024-05-24 23:25:32 -0400
commit3688cda46f3fb5ef51a85433a4cbaba5636e07f7 (patch)
tree3b8c445eaa4a4fe88edca4e827408d05d1b92e12 /visitors.php
parent9e379afd368ea6b8cfc6852a8265eba31fc3a758 (diff)
downloadvisitors_dot_php-3688cda46f3fb5ef51a85433a4cbaba5636e07f7.tar.gz
visitors_dot_php-3688cda46f3fb5ef51a85433a4cbaba5636e07f7.tar.bz2
visitors_dot_php-3688cda46f3fb5ef51a85433a4cbaba5636e07f7.zip
database loading
Diffstat (limited to 'visitors.php')
-rw-r--r--visitors.php15
1 files changed, 15 insertions, 0 deletions
diff --git a/visitors.php b/visitors.php
index 47992d0..b93a67b 100644
--- a/visitors.php
+++ b/visitors.php
@@ -70,6 +70,8 @@ $config['use_path_info'] = false;
// *.jsonl - use newline-delimited JSON objects (jsonlines)
// *.csv - use CSV
// *.db, *.sqlite, *.sqlite3 - use Sqlite3
+//
+// If the file extension is unknown, CSV is picked as default.
$config['db'] = 'visitors.csv';
@@ -228,3 +230,16 @@ final class SqliteDatabase extends Database {
return true;
}
}
+
+function get_database_for_file(string $file): Database {
+ $ext = preg_replace('/.+\.([^.]+)$/', '${1}', $file);
+ return match ($ext) {
+ 'db', 'sqlite', 'sqlite3' => new SqliteDatabase($file),
+ 'csv' => new CsvDatabase($file),
+ 'json' => new JsonDatabase($file),
+ 'jsonl' => new JsonlDatabase($file),
+
+ default => new CsvDatabase($file)
+ };
+}
+