chillu / fakedatabase
Simple 'database' storage adapter which persists into a JSON file
Installs: 2 698
Dependents: 1
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 3
Open Issues: 0
Requires
- php: ^7.2 || ^8.0
- ext-json: *
Requires (Dev)
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.4
This package is auto-updated.
Last update: 2024-10-24 17:45:46 UTC
README
Introduction
Simple "database" storage adapter which persists into a JSON file, making it easy to see the whole database state at a glance. It also carries all the benefits of "schema-less" storage, and doesn't have external dependencies on database drivers. This makes it useful for lightweight storage of test data, e.g. when recording and tracking data changes in integration tests.
The storage is optimized for developer readability as opposed to performance, since the file is persisted on disk every time a change is made.
Usage
// Instanciation $db = new FakeDatabase('/tmp/my_database.json'); // Set a new object with the key 'john' (or override an existing one) $db->set('User', 'john', new FakeObject(array( 'email' => 'john@test.com', 'firstname' => 'John', 'address' => array( 'street' => 'Test Road', 'city' => 'Testington', 'postcode' => 9999 ) ))); // Update (merges with existing data through array_merge()) $db->update('User', 'john', new FakeObject(array('surname' => 'Test'))); // Get all objects for a certain type $objs = $db->getAll('User'); // Get by key $obj = $db->get('User', 'john'); // Simple find $obj = $db->find('User', 'email', 'john@test.com'); // Complex find by dot notation $obj - $db->find('User', 'address.postcode', 9999); // Reset the whole database $db->reset('User', 'address.postcode', 9999);