pdo-document/README.md
Daniel J. Summers 330e272187 alpha2 (#2)
- Change multiple field matching to enum
- Implement auto-generated IDs

Reviewed-on: #2
2024-06-11 11:07:56 +00:00

33 lines
2.1 KiB
Markdown

# PDODocument
This library allows SQLite (and, by v1.0.0-beta1, PostgreSQL) to be treated as a document database. It is a PHP implementation of the .NET [BitBadger.Documents](https://git.bitbadger.solutions/bit-badger/BitBadger.Documents) library.
## Add via Composer
![Packagist Version](https://img.shields.io/packagist/v/bit-badger/pdo-document)
`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 <abbr title="Universally Unique Identifier">UUID</abbr> 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.