Much work on queries

This commit is contained in:
2023-08-26 17:18:05 -04:00
parent dc31b65be8
commit 7421f9c788
7 changed files with 66 additions and 115 deletions

View File

@@ -17,7 +17,7 @@ class Data
public static function configure()
{
Configuration::$connectionString = 'pgsql:host=localhost;port=5432;dbname=leafjson;user=leaf;password=leaf';
//Configuration::$startUp = '\MyPrayerJournal\Data::startUp';
Configuration::$startUp = '\MyPrayerJournal\Data::startUp';
}
/**
@@ -103,12 +103,12 @@ class Data
*/
private static function getJournalByAnswered(string $userId, string $op): array
{
$sql = Query::selectFromTable(self::REQ_TABLE)
. ' WHERE ' . Query::whereDataContains('$1') . ' AND ' . Query::whereJsonPathMatches('$2');
$params = [
Query::jsonbDocParam([ 'userId' => $userId ]),
'$.history[*].action (@ ' . $op . ' "' . RequestAction::Answered->name . '")'
];
$isAnswered = str_replace(':path',
"'$.history[*].action ? (@ $op \"" . RequestAction::Answered->name . "\")'",
Query::whereJsonPathMatches(':path'));
$sql = sprintf("%s WHERE %s AND $isAnswered", Query::selectFromTable(self::REQ_TABLE),
Query::whereDataContains(':criteria'));
$params = [ ':criteria' => Query::jsonbDocParam([ 'userId' => $userId ]) ];
return self::mapToJournalRequest(
Document::customList($sql, $params, Request::class, Document::mapFromJson(...)), true);
}