@easy-cms/db-sqlite 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +16 -5
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -12,8 +12,13 @@ import { drizzle } from "drizzle-orm/libsql";
|
|
|
12
12
|
import { index, integer, real, sqliteTable, text, uniqueIndex } from "drizzle-orm/sqlite-core";
|
|
13
13
|
import { DEFAULT_MIGRATION_DIR, DEFAULT_TABLE_PREFIX } from "@easy-cms/drizzle";
|
|
14
14
|
var kit = () => import("drizzle-kit/api");
|
|
15
|
+
var aliases = 0;
|
|
16
|
+
var alias = () => sql.raw(`_el${++aliases % 1e6}`);
|
|
17
|
+
var jsonPath = (path) => `$${path.map((p) => `."${p}"`).join("")}`;
|
|
18
|
+
var onlyArray = (array) => sql`case when json_type(${array}) = 'array' then ${array} end`;
|
|
15
19
|
var sqliteDialect = {
|
|
16
20
|
name: "sqlite",
|
|
21
|
+
singleWriter: true,
|
|
17
22
|
table: (name, columns, indexes) => sqliteTable(name, columns, indexes),
|
|
18
23
|
index: (name) => index(name),
|
|
19
24
|
uniqueIndex: (name) => uniqueIndex(name),
|
|
@@ -25,12 +30,18 @@ var sqliteDialect = {
|
|
|
25
30
|
json: (name) => text(name, { mode: "json" }),
|
|
26
31
|
// LIKE is case-insensitive for ASCII in SQLite.
|
|
27
32
|
like: (column, pattern) => sql`${column} LIKE ${pattern} ESCAPE '\\'`,
|
|
28
|
-
someElement: (
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
someElement: (array, condition) => {
|
|
34
|
+
const el = alias();
|
|
35
|
+
const where = condition({
|
|
36
|
+
get: (path) => path.length === 0 ? sql`${el}.value` : sql`json_extract(${el}.value, ${jsonPath(path)})`,
|
|
37
|
+
list: (path) => sql`json_extract(${el}.value, ${jsonPath(path)})`
|
|
32
38
|
});
|
|
33
|
-
return sql`exists (select 1 from json_each(${
|
|
39
|
+
return sql`exists (select 1 from json_each(${onlyArray(array)}) as ${el}${where ? sql` where ${where}` : sql``})`;
|
|
40
|
+
},
|
|
41
|
+
firstElementValue: (array, path) => {
|
|
42
|
+
const el = alias();
|
|
43
|
+
const value = sql`json_extract(${el}.value, ${jsonPath(path)})`;
|
|
44
|
+
return sql`(select ${value} from json_each(${onlyArray(array)}) as ${el} where ${value} is not null order by ${el}.key limit 1)`;
|
|
34
45
|
},
|
|
35
46
|
param: () => "?",
|
|
36
47
|
migrationsTableSQL: (name) => `CREATE TABLE IF NOT EXISTS \`${name}\` (
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easy-cms/db-sqlite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "SQLite / libSQL database adapter for Easy CMS",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
"@libsql/client": "^0.18.0",
|
|
23
23
|
"drizzle-kit": "0.31.11",
|
|
24
24
|
"drizzle-orm": "0.45.3",
|
|
25
|
-
"@easy-cms/drizzle": "^0.
|
|
25
|
+
"@easy-cms/drizzle": "^0.8.0"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@easy-cms/core": "^0.
|
|
28
|
+
"@easy-cms/core": "^0.8.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"sharp": "^0.35.4",
|
|
32
|
-
"@easy-cms/core": "^0.
|
|
32
|
+
"@easy-cms/core": "^0.8.0"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|