2024-06-30 20:25:20 -05:00
|
|
|
# DBLite
|
|
|
|
|
2024-07-01 13:10:10 -05:00
|
|
|
The DBLite wrapper provides a simple-to-use database API using PDO's SQLite driver.
|
|
|
|
It was designed to have method signatures very close to Laravel's Eloquent ORM. There
|
|
|
|
are not, however, any ORM features in the DBLite wrapper. These must be handled at
|
|
|
|
the model level.
|
|
|
|
|
|
|
|
By default, foreign keys are enabled and the database is in WAL mode. In general
|
|
|
|
these defaults should be perfect for most use cases.
|
|
|
|
|
|
|
|
## Testing
|
|
|
|
I wrote a simple test file; run it with PHP directly. `php test.php`
|
|
|
|
This test script covers almost every relevant method in the class.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
```php
|
|
|
|
$db = new Database('test.db');
|
|
|
|
|
|
|
|
$db->table('test')->create([
|
|
|
|
'id INTEGER PRIMARY KEY',
|
|
|
|
'name TEXT NOT NULL',
|
|
|
|
'age INTEGER DEFAULT 18'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$db->table('test')->insert([
|
|
|
|
'name' => 'John',
|
|
|
|
'age' => 32
|
|
|
|
]);
|
|
|
|
|
|
|
|
$db->table('test')->where('name', '=', 'John')->select();
|
|
|
|
$db->table('test')->where('age', '>', 16)->selectAll();
|
|
|
|
|
|
|
|
$db->table('test')->where('name', '=', 'John')->delete();
|
|
|
|
```
|
|
|
|
|
|
|
|
## Notes
|
|
|
|
`Database->table()` sets the current working table's name; there is no real need to use it for every query.
|
|
|
|
```php
|
|
|
|
$db->table('test');
|
|
|
|
$db->where('name', '=', 'John')->select();
|
|
|
|
$db->where('age', '>', 16)->selectAll('age');
|
|
|
|
```
|