@gscdump/engine-sqlite 0.9.2 → 0.11.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.d.mts +9 -4
- package/dist/index.mjs +31 -21
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnalysisQuerySource } from "@gscdump/engine/source";
|
|
2
|
+
import { ResolverAdapter } from "@gscdump/engine/resolver";
|
|
2
3
|
import { SQL, SQL as SQL$1, and, eq, gte, lte, sql } from "drizzle-orm";
|
|
3
|
-
import * as _$drizzle_orm_sqlite_core0 from "drizzle-orm/sqlite-core";
|
|
4
|
-
import { ManifestStore } from "@gscdump/engine";
|
|
5
4
|
import * as _$_gscdump_engine_scope0 from "@gscdump/engine/scope";
|
|
6
5
|
import { ScopedRunnerOptions, TableScope } from "@gscdump/engine/scope";
|
|
6
|
+
import * as _$drizzle_orm_sqlite_core0 from "drizzle-orm/sqlite-core";
|
|
7
7
|
import { SqliteRemoteDatabase } from "drizzle-orm/sqlite-proxy";
|
|
8
|
+
import { ManifestStore } from "@gscdump/engine";
|
|
8
9
|
import { ComparisonMode, ResolveWindowOptions, ResolvedWindow, WindowPreset, resolveWindow } from "@gscdump/engine/period";
|
|
9
10
|
import { DrizzleD1Database } from "drizzle-orm/d1";
|
|
10
11
|
/**
|
|
@@ -2233,6 +2234,10 @@ declare const schema: {
|
|
|
2233
2234
|
}>;
|
|
2234
2235
|
};
|
|
2235
2236
|
type Schema = typeof schema;
|
|
2237
|
+
declare function compileSqlite(query: SQL$1): {
|
|
2238
|
+
sql: string;
|
|
2239
|
+
params: unknown[];
|
|
2240
|
+
};
|
|
2236
2241
|
type SqliteRowExecutor = (sql: string, params: unknown[], method: 'run' | 'all' | 'values' | 'get') => Promise<{
|
|
2237
2242
|
rows: unknown[];
|
|
2238
2243
|
}>;
|
|
@@ -2273,7 +2278,7 @@ interface EngineConfig {
|
|
|
2273
2278
|
/** Override for hosts that expose REGEXP (D1, libsql, sqlite3+regexp). */
|
|
2274
2279
|
regex?: boolean;
|
|
2275
2280
|
}
|
|
2276
|
-
declare function createEngine(config: EngineConfig):
|
|
2281
|
+
declare function createEngine(config: EngineConfig): AnalysisQuerySource;
|
|
2277
2282
|
type MetricTable = typeof gsc_pages | typeof gsc_keywords | typeof gsc_countries | typeof gsc_devices | typeof gsc_page_keywords;
|
|
2278
2283
|
declare function aggClicks(t: MetricTable): SQL$1;
|
|
2279
2284
|
declare function aggImpressions(t: MetricTable): SQL$1;
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createSqlQuerySource } from "@gscdump/engine/source";
|
|
2
|
+
import { assertSchemaInSync, createResolverAdapter } from "@gscdump/engine/resolver";
|
|
2
3
|
import { and, and as and$1, eq, eq as eq$1, gte, inArray, isNotNull, isNull, lt, lte, lte as lte$1, or, sql, sql as sql$1 } from "drizzle-orm";
|
|
3
|
-
import { index, integer, primaryKey, real, sqliteTable, text, unique } from "drizzle-orm/sqlite-core";
|
|
4
|
-
import { inferSearchType } from "@gscdump/engine";
|
|
5
4
|
import { createScopedHelpers } from "@gscdump/engine/scope";
|
|
5
|
+
import { SQLiteAsyncDialect, index, integer, primaryKey, real, sqliteTable, text, unique } from "drizzle-orm/sqlite-core";
|
|
6
6
|
import { drizzle } from "drizzle-orm/sqlite-proxy";
|
|
7
|
+
import { inferSearchType } from "@gscdump/engine";
|
|
7
8
|
import { resolveWindow } from "@gscdump/engine/period";
|
|
8
9
|
function metricCols() {
|
|
9
10
|
return {
|
|
@@ -69,6 +70,31 @@ assertSchemaInSync({
|
|
|
69
70
|
tableKeyToName: (key) => key.replace(GSC_PREFIX_RE, ""),
|
|
70
71
|
mode: "superset"
|
|
71
72
|
});
|
|
73
|
+
const sqliteDialect = new SQLiteAsyncDialect();
|
|
74
|
+
function compileSqlite(query) {
|
|
75
|
+
const compiled = sqliteDialect.sqlToQuery(query);
|
|
76
|
+
return {
|
|
77
|
+
sql: compiled.sql,
|
|
78
|
+
params: compiled.params
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function createSqliteInsightRunner(opts) {
|
|
82
|
+
const { executor, logger, rowsAsArrays, schema: schemaOverride } = opts;
|
|
83
|
+
const callback = async (sql, params, method) => {
|
|
84
|
+
const result = await executor(sql, params, method);
|
|
85
|
+
if (!rowsAsArrays) return { rows: result.rows };
|
|
86
|
+
return { rows: result.rows.map((r) => {
|
|
87
|
+
if (Array.isArray(r)) return r;
|
|
88
|
+
if (r && typeof r === "object") return Object.values(r);
|
|
89
|
+
return r;
|
|
90
|
+
}) };
|
|
91
|
+
};
|
|
92
|
+
return { db: drizzle(callback, {
|
|
93
|
+
schema: schemaOverride ?? schema,
|
|
94
|
+
logger
|
|
95
|
+
}) };
|
|
96
|
+
}
|
|
97
|
+
const { scopeFor, mergeScope } = createScopedHelpers(schema);
|
|
72
98
|
function createSqliteResolverAdapter(options = {}) {
|
|
73
99
|
return createResolverAdapter({
|
|
74
100
|
schema,
|
|
@@ -84,7 +110,7 @@ function createSqliteResolverAdapter(options = {}) {
|
|
|
84
110
|
regexPredicate: (expr, pattern, negate) => negate ? sql$1`NOT (${expr} REGEXP ${pattern})` : sql$1`${expr} REGEXP ${pattern}`,
|
|
85
111
|
tableLabel: "sqlite/resolver-adapter",
|
|
86
112
|
includeSiteId: true,
|
|
87
|
-
compile: compileSqlite
|
|
113
|
+
compile: compileSqlite,
|
|
88
114
|
capabilities: {
|
|
89
115
|
regex: options.regex ?? false,
|
|
90
116
|
comparisonJoin: true,
|
|
@@ -103,6 +129,7 @@ function createEngine(config) {
|
|
|
103
129
|
const { executor, siteId, regex } = config;
|
|
104
130
|
return createSqlQuerySource({
|
|
105
131
|
name: "sqlite",
|
|
132
|
+
kind: "local",
|
|
106
133
|
adapter: regex === void 0 ? sqliteResolverAdapter : createSqliteResolverAdapter({ regex }),
|
|
107
134
|
execute: async (sql, params) => {
|
|
108
135
|
return (await executor(sql, params, "all")).rows;
|
|
@@ -472,21 +499,4 @@ function createD1ManifestStore(db) {
|
|
|
472
499
|
purgeTenant
|
|
473
500
|
};
|
|
474
501
|
}
|
|
475
|
-
function createSqliteInsightRunner(opts) {
|
|
476
|
-
const { executor, logger, rowsAsArrays, schema: schemaOverride } = opts;
|
|
477
|
-
const callback = async (sql, params, method) => {
|
|
478
|
-
const result = await executor(sql, params, method);
|
|
479
|
-
if (!rowsAsArrays) return { rows: result.rows };
|
|
480
|
-
return { rows: result.rows.map((r) => {
|
|
481
|
-
if (Array.isArray(r)) return r;
|
|
482
|
-
if (r && typeof r === "object") return Object.values(r);
|
|
483
|
-
return r;
|
|
484
|
-
}) };
|
|
485
|
-
};
|
|
486
|
-
return { db: drizzle(callback, {
|
|
487
|
-
schema: schemaOverride ?? schema,
|
|
488
|
-
logger
|
|
489
|
-
}) };
|
|
490
|
-
}
|
|
491
|
-
const { scopeFor, mergeScope } = createScopedHelpers(schema);
|
|
492
502
|
export { aggClicks, aggCtr, aggImpressions, aggPosition, and, compileSqlite, createD1ManifestStore, createEngine, createSqliteInsightRunner, createSqliteResolverAdapter, createSqliteResolverAdapterFromExecutor, eq, gsc_countries, gsc_devices, gsc_keywords, gsc_page_keywords, gsc_pages, gte, lte, mergeScope, probeSqliteRegex, r2Locks, r2Manifest, r2ShadowDiffs, r2SyncStates, r2Watermarks, r2WriteErrors, resolveWindow, schema, scopeFor, sql, sqliteResolverAdapter };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gscdump/engine-sqlite",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.11.0",
|
|
5
5
|
"description": "SQLite / D1 engine adapter for @gscdump/analysis — typed analytics over sqlite-proxy executors (Cloudflare D1, libsql).",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Harlan Wilton",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"drizzle-orm": "^0.45.2"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@gscdump/engine": "0.
|
|
48
|
-
"gscdump": "0.
|
|
47
|
+
"@gscdump/engine": "0.11.0",
|
|
48
|
+
"gscdump": "0.11.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"drizzle-orm": "^0.45.2",
|