chillu / fakedatabase
简单的'数据库'存储适配器,持久化到JSON文件中
3.0.0
2022-08-24 13:04 UTC
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-08-24 17:27:57 UTC
README
介绍
简单的“数据库”存储适配器,持久化到JSON文件中,可以轻松地一瞥整个数据库的状态。它还包含“无模式”存储的所有优点,且不依赖于数据库驱动程序。这使得它在轻量级存储测试数据时非常有用,例如在集成测试中记录和跟踪数据变化。
存储优化了开发者的可读性,而不是性能,因为每次更改都会在磁盘上持久化文件。
用法
// 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);