42 lines
916 B
PHP
42 lines
916 B
PHP
<?php
|
|
require __DIR__.'/../vendor/autoload.php';
|
|
|
|
use nulib\cl;
|
|
use nulib\db\Capacitor;
|
|
use nulib\db\CapacitorChannel;
|
|
use nulib\db\pgsql\Pgsql;
|
|
use nulib\db\pgsql\PgsqlStorage;
|
|
|
|
$db = new Pgsql([
|
|
"host" => "pegase-dre.self",
|
|
"dbname" => "dre",
|
|
"user" => "root",
|
|
"password" => "admin",
|
|
#"user" => "reader",
|
|
#"password" => "reader",
|
|
]);
|
|
|
|
class MyChannel extends CapacitorChannel {
|
|
const TABLE_NAME = "my";
|
|
const COLUMN_DEFINITIONS = [
|
|
"name" => "varchar not null",
|
|
"age" => "integer",
|
|
"num" => ["integer"],
|
|
];
|
|
|
|
function getItemValues($item): ?array {
|
|
$item = cl::with($item);
|
|
return [
|
|
"name" => cl::first($item),
|
|
"age" => $item["age"] ?? null,
|
|
"num" => rand(),
|
|
];
|
|
}
|
|
}
|
|
|
|
new Capacitor(new PgsqlStorage($db), $channel = new MyChannel());
|
|
|
|
$channel->charge("hello world");
|
|
$channel->charge(["bonjour monde"]);
|
|
$channel->charge(["gutten tag", "age" => 15]);
|