From d6d70fe406a21b600a0fa0ca403313dd8c8a746d Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Tue, 11 Jun 2024 07:03:50 -0400 Subject: [PATCH] Add config details to README --- README.md | 19 +++++++++++++++++++ tests/unit/QueryTest.php | 4 ++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7da0a6f..2692701 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,25 @@ This library allows SQLite (and, by v1.0.0-beta1, PostgreSQL) to be treated as a `composer require bit-badger/pdo-document` +## Configuration + +### Connection Details + +The static variable `Configuration::$pdoDSN` must be set to the [PDO data source name](https://www.php.net/manual/en/pdo.construct.php#refsect1-pdo.construct-parameters) for your database. `Configuration` also has `$username`, `$password`, and `$options` variables that will be used to construct the PDO object it will use for data access. + +### Document Identifiers + +Each document must have a unique identifier. By default, the library assumes that this is a property or array key named `id`, but this can be controlled by setting `Configuration::$idField`. Once documents exist, this should not be changed. + +IDs can be generated automatically on insert. The `AutoId` enumeration has 4 values: + +- `AutoId::None` is the default; no IDs will be generated +- `AutoId::Number` will assign max-ID-plus-one to documents with an ID of 0 +- `AutoId::UUID` will generate a v4 UUID for documents with an empty `string` ID +- `AutoId::RandomString` will generate a string of letters and numbers for documents with an empty `string` ID; `Configuration::$idStringLength` controls the length of the generated string, and defaults to 16 characters + +In all generated scenarios, if the ID value is not 0 or blank, that ID will be used instead of a generated one. + ## Usage Documentation for this library is not complete; however, its structure is very similar to the .NET version, so [its documentation will help](https://bitbadger.solutions/open-source/relational-documents/basic-usage.html) until its project specific documentation is developed. Things like `Count.All()` become `Count::all`, and all the `byField` operations are named `byFields` and take an array of fields. diff --git a/tests/unit/QueryTest.php b/tests/unit/QueryTest.php index b9e38d4..a816157 100644 --- a/tests/unit/QueryTest.php +++ b/tests/unit/QueryTest.php @@ -161,7 +161,7 @@ class QueryTest extends TestCase #[TestDox('Insert succeeds with auto random string for SQLite')] public function testInsertSucceedsWithAutoRandomStringForSQLite(): void { - Configuration::$mode = Mode::SQLite; + Configuration::$mode = Mode::SQLite; try { $query = Query::insert('test_tbl', AutoId::RandomString); $this->assertStringStartsWith("INSERT INTO test_tbl VALUES (json_set(:data, '$.id', '", $query, @@ -170,7 +170,7 @@ class QueryTest extends TestCase $id = str_replace(["INSERT INTO test_tbl VALUES (json_set(:data, '$.id', '", "'))"], '', $query); $this->assertEquals(16, strlen($id), "Generated ID [$id] should have been 16 characters long"); } finally { - Configuration::$mode = null; + Configuration::$mode = null; } }