@aiao/rxdb-adapter-pglite 0.0.3 → 0.0.4

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Aiao Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -69,3 +69,4 @@ export declare class PGliteClient implements IPGliteClient {
69
69
  version(): Promise<string>;
70
70
  }
71
71
  export {};
72
+ //# sourceMappingURL=PGliteClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PGliteClient.d.ts","sourceRoot":"","sources":["../src/PGliteClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAU,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGvG,UAAU,mBAAmB;IAC3B,KAAK,CAAC,EAAE,QAAQ,GAAG,KAAK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AC,CAAC,EAAE,UAAU,EAAE,oBAAoB,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAI/E,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAIpE,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAIpF,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAIlF,WAAW,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAIrE,YAAY,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAIjD,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrB,OAAO;CAId"}
@@ -1,6 +1,6 @@
1
- import { EntityType, IRepository, IRxDBAdapter, RxDB, RxDBAdapterLocalBase, TransactionFun } from '@aiao/rxdb';
1
+ import { EntityType, IRepository, IRxDBAdapter, RestoreEntityOptions, RxDB, RxDBAdapterLocalBase, TransactionFun } from '@aiao/rxdb';
2
2
  import { Observable } from 'rxjs';
3
- import { ADAPTER_NAME, PGliteOptions } from './pglite.interface';
3
+ import { ADAPTER_NAME, PGliteOptions } from './pglite.interface.js';
4
4
  export declare class RxDBAdapterPGlite extends RxDBAdapterLocalBase implements IRxDBAdapter {
5
5
  #private;
6
6
  private readonly options;
@@ -10,14 +10,18 @@ export declare class RxDBAdapterPGlite extends RxDBAdapterLocalBase implements I
10
10
  version$: Observable<string>;
11
11
  name: string;
12
12
  constructor(rxdb: RxDB, options: PGliteOptions);
13
- connect(): Observable<this>;
13
+ saveMany<T extends EntityType>(entities: InstanceType<T>[]): Promise<InstanceType<T>[]>;
14
+ connect(): Observable<IRxDBAdapter>;
14
15
  disconnect(): Promise<void>;
16
+ createBranch(branchId: string, fromChangeId?: number): Promise<void>;
17
+ switchBranch(branchId: string): Promise<void>;
18
+ restoreEntity<T extends EntityType>(entity: InstanceType<T>, options: RestoreEntityOptions): Promise<InstanceType<T>>;
15
19
  /**
16
20
  * 获取版本
17
21
  */
18
22
  version(): Promise<string>;
19
23
  getRepository<T extends EntityType, RT extends IRepository<T>>(EntityType: EntityType): RT;
20
- createTable(EntityType: EntityType): Promise<boolean>;
24
+ createTables<T extends EntityType>(entities: T[]): Promise<boolean>;
21
25
  isTableExisted(EntityType: EntityType): Promise<boolean>;
22
26
  /**
23
27
  * 判断表是否存在
@@ -31,3 +35,4 @@ declare module '@aiao/rxdb' {
31
35
  [ADAPTER_NAME]: RxDBAdapterPGlite;
32
36
  }
33
37
  }
38
+ //# sourceMappingURL=RxDBAdapterPGlite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RxDBAdapterPGlite.d.ts","sourceRoot":"","sources":["../src/RxDBAdapterPGlite.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,WAAW,EACX,YAAY,EACZ,oBAAoB,EACpB,IAAI,EACJ,oBAAoB,EACpB,cAAc,EAEf,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,UAAU,EAAqD,MAAM,MAAM,CAAC;AAErF,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAIpE,qBAAa,iBAAkB,SAAQ,oBAAqB,YAAW,YAAY;;IAkB/E,OAAO,CAAC,QAAQ,CAAC,OAAO;IAZ1B;;OAEG;IACH,QAAQ,qBAGN;IAEF,IAAI,EAAE,MAAM,CAAgB;gBAG1B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db';
2
- import { RxDBAdapterPGlite } from './RxDBAdapterPGlite';
2
+ import { RxDBAdapterPGlite } from './RxDBAdapterPGlite.js';
3
3
  declare const _default: (adapter: RxDBAdapterPGlite, metadata: EntityMetadata) => string;
4
4
  export default _default;
5
+ //# sourceMappingURL=generate_table_create_sql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate_table_create_sql.d.ts","sourceRoot":"","sources":["../src/generate_table_create_sql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAgB,MAAM,YAAY,CAAC;AAE1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;yBAqE3C,SAAS,iBAAiB,EAAE,UAAU,cAAc;AAApE,wBAKE"}
@@ -0,0 +1,3 @@
1
+ export { RxdbAdapterPGliteError } from './pglite.utils.js';
2
+ export * from './RxDBAdapterPGlite.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,cAAc,wBAAwB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,188 @@
1
+ import { PropertyType as i, RxDBAdapterLocalBase as _, getEntityMetadata as T } from "@aiao/rxdb";
2
+ import { Observable as y, shareReplay as w, switchMap as m, from as f, map as h, firstValueFrom as p } from "rxjs";
3
+ import { isFunction as b, isString as x } from "@aiao/utils";
4
+ import { PGlite as $ } from "@electric-sql/pglite";
5
+ class a extends Error {
6
+ constructor(e) {
7
+ super(e), this.name = "RxDBError", Object.setPrototypeOf(this, a.prototype);
8
+ }
9
+ }
10
+ const g = (s) => {
11
+ switch (s.type) {
12
+ case i.uuid:
13
+ return "uuid";
14
+ case i.string:
15
+ return "varchar";
16
+ case i.json:
17
+ return "jsonb";
18
+ case i.number:
19
+ return "numeric";
20
+ case i.integer:
21
+ return "integer";
22
+ case i.boolean:
23
+ return "boolean";
24
+ case i.date:
25
+ return "timestamptz";
26
+ }
27
+ throw new Error("rxDBColumnTypeToPGliteType: type '" + s.type + "' not support");
28
+ }, R = (s) => {
29
+ switch (s.type) {
30
+ case i.uuid:
31
+ return "uuid_ops";
32
+ case i.string:
33
+ return "bpchar_ops";
34
+ case i.json:
35
+ return "jsonb_ops";
36
+ case i.number:
37
+ return "numeric_ops";
38
+ case i.integer:
39
+ return "int4_ops";
40
+ default:
41
+ throw new a(`rxDBColumnTypeToPGliteTypeIndexName: type '${s.type}' not support`);
42
+ }
43
+ }, q = (s, e) => `idx_${s.namespace}_${s.name}_${e.name}`, M = (s, e) => {
44
+ let t = `CREATE TABLE ${e.namespace}."${e.name}" (`;
45
+ const n = [], c = [], l = [];
46
+ e.propertyMap.forEach((r) => {
47
+ let o = "";
48
+ o += `"${r.name}"`;
49
+ const E = g(r);
50
+ if (r.primary ? r.type === i.integer ? o += " serial PRIMARY KEY" : o += ` ${E} PRIMARY KEY` : o += ` ${E}`, !r.nullable) o += " NOT NULL";
51
+ else if (Reflect.get(r, "default") !== void 0) {
52
+ let u = r.default;
53
+ b(r.default) && (u = r.default()), x(u) ? ["CURRENT_TIMESTAMP", "now()"].includes(u) ? o += " DEFAULT now()" : o += ` DEFAULT '${u}'` : o += ` DEFAULT ${String(u)}`;
54
+ }
55
+ r.unique && n.push(
56
+ `CREATE UNIQUE INDEX "${q(e, r)}" on ${e.namespace}."${e.name}" ("${r.name}" ${R(r)});`
57
+ ), l.push(o);
58
+ });
59
+ const d = [...l, ...c];
60
+ if (d.length)
61
+ t += d.map((r) => `
62
+ ${r}`).join(","), t += `
63
+ );`;
64
+ else
65
+ throw new a("columns is empty!");
66
+ return n.length && (t += `
67
+ ` + n.join(`
68
+ `)), t;
69
+ }, v = (s, e) => "", A = (s, e) => {
70
+ let t = "";
71
+ return t += M(s, e), t += v(), t;
72
+ }, C = "pglite";
73
+ class D {
74
+ #e;
75
+ async init(e, t) {
76
+ return this.#e = new $({
77
+ dataDir: t.store === "memory" ? void 0 : `idb://${e}`,
78
+ database: e
79
+ }), this.#e.waitReady;
80
+ }
81
+ sql(e, ...t) {
82
+ return this.#e.sql(e, ...t);
83
+ }
84
+ exec(e, t) {
85
+ return this.#e.exec(e, t);
86
+ }
87
+ query(e, t, n) {
88
+ return this.#e.query(e, t, n);
89
+ }
90
+ describeQuery(e, t) {
91
+ return this.#e.describeQuery(e, t);
92
+ }
93
+ transaction(e) {
94
+ return this.#e.transaction(e);
95
+ }
96
+ runExclusive(e) {
97
+ return this.#e.runExclusive(e);
98
+ }
99
+ disconnect() {
100
+ throw new a("Method not implemented.");
101
+ }
102
+ async version() {
103
+ return (await this.#e.query("SELECT version()")).rows[0].version;
104
+ }
105
+ }
106
+ class B extends _ {
107
+ constructor(e, t) {
108
+ super(e), this.options = t;
109
+ }
110
+ #e = new y((e) => {
111
+ const t = new D();
112
+ t.init(this.rxdb.options.dbName, this.options).then(() => e.next(t));
113
+ }).pipe(w(1));
114
+ /**
115
+ * 数据库版本
116
+ */
117
+ version$ = this.#e.pipe(
118
+ m((e) => f(e.version())),
119
+ w(1)
120
+ );
121
+ name = C;
122
+ saveMany(e) {
123
+ throw new Error("Method not implemented.");
124
+ }
125
+ connect() {
126
+ return this.#e.pipe(h(() => this));
127
+ }
128
+ disconnect() {
129
+ throw new a("Method disconnect not implemented.");
130
+ }
131
+ createBranch(e, t) {
132
+ throw new Error("Method not implemented.");
133
+ }
134
+ switchBranch(e) {
135
+ throw new Error("Method not implemented.");
136
+ }
137
+ restoreEntity(e, t) {
138
+ throw new Error("Method not implemented.");
139
+ }
140
+ /**
141
+ * 获取版本
142
+ */
143
+ version() {
144
+ return p(this.version$);
145
+ }
146
+ getRepository(e) {
147
+ throw new a("Method getRepository not implemented.");
148
+ }
149
+ createTables(e) {
150
+ let t = "";
151
+ for (let n = 0; n < e.length; n++) {
152
+ const c = e[n], l = T(c);
153
+ t += `
154
+ ` + A(this, l), l.log;
155
+ }
156
+ return p(this.#n(t).pipe(h(() => !0)));
157
+ }
158
+ async isTableExisted(e) {
159
+ return p(this.isTableExisted$(e));
160
+ }
161
+ /**
162
+ * 判断表是否存在
163
+ * @param EntityType
164
+ */
165
+ isTableExisted$(e) {
166
+ const t = T(e);
167
+ return this.#t(
168
+ `SELECT EXISTS (
169
+ SELECT 1
170
+ FROM information_schema.tables
171
+ WHERE table_schema = '${t.namespace}'
172
+ AND table_name = '${t.name}');`
173
+ ).pipe(h((n) => n.rows[0]?.exists));
174
+ }
175
+ transaction(e) {
176
+ throw new a("Method transaction not implemented.");
177
+ }
178
+ #t(e, t, n) {
179
+ return this.#e.pipe(m((c) => c.query(e, t, n)));
180
+ }
181
+ #n(e, t) {
182
+ return this.#e.pipe(m((n) => n.exec(e, t)));
183
+ }
184
+ }
185
+ export {
186
+ B as RxDBAdapterPGlite,
187
+ a as RxdbAdapterPGliteError
188
+ };
@@ -3,3 +3,4 @@ export declare const ADAPTER_NAME: "pglite";
3
3
  export interface PGliteOptions extends IRxDBAdapterOptions {
4
4
  store?: 'memory' | 'idb';
5
5
  }
6
+ //# sourceMappingURL=pglite.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pglite.interface.d.ts","sourceRoot":"","sources":["../src/pglite.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,eAAO,MAAM,YAAY,EAAG,QAAiB,CAAC;AAE9C,MAAM,WAAW,aAAc,SAAQ,mBAAmB;IACxD,KAAK,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAC;CAC1B"}
@@ -1,5 +1,6 @@
1
- import { EntityMetadata, EntityPropertyMetadata, EntityRelationMetadata, RxDBError } from '@aiao/rxdb';
2
- export declare class RxdbAdapterPGliteError extends RxDBError {
1
+ import { EntityMetadata, EntityPropertyMetadata, EntityRelationMetadata } from '@aiao/rxdb';
2
+ export declare class RxdbAdapterPGliteError extends Error {
3
+ constructor(message: string);
3
4
  }
4
5
  export declare const getTableNameByMetadata: (metadata: EntityMetadata) => string;
5
6
  type PGliteDataType = 'uuid' | 'varchar' | 'jsonb' | 'numeric' | 'integer' | 'boolean' | 'timestamptz';
@@ -14,3 +15,4 @@ export declare const rxDBColumnTypeToPGliteType: (property: EntityPropertyMetada
14
15
  export declare const rxDBColumnTypeToPGliteTypeIndexName: (property: EntityPropertyMetadata) => string;
15
16
  export declare const getTableColumnIndexName: (metadata: EntityMetadata, property: EntityPropertyMetadata | EntityRelationMetadata) => string;
16
17
  export {};
18
+ //# sourceMappingURL=pglite.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pglite.utils.d.ts","sourceRoot":"","sources":["../src/pglite.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,sBAAsB,EAAgB,MAAM,YAAY,CAAC;AAE1G,qBAAa,sBAAuB,SAAQ,KAAK;gBACnC,OAAO,EAAE,MAAM;CAK5B;AAED,eAAO,MAAM,sBAAsB,GAAI,UAAU,cAAc,WAA6C,CAAC;AAG7G,KAAK,cAAc,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,aAAa,CAAC;AAEvG;;GAEG;AACH,eAAO,MAAM,0BAA0B,GAAI,UAAU,sBAAsB,KAAG,cAkB7E,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,mCAAmC,GAAI,UAAU,sBAAsB,KAAG,MAgBtF,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAClC,UAAU,cAAc,EACxB,UAAU,sBAAsB,GAAG,sBAAsB,WACO,CAAC"}
package/package.json CHANGED
@@ -1,16 +1,36 @@
1
1
  {
2
2
  "name": "@aiao/rxdb-adapter-pglite",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "type": "module",
5
- "main": "./index.js",
6
- "types": "./index.d.ts",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ "./package.json": "./package.json",
10
+ ".": {
11
+ "@aiao/source": "./src/index.ts",
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js",
14
+ "default": "./dist/index.js"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "!**/*.tsbuildinfo"
20
+ ],
21
+ "nx": {
22
+ "name": "rxdb-adapter-pglite",
23
+ "tags": [
24
+ "js-lib"
25
+ ]
26
+ },
7
27
  "dependencies": {
8
- "@electric-sql/pglite": "^0.3.6",
9
- "@aiao/rxdb": "0.0.3",
10
- "rxjs": "~7.8.2",
11
- "@aiao/utils": "0.0.3"
28
+ "rxjs": "^7.8.2",
29
+ "@electric-sql/pglite": "^0.3.9",
30
+ "@aiao/rxdb": "0.0.4",
31
+ "@aiao/utils": "0.0.4"
12
32
  },
13
- "publishConfig": {
14
- "access": "public"
33
+ "devDependencies": {
34
+ "@aiao/rxdb-test": "0.0.4"
15
35
  }
16
36
  }
package/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export { RxdbAdapterPGliteError } from './pglite.utils';
2
- export * from './RxDBAdapterPGlite';
package/index.js DELETED
@@ -1,170 +0,0 @@
1
- import { RxDBError as b, PropertyType as r, TransactionBeginEvent as f, TransactionCommitEvent as w, TransactionRollbackEvent as x, RxDBAdapterLocalBase as $, getEntityMetadata as T } from "@aiao/rxdb";
2
- import { Observable as g, shareReplay as _, switchMap as u, from as y, map as m, firstValueFrom as p } from "rxjs";
3
- import { isFunction as R, isString as q } from "@aiao/utils";
4
- import { PGlite as v } from "@electric-sql/pglite";
5
- class a extends b {
6
- }
7
- const A = (s) => {
8
- switch (s.type) {
9
- case r.uuid:
10
- return "uuid";
11
- case r.string:
12
- return "varchar";
13
- case r.json:
14
- return "jsonb";
15
- case r.number:
16
- return "numeric";
17
- case r.integer:
18
- return "integer";
19
- case r.boolean:
20
- return "boolean";
21
- case r.date:
22
- return "timestamptz";
23
- }
24
- }, L = (s) => {
25
- switch (s.type) {
26
- case r.uuid:
27
- return "uuid_ops";
28
- case r.string:
29
- return "bpchar_ops";
30
- case r.json:
31
- return "jsonb_ops";
32
- case r.number:
33
- return "numeric_ops";
34
- case r.integer:
35
- return "int4_ops";
36
- default:
37
- throw new a(`rxDBColumnTypeToPGliteTypeIndexName: type '${s.type}' not support`);
38
- }
39
- }, C = (s, e) => `idx_${s.namespace}_${s.name}_${e.name}`, D = (s, e) => {
40
- let t = `CREATE TABLE ${e.namespace}."${e.name}" (`;
41
- const i = [], l = [], h = [];
42
- e.propertyMap.forEach((n) => {
43
- let o = "";
44
- o += `"${n.name}"`;
45
- const E = A(n);
46
- if (n.primary ? n.type === r.integer ? o += " serial PRIMARY KEY" : o += ` ${E} PRIMARY KEY` : o += ` ${E}`, !n.nullable) o += " NOT NULL";
47
- else if (Reflect.get(n, "default") !== void 0) {
48
- let c = n.default;
49
- R(n.default) && (c = n.default()), q(c) ? ["CURRENT_TIMESTAMP", "now()"].includes(c) ? o += " DEFAULT now()" : o += ` DEFAULT '${c}'` : o += ` DEFAULT ${String(c)}`;
50
- }
51
- n.unique && i.push(
52
- `CREATE UNIQUE INDEX "${C(e, n)}" on ${e.namespace}."${e.name}" ("${n.name}" ${L(n)});`
53
- ), h.push(o);
54
- });
55
- const d = [...h, ...l];
56
- if (d.length)
57
- t += d.map((n) => `
58
- ${n}`).join(","), t += `
59
- );`;
60
- else
61
- throw new a("columns is empty!");
62
- return i.length && (t += `
63
- ` + i.join(`
64
- `)), t;
65
- }, M = (s, e) => "", P = (s, e) => {
66
- let t = "";
67
- return t += D(s, e), t += M(), t;
68
- }, S = "pglite";
69
- class N {
70
- #e;
71
- async init(e, t) {
72
- return this.#e = new v({
73
- dataDir: t.store === "memory" ? void 0 : `idb://${e}`,
74
- database: e
75
- }), this.#e.waitReady;
76
- }
77
- sql(e, ...t) {
78
- return this.#e.sql(e, ...t);
79
- }
80
- exec(e, t) {
81
- return this.#e.exec(e, t);
82
- }
83
- query(e, t, i) {
84
- return this.#e.query(e, t, i);
85
- }
86
- describeQuery(e, t) {
87
- return this.#e.describeQuery(e, t);
88
- }
89
- transaction(e) {
90
- return this.#e.transaction(e);
91
- }
92
- runExclusive(e) {
93
- return this.#e.runExclusive(e);
94
- }
95
- disconnect() {
96
- throw new a("Method not implemented.");
97
- }
98
- async version() {
99
- return (await this.#e.query("SELECT version()")).rows[0].version;
100
- }
101
- }
102
- class U extends $ {
103
- constructor(e, t) {
104
- super(e), this.options = t;
105
- }
106
- #e = new g((e) => {
107
- const t = new N();
108
- t.init(this.rxdb.options.dbName, this.options).then(() => e.next(t));
109
- }).pipe(_(1));
110
- /**
111
- * 数据库版本
112
- */
113
- version$ = this.#e.pipe(
114
- u((e) => y(e.version())),
115
- _(1)
116
- );
117
- name = S;
118
- connect() {
119
- return this.#e.pipe(m(() => this));
120
- }
121
- disconnect() {
122
- throw new a("Method disconnect not implemented.");
123
- }
124
- /**
125
- * 获取版本
126
- */
127
- version() {
128
- return p(this.version$);
129
- }
130
- getRepository(e) {
131
- throw new a("Method getRepository not implemented.");
132
- }
133
- createTable(e) {
134
- const t = T(e), i = P(this, t);
135
- return t.log, p(this.#n(i).pipe(m(() => !0)));
136
- }
137
- async isTableExisted(e) {
138
- return p(this.isTableExisted$(e));
139
- }
140
- /**
141
- * 判断表是否存在
142
- * @param EntityType
143
- */
144
- isTableExisted$(e) {
145
- const t = T(e);
146
- return this.#t(
147
- `SELECT EXISTS (
148
- SELECT 1
149
- FROM information_schema.tables
150
- WHERE table_schema = '${t.namespace}'
151
- AND table_name = '${t.name}');`
152
- ).pipe(m((i) => i.rows[0]?.exists));
153
- }
154
- transaction(e) {
155
- throw new a("Method transaction not implemented.");
156
- }
157
- #t(e, t, i) {
158
- return this.#e.pipe(u((l) => l.query(e, t, i)));
159
- }
160
- #n(e, t) {
161
- return this.#e.pipe(u((i) => i.exec(e, t)));
162
- }
163
- }
164
- new f();
165
- new w();
166
- new x();
167
- export {
168
- U as RxDBAdapterPGlite,
169
- a as RxdbAdapterPGliteError
170
- };