xdriver 2.0.13 → 2.0.15
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/database.d.ts +1 -1
- package/lib/mapper.d.ts +5 -2
- package/lib/mapper.js +35 -15
- package/lib/table.d.ts +3 -1
- package/lib/table.js +25 -2
- package/package.json +1 -1
- package/src/mapper.ts +29 -17
- package/src/table.ts +23 -3
package/lib/database.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export default class Database extends Connection {
|
|
|
10
10
|
count(table: string, key: IDBValidKey | IDBKeyRange): Promise<number>;
|
|
11
11
|
insert(table: string, data: Array<Record<string, any>>): Promise<IDBValidKey[]>;
|
|
12
12
|
update(table: string, modify: Row, key?: IDBValidKey | IDBKeyRange | null): Promise<IDBValidKey>;
|
|
13
|
-
delete(table: string, key: IDBValidKey | IDBKeyRange): Promise<
|
|
13
|
+
delete(table: string, key: IDBValidKey | IDBKeyRange): Promise<void>;
|
|
14
14
|
truncate(table: string): Promise<void>;
|
|
15
15
|
getPagination<R extends Row>(table: string, pageSize?: number): Promise<Pagination<R>>;
|
|
16
16
|
scan<R extends Row>(table: string, key?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection, indexName?: string): Promise<RowPacket<R>>;
|
package/lib/mapper.d.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import Table, { Pagination, Row, RowPacket } from "./table";
|
|
2
2
|
export default class Mapper<T extends Row> {
|
|
3
|
-
private
|
|
3
|
+
private _table;
|
|
4
4
|
constructor(table: Table);
|
|
5
|
+
get table(): Table;
|
|
5
6
|
truncate(): Promise<void>;
|
|
6
7
|
count(key?: IDBValidKey | IDBKeyRange): Promise<number>;
|
|
7
8
|
insert(data: T | Array<T>): Promise<IDBValidKey[]>;
|
|
8
9
|
update(modify: Row, key?: IDBValidKey | IDBKeyRange | null): Promise<IDBValidKey>;
|
|
9
10
|
query(key?: IDBValidKey | IDBKeyRange, count?: number): Promise<RowPacket<T>>;
|
|
10
11
|
queryById(id: any | Array<any>, indexName?: string): Promise<T | Array<T>>;
|
|
11
|
-
|
|
12
|
+
deleteByKeys(...keys: IDBValidKey[]): Promise<void>;
|
|
13
|
+
delete(key: IDBValidKey | IDBKeyRange): Promise<void>;
|
|
12
14
|
queryByIndex(indexName: string, key?: IDBValidKey | IDBKeyRange, count?: number): Promise<RowPacket<T>>;
|
|
13
15
|
queryByKey(key: IDBValidKey | IDBKeyRange): Promise<RowPacket<T>>;
|
|
16
|
+
queryByKeys<R extends Row>(keys: IDBValidKey[]): Promise<RowPacket<R>>;
|
|
14
17
|
scan(key?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection, indexName?: string): Promise<RowPacket<T>>;
|
|
15
18
|
select(key?: IDBValidKey | IDBKeyRange, count?: number, indexName?: string): Promise<RowPacket<T>>;
|
|
16
19
|
paginate<R extends Row>(pageNo?: number, pageSize?: number, key?: IDBValidKey | IDBKeyRange, indexName?: string): Promise<RowPacket<R>>;
|
package/lib/mapper.js
CHANGED
|
@@ -1,47 +1,67 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
export default class Mapper {
|
|
2
11
|
constructor(table) {
|
|
3
|
-
this.
|
|
12
|
+
this._table = table;
|
|
13
|
+
}
|
|
14
|
+
get table() {
|
|
15
|
+
return this._table;
|
|
4
16
|
}
|
|
5
17
|
truncate() {
|
|
6
|
-
return this.
|
|
18
|
+
return this._table.truncate();
|
|
7
19
|
}
|
|
8
20
|
count(key) {
|
|
9
|
-
return this.
|
|
21
|
+
return this._table.count(key);
|
|
10
22
|
}
|
|
11
23
|
insert(data) {
|
|
12
|
-
return this.
|
|
24
|
+
return this._table.insert(data);
|
|
13
25
|
}
|
|
14
26
|
update(modify, key) {
|
|
15
|
-
return this.
|
|
27
|
+
return this._table.update(modify, key);
|
|
16
28
|
}
|
|
17
29
|
query(key, count) {
|
|
18
|
-
return this.
|
|
30
|
+
return this._table.query(key, count);
|
|
19
31
|
}
|
|
20
32
|
queryById(id, indexName) {
|
|
21
|
-
return this.
|
|
33
|
+
return this._table.queryById(id, indexName);
|
|
34
|
+
}
|
|
35
|
+
deleteByKeys(...keys) {
|
|
36
|
+
return this._table.deleteByKeys(...keys);
|
|
22
37
|
}
|
|
23
38
|
delete(key) {
|
|
24
|
-
return this.
|
|
39
|
+
return this._table.delete(key);
|
|
25
40
|
}
|
|
26
41
|
queryByIndex(indexName, key, count) {
|
|
27
|
-
return this.
|
|
42
|
+
return this._table.queryByIndex(indexName, key, count);
|
|
28
43
|
}
|
|
29
44
|
queryByKey(key) {
|
|
30
|
-
return this.
|
|
45
|
+
return this._table.queryByKey(key);
|
|
46
|
+
}
|
|
47
|
+
queryByKeys(keys) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
return this._table.queryByKeys(keys);
|
|
50
|
+
});
|
|
31
51
|
}
|
|
32
52
|
scan(key, direction = 'next', indexName) {
|
|
33
|
-
return this.
|
|
53
|
+
return this._table.scan(key, direction, indexName);
|
|
34
54
|
}
|
|
35
55
|
select(key, count, indexName) {
|
|
36
|
-
return this.
|
|
56
|
+
return this._table.select(key, count, indexName);
|
|
37
57
|
}
|
|
38
58
|
paginate(pageNo = 1, pageSize = 10, key, indexName) {
|
|
39
|
-
return this.
|
|
59
|
+
return this._table.paginate(pageNo, pageSize, key, indexName);
|
|
40
60
|
}
|
|
41
61
|
getPagination(pageSize = 10) {
|
|
42
|
-
return this.
|
|
62
|
+
return this._table.getPagination(pageSize);
|
|
43
63
|
}
|
|
44
64
|
getAll() {
|
|
45
|
-
return this.
|
|
65
|
+
return this._table.getAllData();
|
|
46
66
|
}
|
|
47
67
|
}
|
package/lib/table.d.ts
CHANGED
|
@@ -69,12 +69,14 @@ export default class Table implements ITable {
|
|
|
69
69
|
get meta(): TableMeta;
|
|
70
70
|
insert(data: Row | Rows): Promise<Array<IDBValidKey>>;
|
|
71
71
|
update(modify: Row, key?: IDBValidKey | IDBKeyRange | null): Promise<IDBValidKey>;
|
|
72
|
-
|
|
72
|
+
deleteByKeys<R extends Row>(...keys: IDBValidKey[]): Promise<void>;
|
|
73
|
+
delete<R extends Row>(key: IDBValidKey | IDBKeyRange): Promise<void>;
|
|
73
74
|
truncate(): Promise<void>;
|
|
74
75
|
dropIndex(name: string): void;
|
|
75
76
|
keys(key?: IDBValidKey | IDBKeyRange | null, count?: number): Promise<IDBValidKey[]>;
|
|
76
77
|
count(key?: IDBValidKey | IDBKeyRange): Promise<number>;
|
|
77
78
|
query<R extends Row>(key?: IDBValidKey | IDBKeyRange, count?: number): Promise<RowPacket<R>>;
|
|
79
|
+
queryByKeys<R extends Row>(keys: IDBValidKey[]): Promise<RowPacket<R>>;
|
|
78
80
|
queryByIndex<R extends Row>(indexName: string, key?: IDBValidKey | IDBKeyRange, count?: number): Promise<RowPacket<R>>;
|
|
79
81
|
select<R extends Row>(key?: IDBValidKey | IDBKeyRange, count?: number, indexName?: string): Promise<RowPacket<R>>;
|
|
80
82
|
queryByKey<R extends Row>(key: IDBValidKey | IDBKeyRange): Promise<RowPacket<R>>;
|
package/lib/table.js
CHANGED
|
@@ -253,15 +253,24 @@ export default class Table {
|
|
|
253
253
|
return _request(store.put(modify, key));
|
|
254
254
|
});
|
|
255
255
|
}
|
|
256
|
+
deleteByKeys(...keys) {
|
|
257
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
258
|
+
if (!keys.length) {
|
|
259
|
+
return Promise.reject('keys is required');
|
|
260
|
+
}
|
|
261
|
+
let objectStore = _getObjectStore(this, 'readwrite');
|
|
262
|
+
for (let key of keys) {
|
|
263
|
+
yield _request(objectStore.delete(key));
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
}
|
|
256
267
|
delete(key) {
|
|
257
268
|
return __awaiter(this, void 0, void 0, function* () {
|
|
258
269
|
if (!key) {
|
|
259
270
|
return Promise.reject('key is required');
|
|
260
271
|
}
|
|
261
272
|
let objectStore = _getObjectStore(this, 'readwrite');
|
|
262
|
-
let rows = yield _request(objectStore.getAll(key));
|
|
263
273
|
yield _request(objectStore.delete(key));
|
|
264
|
-
return rows;
|
|
265
274
|
});
|
|
266
275
|
}
|
|
267
276
|
truncate() {
|
|
@@ -282,6 +291,20 @@ export default class Table {
|
|
|
282
291
|
return new RowPacket(rows);
|
|
283
292
|
});
|
|
284
293
|
}
|
|
294
|
+
queryByKeys(keys) {
|
|
295
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
296
|
+
if (!keys.length) {
|
|
297
|
+
return Promise.reject('keys is required');
|
|
298
|
+
}
|
|
299
|
+
let objectStore = _getObjectStore(this);
|
|
300
|
+
let rows = [];
|
|
301
|
+
for (let key of keys) {
|
|
302
|
+
let row = yield _request(objectStore.get(IDBKeyRange.only(key)));
|
|
303
|
+
rows.push(row);
|
|
304
|
+
}
|
|
305
|
+
return new RowPacket(rows);
|
|
306
|
+
});
|
|
307
|
+
}
|
|
285
308
|
queryByIndex(indexName, key, count) {
|
|
286
309
|
return __awaiter(this, void 0, void 0, function* () {
|
|
287
310
|
const store = _getObjectStore(this);
|
package/package.json
CHANGED
package/src/mapper.ts
CHANGED
|
@@ -1,65 +1,77 @@
|
|
|
1
1
|
import Table, {Pagination, Row, RowPacket} from "./table";
|
|
2
2
|
|
|
3
3
|
export default class Mapper<T extends Row> {
|
|
4
|
-
private
|
|
4
|
+
private _table: Table;
|
|
5
5
|
|
|
6
6
|
constructor(table: Table) {
|
|
7
|
-
this.
|
|
7
|
+
this._table = table;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
get table(): Table {
|
|
11
|
+
return this._table;
|
|
8
12
|
}
|
|
9
13
|
|
|
10
14
|
truncate() {
|
|
11
|
-
return this.
|
|
15
|
+
return this._table.truncate();
|
|
12
16
|
}
|
|
13
17
|
|
|
14
18
|
count(key?: IDBValidKey | IDBKeyRange) {
|
|
15
|
-
return this.
|
|
19
|
+
return this._table.count(key);
|
|
16
20
|
}
|
|
17
21
|
|
|
18
22
|
insert(data: T | Array<T>) {
|
|
19
|
-
return this.
|
|
23
|
+
return this._table.insert(data);
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
update(modify: Row, key?: IDBValidKey | IDBKeyRange | null): Promise<IDBValidKey> {
|
|
23
|
-
return this.
|
|
27
|
+
return this._table.update(modify, key);
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
query(key?: IDBValidKey | IDBKeyRange, count?: number): Promise<RowPacket<T>> {
|
|
27
|
-
return this.
|
|
31
|
+
return this._table.query(key, count);
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
queryById(id: any | Array<any>, indexName?: string): Promise<T | Array<T>> {
|
|
31
|
-
return this.
|
|
35
|
+
return this._table.queryById(id, indexName);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
deleteByKeys(...keys: IDBValidKey[]): Promise<void> {
|
|
39
|
+
return this._table.deleteByKeys(...keys);
|
|
32
40
|
}
|
|
33
41
|
|
|
34
|
-
delete(key: IDBValidKey | IDBKeyRange): Promise<
|
|
35
|
-
return this.
|
|
42
|
+
delete(key: IDBValidKey | IDBKeyRange): Promise<void> {
|
|
43
|
+
return this._table.delete(key);
|
|
36
44
|
}
|
|
37
45
|
|
|
38
46
|
queryByIndex(indexName: string, key?: IDBValidKey | IDBKeyRange, count?: number): Promise<RowPacket<T>> {
|
|
39
|
-
return this.
|
|
47
|
+
return this._table.queryByIndex(indexName, key, count);
|
|
40
48
|
}
|
|
41
49
|
|
|
42
50
|
queryByKey(key: IDBValidKey | IDBKeyRange): Promise<RowPacket<T>> {
|
|
43
|
-
return this.
|
|
51
|
+
return this._table.queryByKey(key);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async queryByKeys<R extends Row>(keys: IDBValidKey[]): Promise<RowPacket<R>> {
|
|
55
|
+
return this._table.queryByKeys(keys);
|
|
44
56
|
}
|
|
45
57
|
|
|
46
58
|
scan(key?: IDBValidKey | IDBKeyRange, direction: IDBCursorDirection = 'next', indexName?: string): Promise<RowPacket<T>> {
|
|
47
|
-
return this.
|
|
59
|
+
return this._table.scan(key, direction, indexName);
|
|
48
60
|
}
|
|
49
61
|
|
|
50
62
|
select(key?: IDBValidKey | IDBKeyRange, count?: number, indexName?: string): Promise<RowPacket<T>> {
|
|
51
|
-
return this.
|
|
63
|
+
return this._table.select(key, count, indexName);
|
|
52
64
|
}
|
|
53
65
|
|
|
54
66
|
paginate<R extends Row>(pageNo: number = 1, pageSize: number = 10, key?: IDBValidKey | IDBKeyRange, indexName?: string): Promise<RowPacket<R>> {
|
|
55
|
-
return this.
|
|
67
|
+
return this._table.paginate(pageNo, pageSize, key, indexName);
|
|
56
68
|
}
|
|
57
69
|
|
|
58
70
|
getPagination(pageSize: number = 10): Promise<Pagination<T>> {
|
|
59
|
-
return this.
|
|
71
|
+
return this._table.getPagination(pageSize);
|
|
60
72
|
}
|
|
61
73
|
|
|
62
74
|
getAll(): Promise<Array<T>> {
|
|
63
|
-
return this.
|
|
75
|
+
return this._table.getAllData();
|
|
64
76
|
}
|
|
65
77
|
}
|
package/src/table.ts
CHANGED
|
@@ -392,18 +392,25 @@ export default class Table implements ITable{
|
|
|
392
392
|
return _request(store.put(modify, key as IDBValidKey));
|
|
393
393
|
}
|
|
394
394
|
|
|
395
|
+
async deleteByKeys<R extends Row>(...keys: IDBValidKey[]): Promise<void> {
|
|
396
|
+
if (!keys.length) {
|
|
397
|
+
return Promise.reject('keys is required');
|
|
398
|
+
}
|
|
399
|
+
let objectStore = _getObjectStore(this, 'readwrite');
|
|
400
|
+
for (let key of keys) {
|
|
401
|
+
await _request(objectStore.delete(key));
|
|
402
|
+
}
|
|
403
|
+
}
|
|
395
404
|
/**
|
|
396
405
|
* 根据主键值删除
|
|
397
406
|
* @param key
|
|
398
407
|
*/
|
|
399
|
-
async delete<R extends Row>(key: IDBValidKey | IDBKeyRange): Promise<
|
|
408
|
+
async delete<R extends Row>(key: IDBValidKey | IDBKeyRange): Promise<void> {
|
|
400
409
|
if (!key) {
|
|
401
410
|
return Promise.reject('key is required');
|
|
402
411
|
}
|
|
403
412
|
let objectStore = _getObjectStore(this, 'readwrite');
|
|
404
|
-
let rows = await _request(objectStore.getAll(key));
|
|
405
413
|
await _request(objectStore.delete(key));
|
|
406
|
-
return rows;
|
|
407
414
|
}
|
|
408
415
|
|
|
409
416
|
/**
|
|
@@ -448,6 +455,19 @@ export default class Table implements ITable{
|
|
|
448
455
|
return new RowPacket<R>(rows);
|
|
449
456
|
}
|
|
450
457
|
|
|
458
|
+
async queryByKeys<R extends Row>(keys: IDBValidKey[]): Promise<RowPacket<R>> {
|
|
459
|
+
if (!keys.length) {
|
|
460
|
+
return Promise.reject('keys is required');
|
|
461
|
+
}
|
|
462
|
+
let objectStore = _getObjectStore(this);
|
|
463
|
+
let rows: Array<R> = []
|
|
464
|
+
for (let key of keys) {
|
|
465
|
+
let row = await _request(objectStore.get(IDBKeyRange.only(key)));
|
|
466
|
+
rows.push(row)
|
|
467
|
+
}
|
|
468
|
+
return new RowPacket(rows);
|
|
469
|
+
}
|
|
470
|
+
|
|
451
471
|
/**
|
|
452
472
|
*
|
|
453
473
|
* @param indexName 索引名称
|