Change to PDODocument library
This commit is contained in:
@@ -2,16 +2,16 @@
|
||||
|
||||
namespace FeedReaderCentral;
|
||||
|
||||
use BitBadger\Documents\DocumentException;
|
||||
use BitBadger\Documents\Field;
|
||||
use BitBadger\Documents\SQLite\Configuration;
|
||||
use BitBadger\Documents\SQLite\Custom;
|
||||
use BitBadger\Documents\SQLite\Definition;
|
||||
use BitBadger\Documents\StringMapper;
|
||||
use BitBadger\PDODocument\Configuration;
|
||||
use BitBadger\PDODocument\Custom;
|
||||
use BitBadger\PDODocument\Definition;
|
||||
use BitBadger\PDODocument\DocumentException;
|
||||
use BitBadger\PDODocument\Field;
|
||||
use BitBadger\PDODocument\Mapper\StringMapper;
|
||||
use DateTimeImmutable;
|
||||
use DateTimeInterface;
|
||||
use Exception;
|
||||
use SQLite3;
|
||||
use PDO;
|
||||
|
||||
/**
|
||||
* A centralized place for data access for the application
|
||||
@@ -21,18 +21,18 @@ class Data
|
||||
/**
|
||||
* Create the search index and synchronization triggers for the item table
|
||||
*
|
||||
* @param SQLite3 $db The database connection on which these will be created
|
||||
* @param PDO $pdo The database connection on which these will be created
|
||||
* @throws DocumentException If any is encountered
|
||||
*/
|
||||
public static function createSearchIndex(SQLite3 $db): void
|
||||
public static function createSearchIndex(PDO $pdo): void
|
||||
{
|
||||
Custom::nonQuery("CREATE VIRTUAL TABLE item_search USING fts5(content, content='item', content_rowid='id')",
|
||||
[], $db);
|
||||
[], $pdo);
|
||||
Custom::nonQuery(<<<'SQL'
|
||||
CREATE TRIGGER item_ai AFTER INSERT ON item BEGIN
|
||||
INSERT INTO item_search (rowid, content) VALUES (new.data->>'id', new.data->>'content');
|
||||
END;
|
||||
SQL, [], $db);
|
||||
SQL, [], $pdo);
|
||||
Custom::nonQuery(<<<'SQL'
|
||||
CREATE TRIGGER item_au AFTER UPDATE ON item BEGIN
|
||||
INSERT INTO item_search (
|
||||
@@ -42,7 +42,7 @@ class Data
|
||||
);
|
||||
INSERT INTO item_search (rowid, content) VALUES (new.data->>'id', new.data->>'content');
|
||||
END;
|
||||
SQL, [], $db);
|
||||
SQL, [], $pdo);
|
||||
Custom::nonQuery(<<<'SQL'
|
||||
CREATE TRIGGER item_ad AFTER DELETE ON item BEGIN
|
||||
INSERT INTO item_search (
|
||||
@@ -51,7 +51,7 @@ class Data
|
||||
'delete', old.data->>'id', old.data->>'content'
|
||||
);
|
||||
END;
|
||||
SQL, [], $db);
|
||||
SQL, [], $pdo);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,23 +62,22 @@ class Data
|
||||
public static function ensureDb(): void
|
||||
{
|
||||
$tables = Custom::array("SELECT name FROM sqlite_master WHERE type = 'table'", [], new StringMapper('name'));
|
||||
$db = Configuration::dbConn();
|
||||
$pdo = Configuration::dbConn();
|
||||
if (!in_array(Table::USER, $tables)) {
|
||||
Definition::ensureTable(Table::USER, $db);
|
||||
Definition::ensureFieldIndex(Table::USER, 'email', ['email'], $db);
|
||||
Definition::ensureTable(Table::USER, $pdo);
|
||||
Definition::ensureFieldIndex(Table::USER, 'email', ['email'], $pdo);
|
||||
}
|
||||
if (!in_array(Table::FEED, $tables)) {
|
||||
Definition::ensureTable(Table::FEED, $db);
|
||||
Definition::ensureFieldIndex(Table::FEED, 'user', ['user_id'], $db);
|
||||
Definition::ensureTable(Table::FEED, $pdo);
|
||||
Definition::ensureFieldIndex(Table::FEED, 'user', ['user_id'], $pdo);
|
||||
}
|
||||
if (!in_array(Table::ITEM, $tables)) {
|
||||
Definition::ensureTable(Table::ITEM, $db);
|
||||
Definition::ensureFieldIndex(Table::ITEM, 'feed', ['feed_id', 'item_link'], $db);
|
||||
self::createSearchIndex($db);
|
||||
Definition::ensureTable(Table::ITEM, $pdo);
|
||||
Definition::ensureFieldIndex(Table::ITEM, 'feed', ['feed_id', 'item_link'], $pdo);
|
||||
self::createSearchIndex($pdo);
|
||||
}
|
||||
$journalMode = Custom::scalar("PRAGMA journal_mode", [], fn($it) => $it[0]);
|
||||
$journalMode = Custom::scalar("PRAGMA journal_mode", [], new StringMapper('journal_mode'));
|
||||
if ($journalMode <> 'wal') Custom::nonQuery("PRAGMA journal_mode = 'wal'", []);
|
||||
$db->close();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,7 +102,7 @@ class Data
|
||||
*/
|
||||
public static function feedField(int $feedId, string $qualifier = ''): Field
|
||||
{
|
||||
$feedField = Field::EQ(Configuration::idField(), $feedId, '@feed');
|
||||
$feedField = Field::EQ(Configuration::$idField, $feedId, '@feed');
|
||||
$feedField->qualifier = $qualifier;
|
||||
return $feedField;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user