xdriver 1.0.5 → 1.0.9
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 +3 -1
- package/lib/Database.js +14 -2
- package/lib/Driver.d.ts +2 -2
- package/lib/Table.d.ts +4 -3
- package/lib/Table.js +19 -3
- package/package.json +1 -1
package/lib/Database.d.ts
CHANGED
|
@@ -3,11 +3,13 @@ export default class Database {
|
|
|
3
3
|
private name;
|
|
4
4
|
private version;
|
|
5
5
|
connect: any;
|
|
6
|
+
private initialized;
|
|
6
7
|
readonly events: any;
|
|
7
8
|
constructor(name: string, version?: number);
|
|
9
|
+
initialize(initialized: Function): this;
|
|
8
10
|
on(event: any, fn?: Function): this;
|
|
9
11
|
isOpen(): boolean;
|
|
10
|
-
open(name?:
|
|
12
|
+
open(name?: any | undefined, version?: any): Promise<unknown>;
|
|
11
13
|
drop(): Promise<unknown>;
|
|
12
14
|
close(): void;
|
|
13
15
|
createTable(tab: string | object, options?: object): Table;
|
package/lib/Database.js
CHANGED
|
@@ -22,6 +22,14 @@ export default class Database {
|
|
|
22
22
|
this.name = name;
|
|
23
23
|
this.version = version;
|
|
24
24
|
this.connect = null;
|
|
25
|
+
this.initialized = () => { };
|
|
26
|
+
}
|
|
27
|
+
initialize(initialized) {
|
|
28
|
+
if (this.isOpen()) {
|
|
29
|
+
throw new Error('You must be call this method before open');
|
|
30
|
+
}
|
|
31
|
+
this.initialized = initialized;
|
|
32
|
+
return this;
|
|
25
33
|
}
|
|
26
34
|
on(event, fn) {
|
|
27
35
|
if (!_instance(event, Object)) {
|
|
@@ -39,6 +47,10 @@ export default class Database {
|
|
|
39
47
|
return this.connect != null;
|
|
40
48
|
}
|
|
41
49
|
open(name, version) {
|
|
50
|
+
if (typeof name === "function") {
|
|
51
|
+
this.initialized = name;
|
|
52
|
+
name = undefined;
|
|
53
|
+
}
|
|
42
54
|
this.name = name || this.name;
|
|
43
55
|
this.version = version || this.version;
|
|
44
56
|
const request = innerDB.open(this.name, version);
|
|
@@ -52,7 +64,7 @@ export default class Database {
|
|
|
52
64
|
this.events.process(IndexdbStatus.CONNECT_CLOSE);
|
|
53
65
|
this.events.close.call(this, e.target.result);
|
|
54
66
|
};
|
|
55
|
-
return new Promise((resolve) => {
|
|
67
|
+
return new Promise((resolve, reject) => {
|
|
56
68
|
request.onsuccess = (e) => {
|
|
57
69
|
this.connect = e.target.result;
|
|
58
70
|
this.events.process(IndexdbStatus.CONNECT_SUCCESS);
|
|
@@ -68,7 +80,7 @@ export default class Database {
|
|
|
68
80
|
this.events.process(IndexdbStatus.CONNECT_SUCCESS);
|
|
69
81
|
this.connect = e.target.result;
|
|
70
82
|
this.events.change.call(this, this.connect);
|
|
71
|
-
|
|
83
|
+
this.initialized();
|
|
72
84
|
};
|
|
73
85
|
});
|
|
74
86
|
}
|
package/lib/Driver.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ declare class Driver extends Database {
|
|
|
6
6
|
selectByKey(table: string, key: any): any;
|
|
7
7
|
count(table: string, keyRange?: KeyRange): any;
|
|
8
8
|
update(table: string, modify: any, where: any): Promise<unknown> | undefined;
|
|
9
|
-
delete(table: string, key: any):
|
|
10
|
-
truncate(table: string):
|
|
9
|
+
delete(table: string, key: any): any;
|
|
10
|
+
truncate(table: string): any;
|
|
11
11
|
}
|
|
12
12
|
export default Driver;
|
package/lib/Table.d.ts
CHANGED
|
@@ -16,9 +16,10 @@ 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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
merge(row: any): Promise<unknown> | undefined;
|
|
20
|
+
delete(key: any): any;
|
|
21
|
+
clear(): any;
|
|
22
|
+
dropIndex(name: string): any;
|
|
22
23
|
keys(keyRange?: KeyRange, limit?: number): any;
|
|
23
24
|
count(keyRange?: KeyRange): any;
|
|
24
25
|
query(keyRange?: KeyRange, limit?: number): any;
|
package/lib/Table.js
CHANGED
|
@@ -68,14 +68,27 @@ 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
|
-
_request(_getObjectStore(this, TransactionMode.READ_WRITE).delete(key));
|
|
85
|
+
return _request(_getObjectStore(this, TransactionMode.READ_WRITE).delete(key));
|
|
73
86
|
}
|
|
74
87
|
clear() {
|
|
75
|
-
_request(_getObjectStore(this, TransactionMode.READ_WRITE).clear());
|
|
88
|
+
return _request(_getObjectStore(this, TransactionMode.READ_WRITE).clear());
|
|
76
89
|
}
|
|
77
90
|
dropIndex(name) {
|
|
78
|
-
_getObjectStore(this, TransactionMode.READ_WRITE).deleteIndex(name);
|
|
91
|
+
return _getObjectStore(this, TransactionMode.READ_WRITE).deleteIndex(name);
|
|
79
92
|
}
|
|
80
93
|
keys(keyRange, limit) {
|
|
81
94
|
const store = _getObjectStore(this);
|
|
@@ -91,6 +104,9 @@ export default class Table {
|
|
|
91
104
|
return _request(request);
|
|
92
105
|
}
|
|
93
106
|
select(where, options) {
|
|
107
|
+
if (!where) {
|
|
108
|
+
return this.query();
|
|
109
|
+
}
|
|
94
110
|
let { index = '', limit = void 0, useIndex = false } = options;
|
|
95
111
|
if (useIndex && index) {
|
|
96
112
|
return this.queryByIndex(index, where, limit);
|