xdriver 1.0.3 → 1.0.7
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/Table.d.ts +3 -1
- package/lib/Table.js +25 -2
- package/package.json +1 -1
package/lib/Table.d.ts
CHANGED
|
@@ -16,15 +16,17 @@ export default class Table {
|
|
|
16
16
|
}, database: Database);
|
|
17
17
|
insert(data: Array<any>): Promise<unknown>;
|
|
18
18
|
update(modify: any, where?: any): Promise<unknown> | undefined;
|
|
19
|
+
merge(row: any): Promise<unknown> | undefined;
|
|
19
20
|
delete(key: any): void;
|
|
20
21
|
clear(): void;
|
|
21
22
|
dropIndex(name: string): void;
|
|
22
23
|
keys(keyRange?: KeyRange, limit?: number): any;
|
|
23
24
|
count(keyRange?: KeyRange): any;
|
|
24
25
|
query(keyRange?: KeyRange, limit?: number): any;
|
|
26
|
+
select(where: any, options?: any): any;
|
|
25
27
|
queryByKey(key: any): any;
|
|
26
28
|
fetch(keyRange?: KeyRange, direction?: CursorDirection): Promise<unknown>;
|
|
27
|
-
queryByIndex(name: string, key: any): any;
|
|
29
|
+
queryByIndex(name: string, key: any, count?: number): any;
|
|
28
30
|
deplete(direction?: any): Promise<unknown>;
|
|
29
31
|
multiple(indexName: string, each: Function, keyRange?: KeyRange, cursorDirection?: CursorDirection): Promise<unknown>;
|
|
30
32
|
}
|
package/lib/Table.js
CHANGED
|
@@ -68,6 +68,19 @@ export default class Table {
|
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
+
merge(row) {
|
|
72
|
+
let { primaryKey } = this;
|
|
73
|
+
if (row[primaryKey]) {
|
|
74
|
+
let where = {};
|
|
75
|
+
where[primaryKey] = primaryKey;
|
|
76
|
+
let modify = Object.assign({}, row);
|
|
77
|
+
delete modify[primaryKey];
|
|
78
|
+
return this.update(modify, where);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
return this.insert(row);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
71
84
|
delete(key) {
|
|
72
85
|
_request(_getObjectStore(this, TransactionMode.READ_WRITE).delete(key));
|
|
73
86
|
}
|
|
@@ -90,6 +103,16 @@ export default class Table {
|
|
|
90
103
|
const request = _getObjectStore(this).getAll(keyRange, limit);
|
|
91
104
|
return _request(request);
|
|
92
105
|
}
|
|
106
|
+
select(where, options) {
|
|
107
|
+
if (!where) {
|
|
108
|
+
return this.query();
|
|
109
|
+
}
|
|
110
|
+
let { index = '', limit = void 0, useIndex = false } = options;
|
|
111
|
+
if (useIndex && index) {
|
|
112
|
+
return this.queryByIndex(index, where, limit);
|
|
113
|
+
}
|
|
114
|
+
return this.query(where, limit);
|
|
115
|
+
}
|
|
93
116
|
queryByKey(key) {
|
|
94
117
|
const request = _getObjectStore(this).get(key);
|
|
95
118
|
return _request(request);
|
|
@@ -111,10 +134,10 @@ export default class Table {
|
|
|
111
134
|
});
|
|
112
135
|
});
|
|
113
136
|
}
|
|
114
|
-
queryByIndex(name, key) {
|
|
137
|
+
queryByIndex(name, key, count) {
|
|
115
138
|
const store = _getObjectStore(this);
|
|
116
139
|
const index = store.index(name);
|
|
117
|
-
return _request(index.getAll(key));
|
|
140
|
+
return _request(index.getAll(key, count));
|
|
118
141
|
}
|
|
119
142
|
deplete(direction = CursorDirection.NEXT) {
|
|
120
143
|
const store = _getObjectStore(this, TransactionMode.READ_WRITE);
|