Skip to content

Commit

Permalink
fix(db): add sqlite support
Browse files Browse the repository at this point in the history
- add support for views and specially filtering
- see known bugs: #453 (comment)

Signed-off-by: Florian Steffens <florian.steffens@nextcloud.com>
  • Loading branch information
Florian Steffens committed Aug 31, 2023
1 parent 3812308 commit 18d9d6d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
1 change: 1 addition & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Have a good time and manage whatever you want.
<dependencies>
<database>pgsql</database>
<database>mysql</database>
<database>sqlite</database>
<nextcloud min-version="25" max-version="27"/>
</dependencies>
<commands>
Expand Down
11 changes: 5 additions & 6 deletions lib/Db/ColumnTypes/SuperColumnQB.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public function formatCellValue(string $unformattedValue): string {
if ($this->platform === self::DB_PLATFORM_PGSQL) {
return 'LOWER('.$unformattedValue.')';
} elseif ($this->platform === self::DB_PLATFORM_SQLITE) {
// TODO DB BE SQLITE
return '';
return $unformattedValue;
} else { // mariadb / mysql
return 'JSON_UNQUOTE(LOWER(' . $unformattedValue . '))';
}
Expand Down Expand Up @@ -80,9 +79,9 @@ private function sqlFilterOperation(string $operator, string $formattedCellValue

private function getFormattedDataCellValue(string $columnPlaceHolder, int $columnId): string {
if ($this->platform === self::DB_PLATFORM_PGSQL) {
$cellValue = 'c'.intval($columnId).' ->> \'value\'';
$cellValue = 'c'.$columnId.' ->> \'value\'';
} elseif ($this->platform === self::DB_PLATFORM_SQLITE) {
// TODO DB BE SQLITE
$cellValue = 'json_extract(t2.value, "$.columnId") = '.$columnId.' AND LOWER(json_extract(t2.value, "$.value"))';
} else {
$cellValue = 'JSON_EXTRACT(data, CONCAT( JSON_UNQUOTE(JSON_SEARCH(JSON_EXTRACT(data, \'$[*].columnId\'), \'one\', :'.$columnPlaceHolder.')), \'.value\'))';
}
Expand Down Expand Up @@ -134,8 +133,8 @@ public function addWhereFilterExpression(IQueryBuilder $qb, array $filter, strin
if ($this->platform === self::DB_PLATFORM_PGSQL) {
$sqlFilterString = $filterOperation;
} elseif ($this->platform === self::DB_PLATFORM_SQLITE) {
// TODO DB BE SQLITE
$sqlFilterString = '';
$qb->from($qb->createFunction('json_each(data) as t2'));
$sqlFilterString = $filterOperation;
} else { // mariadb / mysql
$sqlFilterString = $filterOperation;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Db/RowMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ private function addOrderByRules(IQueryBuilder $qb, $sortArray) {
if ($this->platform === IColumnTypeQB::DB_PLATFORM_PGSQL) {
$orderString = 'c'.$sortRule['columnId'].'->>\'value\'';
} elseif ($this->platform === IColumnTypeQB::DB_PLATFORM_SQLITE) {
// TODO DB BE SQLITE
$orderString = '';
// here is an error for (multiple) sorting, works only for the first column at the moment
$orderString = 'json_extract(t2.value, "$.value")';
} else { // mariadb / mysql
$orderString = 'JSON_EXTRACT(data, CONCAT( JSON_UNQUOTE(JSON_SEARCH(JSON_EXTRACT(data, \'$[*].columnId\'), \'one\', :'.$sortColumnPlaceholder.')), \'.value\'))';
}
Expand Down

0 comments on commit 18d9d6d

Please sign in to comment.