@aiao/rxdb-adapter-sqlite 0.0.1
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/README.md +1 -0
- package/RxDBAdapterSqlite.d.ts +66 -0
- package/SqliteClient.d.ts +19 -0
- package/SqliteRepository.d.ts +23 -0
- package/SqliteRepositoryBase.d.ts +85 -0
- package/SqliteTreeRepository.d.ts +17 -0
- package/execute_statement_helper.d.ts +7 -0
- package/generate_entity_delete_sql.d.ts +9 -0
- package/generate_entity_find_tree_sql.d.ts +41 -0
- package/generate_entity_insert_sql.d.ts +9 -0
- package/generate_entity_soft_delete_sql.d.ts +9 -0
- package/generate_entity_update_sql.d.ts +9 -0
- package/generate_query_find_sql.d.ts +30 -0
- package/generate_table_create_sql.d.ts +8 -0
- package/generate_table_trigger_sql.d.ts +8 -0
- package/index.d.ts +5 -0
- package/index.js +1136 -0
- package/package.json +20 -0
- package/sqlite-load.utils.d.ts +39 -0
- package/sqlite.interface.d.ts +57 -0
- package/sqlite.utils.d.ts +107 -0
- package/types.d.ts +7 -0
- package/wa-sqlite.d.ts +611 -0
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aiao/rxdb-adapter-sqlite",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./index.js",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@aiao/rxdb": "*",
|
|
8
|
+
"@aiao/utils": "0.0.1",
|
|
9
|
+
"rxjs": "~7.8.0",
|
|
10
|
+
"@journeyapps/wa-sqlite": "^1.2.4",
|
|
11
|
+
"comlink": "^4.4.2"
|
|
12
|
+
},
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./index.js",
|
|
15
|
+
"types": "./index.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { LoadModuleOptions } from './sqlite.interface';
|
|
2
|
+
import { SQLiteAPI } from './wa-sqlite';
|
|
3
|
+
interface VFSConfig {
|
|
4
|
+
/**
|
|
5
|
+
* vfs 的名称
|
|
6
|
+
*/
|
|
7
|
+
name: string;
|
|
8
|
+
vfsModule: () => Promise<any>;
|
|
9
|
+
vfsOptions?: any;
|
|
10
|
+
/**
|
|
11
|
+
* 是否支持同步
|
|
12
|
+
*/
|
|
13
|
+
sync: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* 支持异步
|
|
16
|
+
*/
|
|
17
|
+
async: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* 支持在 js 环境下运行
|
|
20
|
+
*/
|
|
21
|
+
jsContext: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* 支持使用 web worker
|
|
24
|
+
*/
|
|
25
|
+
worker: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* 支持使用 shared worker
|
|
28
|
+
*/
|
|
29
|
+
sharedWorker: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* 支持多个连接
|
|
32
|
+
*/
|
|
33
|
+
multipleConnections?: boolean;
|
|
34
|
+
}
|
|
35
|
+
export declare const WA_SQLITE_VFS_LIST: VFSConfig[];
|
|
36
|
+
export declare const checkVFSConfig: (options: LoadModuleOptions) => VFSConfig;
|
|
37
|
+
export declare const sqliteLoad: (options: LoadModuleOptions) => Promise<SQLiteAPI>;
|
|
38
|
+
export declare const getSqliteEventName: (dbName: string, eventName: string) => string;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { IRxDBAdapterOptions, UnixMilliseconds } from '@aiao/rxdb';
|
|
2
|
+
import { SQLiteCompatibleType } from './wa-sqlite';
|
|
3
|
+
export type SupportVFS = 'MemoryVFS' | 'MemoryAsyncVFS' | 'IDBBatchAtomicVFS' | 'OPFSAdaptiveVFS' | 'AccessHandlePoolVFS' | 'OPFSAnyContextVFS' | 'OPFSCoopSyncVFS' | 'OPFSPermutedVFS';
|
|
4
|
+
export interface SqliteData {
|
|
5
|
+
columns: string[];
|
|
6
|
+
rows: SQLiteCompatibleType[][];
|
|
7
|
+
}
|
|
8
|
+
export interface SqliteSuccessResult {
|
|
9
|
+
sql: string;
|
|
10
|
+
rowsAffected: number;
|
|
11
|
+
runStart: number;
|
|
12
|
+
runEnd: number;
|
|
13
|
+
results: SqliteData[];
|
|
14
|
+
}
|
|
15
|
+
export type SqliteResult = SqliteSuccessResult;
|
|
16
|
+
export interface SqliteOptions extends IRxDBAdapterOptions {
|
|
17
|
+
/**
|
|
18
|
+
* vfs
|
|
19
|
+
*/
|
|
20
|
+
vfs: SupportVFS;
|
|
21
|
+
/**
|
|
22
|
+
* 异步方式
|
|
23
|
+
*/
|
|
24
|
+
async: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* 是否启用 worker
|
|
27
|
+
*/
|
|
28
|
+
worker: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* worker
|
|
31
|
+
*/
|
|
32
|
+
workerInstance?: Worker;
|
|
33
|
+
/**
|
|
34
|
+
* wasm 路径
|
|
35
|
+
*/
|
|
36
|
+
wasmPath?: string;
|
|
37
|
+
/**
|
|
38
|
+
* @see https://www.sqlite.org/pragma.html#pragma_cache_size
|
|
39
|
+
* @default 51200
|
|
40
|
+
*/
|
|
41
|
+
cacheSizeKb?: number;
|
|
42
|
+
}
|
|
43
|
+
export type LoadModuleOptions = Pick<SqliteOptions, 'vfs' | 'async' | 'wasmPath' | 'worker' | 'cacheSizeKb'>;
|
|
44
|
+
export declare enum SQliteChangeType {
|
|
45
|
+
SQLITE_DELETE = 9,
|
|
46
|
+
SQLITE_INSERT = 18,
|
|
47
|
+
SQLITE_UPDATE = 23
|
|
48
|
+
}
|
|
49
|
+
export interface SqliteChangeEvent {
|
|
50
|
+
type: SQliteChangeType;
|
|
51
|
+
dbName: string | null;
|
|
52
|
+
tableName: string | null;
|
|
53
|
+
rowid: bigint;
|
|
54
|
+
recordAt: UnixMilliseconds;
|
|
55
|
+
timeStamp: DOMHighResTimeStamp;
|
|
56
|
+
}
|
|
57
|
+
export declare const ADAPTER_NAME: "sqlite";
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { EntityMetadata, EntityPropertyMetadata, EntityRelationMetadata, RuleGroup, RxDBError, RxDBScalar } from '@aiao/rxdb';
|
|
2
|
+
import { SqliteResult } from './sqlite.interface';
|
|
3
|
+
import { SQLiteCompatibleType } from './wa-sqlite';
|
|
4
|
+
/**
|
|
5
|
+
* 检查 sqlite 表是否存在
|
|
6
|
+
* @param tableName
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare const isTableExistedSql: (tableName: string) => string;
|
|
10
|
+
/**
|
|
11
|
+
* 检查 sqlite 结果是否为空
|
|
12
|
+
* @param result
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
export declare const isSqlResultEmpty: (result: SqliteResult) => boolean;
|
|
16
|
+
/**
|
|
17
|
+
* sqlite 行 id 列名
|
|
18
|
+
*/
|
|
19
|
+
export declare const ROWID: "_rowid";
|
|
20
|
+
/**
|
|
21
|
+
* 类型
|
|
22
|
+
* https://www.sqlite.org/datatype3.html
|
|
23
|
+
*/
|
|
24
|
+
type SqliteDataType = 'NULL' | 'INTEGER' | 'REAL' | 'TEXT' | 'BLOB';
|
|
25
|
+
/**
|
|
26
|
+
* rxdb 的类型 转 sqlite 类型
|
|
27
|
+
*/
|
|
28
|
+
export declare const rxDBColumnTypeToSqliteType: (property: EntityPropertyMetadata) => SqliteDataType;
|
|
29
|
+
/**
|
|
30
|
+
* 转换 js 类型为 sqlite 类型
|
|
31
|
+
* @param value
|
|
32
|
+
* @param property
|
|
33
|
+
* @returns
|
|
34
|
+
*/
|
|
35
|
+
export declare const transformValueJsToSqlite: (value: RxDBScalar, property: EntityPropertyMetadata) => RxDBScalar | null | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* 转换 sqlite 类型为 js 类型
|
|
38
|
+
* @param value sqlite 类型的值
|
|
39
|
+
* @param property 实体属性
|
|
40
|
+
* @returns js 类型的值
|
|
41
|
+
*/
|
|
42
|
+
export declare const transformValueSqliteToJs: (value: RxDBScalar | any, property: EntityPropertyMetadata) => any;
|
|
43
|
+
/**
|
|
44
|
+
* 获取表名
|
|
45
|
+
* @param name 表名
|
|
46
|
+
* @param namespace 命名空间
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
49
|
+
export declare const getTableName: (name: string, namespace: string) => string;
|
|
50
|
+
/**
|
|
51
|
+
* 通过 metadata 获取表名
|
|
52
|
+
* @param metadata
|
|
53
|
+
* @returns
|
|
54
|
+
*/
|
|
55
|
+
export declare const getTableNameByMetadata: (metadata: EntityMetadata) => string;
|
|
56
|
+
/**
|
|
57
|
+
* 获取表列索引名称
|
|
58
|
+
* @param metadata
|
|
59
|
+
* @param property
|
|
60
|
+
* @returns
|
|
61
|
+
*/
|
|
62
|
+
export declare const getTableColumnIndexName: (metadata: EntityMetadata, property: EntityPropertyMetadata | EntityRelationMetadata) => string;
|
|
63
|
+
export declare class RxdbAdapterSqliteError extends RxDBError {
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* 格式化实体数据,转换为 sqlite 类型
|
|
67
|
+
* @param metadata
|
|
68
|
+
* @param entity
|
|
69
|
+
* @returns
|
|
70
|
+
*/
|
|
71
|
+
export declare const transformEntityValueToSql: (metadata: EntityMetadata, entity: any) => any;
|
|
72
|
+
/**
|
|
73
|
+
* 格式化创建时的实体数据
|
|
74
|
+
* @param metadata
|
|
75
|
+
* @param entity
|
|
76
|
+
* @returns
|
|
77
|
+
*/
|
|
78
|
+
export declare const normalizeCreateEntity: (metadata: EntityMetadata, entity: any) => any;
|
|
79
|
+
/**
|
|
80
|
+
* 格式化实体数据,过滤掉 readonly 字段
|
|
81
|
+
* @param metadata
|
|
82
|
+
* @param entity
|
|
83
|
+
* @returns
|
|
84
|
+
*/
|
|
85
|
+
export declare const normalizeEntity: (metadata: EntityMetadata, entity: any) => any;
|
|
86
|
+
/**
|
|
87
|
+
* 查询去除软删除数据
|
|
88
|
+
* @param where
|
|
89
|
+
* @returns
|
|
90
|
+
*/
|
|
91
|
+
export declare const withoutSoftDelete: <RG extends RuleGroup<any, any, any>>(where: RG) => RG;
|
|
92
|
+
/**
|
|
93
|
+
* 展示 sql 合并后的结果
|
|
94
|
+
* @param sql
|
|
95
|
+
* @param params
|
|
96
|
+
* @returns
|
|
97
|
+
*/
|
|
98
|
+
export declare const showSQL: (sql: string, params: any[]) => string;
|
|
99
|
+
/**
|
|
100
|
+
* 获取实体对象数据
|
|
101
|
+
* @param metadata
|
|
102
|
+
* @param columns
|
|
103
|
+
* @param row
|
|
104
|
+
* @returns
|
|
105
|
+
*/
|
|
106
|
+
export declare const getEntityObjectFromResult: (metadata: EntityMetadata, columns: string[], row: SQLiteCompatibleType[]) => any;
|
|
107
|
+
export {};
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
declare module '@journeyapps/wa-sqlite/src/examples/OPFSCoopSyncVFS.js' { }
|
|
2
|
+
declare module '@journeyapps/wa-sqlite/src/examples/AccessHandlePoolVFS.js' { }
|
|
3
|
+
declare module '@journeyapps/wa-sqlite/src/examples/OPFSAnyContextVFS.js' { }
|
|
4
|
+
declare module '@journeyapps/wa-sqlite/src/examples/IDBBatchAtomicVFS.js' { }
|
|
5
|
+
declare module '@journeyapps/wa-sqlite/src/examples/IDBMirrorVFS.js' { }
|
|
6
|
+
declare module '@journeyapps/wa-sqlite/src/examples/OPFSAdaptiveVFS.js' { }
|
|
7
|
+
declare module '@journeyapps/wa-sqlite/src/examples/OPFSPermutedVFS.js' { }
|