-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSqliteFileModel.php
More file actions
41 lines (33 loc) · 1.07 KB
/
Copy pathSqliteFileModel.php
File metadata and controls
41 lines (33 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Waad\Truffle\Enums\DataType;
use Waad\Truffle\Truffle;
/**
* Persist data to a SQLite file instead of in-memory.
* Ideal for large datasets that don't need rebuilding every request.
*/
class Region extends Model
{
use Truffle;
protected static $truffleSqliteFile;
protected $schema = [
'id' => DataType::Id,
'name' => DataType::String,
'timezone' => DataType::String,
];
protected $records = [
['id' => 1, 'name' => 'US East', 'timezone' => 'America/New_York'],
['id' => 2, 'name' => 'US West', 'timezone' => 'America/Los_Angeles'],
['id' => 3, 'name' => 'Europe', 'timezone' => 'Europe/London'],
];
public function __construct(array $attributes = [])
{
static::$truffleSqliteFile ??= storage_path('truffle/regions.sqlite');
parent::__construct($attributes);
}
}
// Usage:
// Region::all();
// Region::deleteTruffleSqliteFile(); // delete the file
// Region::refreshTruffleSqliteFile(); // delete + rebuild