-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy path03-table-cli.php
More file actions
32 lines (23 loc) · 1.02 KB
/
03-table-cli.php
File metadata and controls
32 lines (23 loc) · 1.02 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
<?php
declare(strict_types=1);
require __DIR__ . '/../../vendor/autoload.php';
use tommyknocker\pdodb\cli\Application;
// Example: basic table CLI flows on SQLite temp file
putenv('PDODB_DRIVER=sqlite');
$dbPath = sys_get_temp_dir() . '/pdodb_table_example_' . uniqid() . '.sqlite';
putenv('PDODB_PATH=' . $dbPath);
putenv('PDODB_NON_INTERACTIVE=1');
$app = new Application();
$run = static function (array $argv) use ($app): void {
echo ">> " . implode(' ', array_slice($argv, 1)) . "\n";
$app->run($argv);
echo "\n";
};
$run(['pdodb', 'table', 'create', 'demo', '--columns=id:int,name:string:nullable', '--force']);
$run(['pdodb', 'table', 'info', 'demo']);
$run(['pdodb', 'table', 'columns', 'add', 'demo', 'price', '--type=float']);
$run(['pdodb', 'table', 'indexes', 'add', 'demo', 'idx_demo_name', '--columns=name']);
$run(['pdodb', 'table', 'indexes', 'list', 'demo', '--format=json']);
$run(['pdodb', 'table', 'truncate', 'demo', '--force']);
$run(['pdodb', 'table', 'drop', 'demo', '--force']);
@unlink($dbPath);