ajout colonnes génériques
This commit is contained in:
parent
88436296e7
commit
5ecc9ac3d7
@ -32,19 +32,29 @@ abstract class CapacitorStorage {
|
|||||||
return $channel;
|
return $channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** DOIT être défini dans les classes dérivées */
|
const PRIMARY_KEY_DEFINITION = [
|
||||||
const PRIMARY_KEY_DEFINITION = null;
|
"id_" => "genserial",
|
||||||
|
];
|
||||||
|
|
||||||
|
# les définitions sont par défaut pour MariaDB/MySQL
|
||||||
const SERDATA_DEFINITION = "mediumtext";
|
const SERDATA_DEFINITION = "mediumtext";
|
||||||
const SERSUM_DEFINITION = "varchar(40)";
|
const SERSUM_DEFINITION = "varchar(40)";
|
||||||
const SERTS_DEFINITION = "datetime";
|
const SERTS_DEFINITION = "datetime";
|
||||||
|
const GENSERIAL_DEFINITION = "integer primary key autoincrement";
|
||||||
|
const GENLIC_DEFINITION = "varchar(80)";
|
||||||
|
const GENLIB_DEFINITION = "varchar(255)";
|
||||||
|
const GENTEXT_DEFINITION = "mediumtext";
|
||||||
|
|
||||||
protected static function sercol($def): string {
|
protected static function gencol($def): string {
|
||||||
if (!is_string($def)) $def = strval($def);
|
if (!is_string($def)) $def = strval($def);
|
||||||
switch ($def) {
|
switch ($def) {
|
||||||
case "serdata": $def = static::SERDATA_DEFINITION; break;
|
case "serdata": $def = static::SERDATA_DEFINITION; break;
|
||||||
case "sersum": $def = static::SERSUM_DEFINITION; break;
|
case "sersum": $def = static::SERSUM_DEFINITION; break;
|
||||||
case "serts": $def = static::SERTS_DEFINITION; break;
|
case "serts": $def = static::SERTS_DEFINITION; break;
|
||||||
|
case "genserial": $def = static::GENSERIAL_DEFINITION; break;
|
||||||
|
case "genlic": $def = static::GENLIC_DEFINITION; break;
|
||||||
|
case "genlib": $def = static::GENLIB_DEFINITION; break;
|
||||||
|
case "gentext": $def = static::GENTEXT_DEFINITION; break;
|
||||||
}
|
}
|
||||||
return $def;
|
return $def;
|
||||||
}
|
}
|
||||||
@ -81,7 +91,7 @@ abstract class CapacitorStorage {
|
|||||||
$mindex++;
|
$mindex++;
|
||||||
} else {
|
} else {
|
||||||
if ($mdef) {
|
if ($mdef) {
|
||||||
$definitions[$mcol] = self::sercol($mdef);
|
$definitions[$mcol] = self::gencol($mdef);
|
||||||
} else {
|
} else {
|
||||||
unset($definitions[$mcol]);
|
unset($definitions[$mcol]);
|
||||||
}
|
}
|
||||||
@ -92,7 +102,7 @@ abstract class CapacitorStorage {
|
|||||||
$constraints[] = $def;
|
$constraints[] = $def;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$definitions[$col] = self::sercol($def);
|
$definitions[$col] = self::gencol($def);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cl::merge($definitions, $constraints);
|
return cl::merge($definitions, $constraints);
|
||||||
|
@ -19,10 +19,6 @@ class MysqlStorage extends CapacitorStorage {
|
|||||||
return $this->db;
|
return $this->db;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PRIMARY_KEY_DEFINITION = [
|
|
||||||
"id_" => "integer primary key auto_increment",
|
|
||||||
];
|
|
||||||
|
|
||||||
protected function tableExists(string $tableName): bool {
|
protected function tableExists(string $tableName): bool {
|
||||||
$db = $this->db;
|
$db = $this->db;
|
||||||
$found = $db->get([
|
$found = $db->get([
|
||||||
|
@ -9,6 +9,8 @@ class PgsqlStorage extends CapacitorStorage {
|
|||||||
const SERDATA_DEFINITION = "text";
|
const SERDATA_DEFINITION = "text";
|
||||||
const SERSUM_DEFINITION = "varchar(40)";
|
const SERSUM_DEFINITION = "varchar(40)";
|
||||||
const SERTS_DEFINITION = "timestamp";
|
const SERTS_DEFINITION = "timestamp";
|
||||||
|
const GENSERIAL_DEFINITION = "serial primary key";
|
||||||
|
const GENTEXT_DEFINITION = "text";
|
||||||
|
|
||||||
function __construct($pgsql) {
|
function __construct($pgsql) {
|
||||||
$this->db = Pgsql::with($pgsql);
|
$this->db = Pgsql::with($pgsql);
|
||||||
@ -20,10 +22,6 @@ class PgsqlStorage extends CapacitorStorage {
|
|||||||
return $this->db;
|
return $this->db;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PRIMARY_KEY_DEFINITION = [
|
|
||||||
"id_" => "serial primary key",
|
|
||||||
];
|
|
||||||
|
|
||||||
protected function tableExists(string $tableName): bool {
|
protected function tableExists(string $tableName): bool {
|
||||||
if (($index = strpos($tableName, ".")) !== false) {
|
if (($index = strpos($tableName, ".")) !== false) {
|
||||||
$schemaName = substr($tableName, 0, $index);
|
$schemaName = substr($tableName, 0, $index);
|
||||||
|
@ -19,10 +19,6 @@ class SqliteStorage extends CapacitorStorage {
|
|||||||
return $this->db;
|
return $this->db;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PRIMARY_KEY_DEFINITION = [
|
|
||||||
"id_" => "integer primary key autoincrement",
|
|
||||||
];
|
|
||||||
|
|
||||||
protected function tableExists(string $tableName): bool {
|
protected function tableExists(string $tableName): bool {
|
||||||
$found = $this->db->get([
|
$found = $this->db->get([
|
||||||
# depuis la version 3.33.0 le nom officiel de la table est sqlite_schema,
|
# depuis la version 3.33.0 le nom officiel de la table est sqlite_schema,
|
||||||
|
@ -7,6 +7,12 @@ use nulib\db\Capacitor;
|
|||||||
use nulib\db\CapacitorChannel;
|
use nulib\db\CapacitorChannel;
|
||||||
|
|
||||||
class SqliteStorageTest extends TestCase {
|
class SqliteStorageTest extends TestCase {
|
||||||
|
static function Txx(...$values): void {
|
||||||
|
foreach ($values as $value) {
|
||||||
|
var_export($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function _testChargeStrings(SqliteStorage $storage, ?string $channel) {
|
function _testChargeStrings(SqliteStorage $storage, ?string $channel) {
|
||||||
$storage->reset($channel);
|
$storage->reset($channel);
|
||||||
$storage->charge($channel, "first");
|
$storage->charge($channel, "first");
|
||||||
@ -78,7 +84,7 @@ class SqliteStorageTest extends TestCase {
|
|||||||
$capacitor->each(["age" => [">", 10]], $setDone, ["++"]);
|
$capacitor->each(["age" => [">", 10]], $setDone, ["++"]);
|
||||||
$capacitor->each(["done" => 0], $setDone, null);
|
$capacitor->each(["done" => 0], $setDone, null);
|
||||||
|
|
||||||
Txx(cl::all($capacitor->discharge(false)));
|
self::Txx(cl::all($capacitor->discharge(false)));
|
||||||
$capacitor->close();
|
$capacitor->close();
|
||||||
self::assertTrue(true);
|
self::assertTrue(true);
|
||||||
}
|
}
|
||||||
@ -133,16 +139,16 @@ class SqliteStorageTest extends TestCase {
|
|||||||
$capacitor->charge(["a" => null, "b" => null]);
|
$capacitor->charge(["a" => null, "b" => null]);
|
||||||
$capacitor->charge(["a" => "first", "b" => "second"]);
|
$capacitor->charge(["a" => "first", "b" => "second"]);
|
||||||
|
|
||||||
Txx("=== all");
|
self::Txx("=== all");
|
||||||
/** @var Sqlite $sqlite */
|
/** @var Sqlite $sqlite */
|
||||||
$sqlite = $capacitor->getStorage()->db();
|
$sqlite = $capacitor->getStorage()->db();
|
||||||
Txx(cl::all($sqlite->all([
|
self::Txx(cl::all($sqlite->all([
|
||||||
"select",
|
"select",
|
||||||
"from" => $capacitor->getChannel()->getTableName(),
|
"from" => $capacitor->getChannel()->getTableName(),
|
||||||
])));
|
])));
|
||||||
Txx("=== each");
|
self::Txx("=== each");
|
||||||
$capacitor->each(null, function ($item, $values) {
|
$capacitor->each(null, function ($item, $values) {
|
||||||
Txx($values);
|
self::Txx($values);
|
||||||
});
|
});
|
||||||
|
|
||||||
$capacitor->close();
|
$capacitor->close();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user