Database/README.md

42 lines
1.2 KiB
Markdown
Raw Normal View History

2024-07-01 13:58:37 -05:00
# Database
2024-06-30 20:25:20 -05:00
2024-07-01 13:58:37 -05:00
This SQLite database wrapper provides a simple-to-use interface using PDO's SQLite driver.
2024-07-01 13:10:10 -05:00
It was designed to have method signatures very close to Laravel's Eloquent ORM. There
2024-07-01 13:58:37 -05:00
are not, however, any ORM features in this wrapper. These must be handled at
2024-07-01 13:10:10 -05:00
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');
```