xdriver 2.0.16 → 2.0.18
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/lib/connection.d.ts +1 -0
- package/lib/connection.js +17 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +11 -3
- package/lib/mapper.d.ts +1 -1
- package/lib/table.d.ts +1 -1
- package/package.json +1 -1
- package/src/connection.ts +15 -0
- package/src/index.ts +12 -3
- package/src/mapper.ts +1 -1
- package/src/table.ts +1 -1
package/lib/connection.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export default class Connection {
|
|
|
18
18
|
constructor(database?: string, version?: number);
|
|
19
19
|
on<T extends EventKey>(event: T, handle: EventMap[T]): this;
|
|
20
20
|
get connected(): boolean;
|
|
21
|
+
get tables(): string[];
|
|
21
22
|
connect(name?: string, version?: number, upgrade?: (idbDatabase: IDBDatabase, event: IDBVersionChangeEvent) => any): Promise<any>;
|
|
22
23
|
drop(): Promise<Event>;
|
|
23
24
|
close(): void;
|
package/lib/connection.js
CHANGED
|
@@ -25,6 +25,23 @@ export default class Connection {
|
|
|
25
25
|
get connected() {
|
|
26
26
|
return this.idbDatabase != void 0;
|
|
27
27
|
}
|
|
28
|
+
get tables() {
|
|
29
|
+
var _a;
|
|
30
|
+
if (!this.connected) {
|
|
31
|
+
throw new Error('Please connect to the database first');
|
|
32
|
+
}
|
|
33
|
+
let tables = [];
|
|
34
|
+
let objectStoreNames = (_a = this.idbDatabase) === null || _a === void 0 ? void 0 : _a.objectStoreNames;
|
|
35
|
+
if (!objectStoreNames)
|
|
36
|
+
return tables;
|
|
37
|
+
for (let i = 0; i < objectStoreNames.length; i++) {
|
|
38
|
+
let item = objectStoreNames.item(i);
|
|
39
|
+
if (!item)
|
|
40
|
+
continue;
|
|
41
|
+
tables.push(item);
|
|
42
|
+
}
|
|
43
|
+
return tables;
|
|
44
|
+
}
|
|
28
45
|
connect(name, version, upgrade) {
|
|
29
46
|
return __awaiter(this, void 0, void 0, function* () {
|
|
30
47
|
var _a;
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -21,8 +21,16 @@ export default class Driver {
|
|
|
21
21
|
this.version = version;
|
|
22
22
|
}
|
|
23
23
|
defineTables(...tables) {
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
for (let table of tables) {
|
|
25
|
+
let index = this.tables.findIndex(t => t.name === table.name);
|
|
26
|
+
if (index >= 0) {
|
|
27
|
+
this.tables[index] = table;
|
|
28
|
+
logger.debug(`Update table: ${table.name}`);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
this.tables.push(table);
|
|
32
|
+
logger.debug(`Define table: ${table.name}`);
|
|
33
|
+
}
|
|
26
34
|
return this;
|
|
27
35
|
}
|
|
28
36
|
hasChange(database) {
|
|
@@ -133,7 +141,7 @@ export default class Driver {
|
|
|
133
141
|
database.close();
|
|
134
142
|
yield database.connect(this.name, ++this.version);
|
|
135
143
|
}
|
|
136
|
-
return database;
|
|
144
|
+
return this.database = database;
|
|
137
145
|
});
|
|
138
146
|
}
|
|
139
147
|
}
|
package/lib/mapper.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export default class Mapper<T extends Row> {
|
|
|
13
13
|
delete(key: IDBValidKey | IDBKeyRange): Promise<void>;
|
|
14
14
|
queryByIndex(indexName: string, key?: IDBValidKey | IDBKeyRange, count?: number): Promise<RowPacket<T>>;
|
|
15
15
|
queryByKey(key: IDBValidKey | IDBKeyRange): Promise<RowPacket<T>>;
|
|
16
|
-
queryByKeys(keys: IDBValidKey[]): Promise<RowPacket<T>>;
|
|
16
|
+
queryByKeys(keys: (IDBValidKey | IDBKeyRange)[]): Promise<RowPacket<T>>;
|
|
17
17
|
scan(key?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection, indexName?: string): Promise<RowPacket<T>>;
|
|
18
18
|
select(key?: IDBValidKey | IDBKeyRange, count?: number, indexName?: string): Promise<RowPacket<T>>;
|
|
19
19
|
paginate(pageNo?: number, pageSize?: number, key?: IDBValidKey | IDBKeyRange, indexName?: string): Promise<RowPacket<T>>;
|
package/lib/table.d.ts
CHANGED
|
@@ -76,7 +76,7 @@ export default class Table implements ITable {
|
|
|
76
76
|
keys(key?: IDBValidKey | IDBKeyRange | null, count?: number): Promise<IDBValidKey[]>;
|
|
77
77
|
count(key?: IDBValidKey | IDBKeyRange): Promise<number>;
|
|
78
78
|
query<R extends Row>(key?: IDBValidKey | IDBKeyRange, count?: number): Promise<RowPacket<R>>;
|
|
79
|
-
queryByKeys<R extends Row>(keys: IDBValidKey[]): Promise<RowPacket<R>>;
|
|
79
|
+
queryByKeys<R extends Row>(keys: (IDBValidKey | IDBKeyRange)[]): Promise<RowPacket<R>>;
|
|
80
80
|
queryByIndex<R extends Row>(indexName: string, key?: IDBValidKey | IDBKeyRange, count?: number): Promise<RowPacket<R>>;
|
|
81
81
|
select<R extends Row>(key?: IDBValidKey | IDBKeyRange, count?: number, indexName?: string): Promise<RowPacket<R>>;
|
|
82
82
|
queryByKey<R extends Row>(key: IDBValidKey | IDBKeyRange): Promise<RowPacket<R>>;
|
package/package.json
CHANGED
package/src/connection.ts
CHANGED
|
@@ -37,6 +37,21 @@ export default class Connection {
|
|
|
37
37
|
return this.idbDatabase != void 0;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
get tables(): string[] {
|
|
41
|
+
if (!this.connected) {
|
|
42
|
+
throw new Error('Please connect to the database first')
|
|
43
|
+
}
|
|
44
|
+
let tables: Array<string> = [];
|
|
45
|
+
let objectStoreNames = this.idbDatabase?.objectStoreNames
|
|
46
|
+
if (!objectStoreNames) return tables;
|
|
47
|
+
for (let i = 0; i < objectStoreNames.length; i++) {
|
|
48
|
+
let item = objectStoreNames.item(i);
|
|
49
|
+
if (!item) continue;
|
|
50
|
+
tables.push(item);
|
|
51
|
+
}
|
|
52
|
+
return tables;
|
|
53
|
+
}
|
|
54
|
+
|
|
40
55
|
async connect(name?: string, version?: number, upgrade?: (idbDatabase: IDBDatabase, event: IDBVersionChangeEvent) => any): Promise<any> {
|
|
41
56
|
if ((!name || version == void 0) && this.connected) {
|
|
42
57
|
return Promise.resolve(this);
|
package/src/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ const logger = Logger.getLogger("Driver")
|
|
|
10
10
|
export default class Driver {
|
|
11
11
|
private readonly name: string;
|
|
12
12
|
private version: number;
|
|
13
|
+
private database?: Database;
|
|
13
14
|
private readonly tables: Array<TableMeta> = [];
|
|
14
15
|
|
|
15
16
|
constructor(name: string, version: number = 0) {
|
|
@@ -18,8 +19,16 @@ export default class Driver {
|
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
defineTables(...tables: Array<TableMeta>): this {
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
for(let table of tables) {
|
|
23
|
+
let index = this.tables.findIndex(t => t.name === table.name);
|
|
24
|
+
if (index >= 0) {
|
|
25
|
+
this.tables[index] = table;
|
|
26
|
+
logger.debug(`Update table: ${table.name}`);
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
this.tables.push(table);
|
|
30
|
+
logger.debug(`Define table: ${table.name}`);
|
|
31
|
+
}
|
|
23
32
|
return this;
|
|
24
33
|
}
|
|
25
34
|
|
|
@@ -140,7 +149,7 @@ export default class Driver {
|
|
|
140
149
|
await database.connect(this.name, ++this.version)
|
|
141
150
|
}
|
|
142
151
|
|
|
143
|
-
return database;
|
|
152
|
+
return this.database = database;
|
|
144
153
|
}
|
|
145
154
|
}
|
|
146
155
|
|
package/src/mapper.ts
CHANGED
|
@@ -51,7 +51,7 @@ export default class Mapper<T extends Row> {
|
|
|
51
51
|
return this._table.queryByKey(key);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
async queryByKeys(keys: IDBValidKey[]): Promise<RowPacket<T>> {
|
|
54
|
+
async queryByKeys(keys: (IDBValidKey | IDBKeyRange)[]): Promise<RowPacket<T>> {
|
|
55
55
|
return this._table.queryByKeys(keys);
|
|
56
56
|
}
|
|
57
57
|
|
package/src/table.ts
CHANGED
|
@@ -455,7 +455,7 @@ export default class Table implements ITable{
|
|
|
455
455
|
return new RowPacket<R>(rows);
|
|
456
456
|
}
|
|
457
457
|
|
|
458
|
-
async queryByKeys<R extends Row>(keys: IDBValidKey[]): Promise<RowPacket<R>> {
|
|
458
|
+
async queryByKeys<R extends Row>(keys: (IDBValidKey | IDBKeyRange)[]): Promise<RowPacket<R>> {
|
|
459
459
|
if (!keys.length) {
|
|
460
460
|
return Promise.reject('keys is required');
|
|
461
461
|
}
|