diff options
Diffstat (limited to 'visitors.php')
-rw-r--r-- | visitors.php | 15 |
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) + }; +} + |