xdriver 1.0.7 → 1.0.11
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 +13 -2
- package/lib/Driver.d.ts +4 -3
- package/lib/Driver.js +4 -1
- package/lib/Table.d.ts +3 -3
- package/lib/Table.js +4 -4
- 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?: string | undefined, version?:
|
|
12
|
+
open(name?: string | 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,9 @@ export default class Database {
|
|
|
39
47
|
return this.connect != null;
|
|
40
48
|
}
|
|
41
49
|
open(name, version) {
|
|
50
|
+
if (!name && !version && this.isOpen()) {
|
|
51
|
+
return Promise.resolve(this);
|
|
52
|
+
}
|
|
42
53
|
this.name = name || this.name;
|
|
43
54
|
this.version = version || this.version;
|
|
44
55
|
const request = innerDB.open(this.name, version);
|
|
@@ -52,7 +63,7 @@ export default class Database {
|
|
|
52
63
|
this.events.process(IndexdbStatus.CONNECT_CLOSE);
|
|
53
64
|
this.events.close.call(this, e.target.result);
|
|
54
65
|
};
|
|
55
|
-
return new Promise((resolve) => {
|
|
66
|
+
return new Promise((resolve, reject) => {
|
|
56
67
|
request.onsuccess = (e) => {
|
|
57
68
|
this.connect = e.target.result;
|
|
58
69
|
this.events.process(IndexdbStatus.CONNECT_SUCCESS);
|
|
@@ -68,7 +79,7 @@ export default class Database {
|
|
|
68
79
|
this.events.process(IndexdbStatus.CONNECT_SUCCESS);
|
|
69
80
|
this.connect = e.target.result;
|
|
70
81
|
this.events.change.call(this, this.connect);
|
|
71
|
-
|
|
82
|
+
this.initialized();
|
|
72
83
|
};
|
|
73
84
|
});
|
|
74
85
|
}
|
package/lib/Driver.d.ts
CHANGED
|
@@ -2,11 +2,12 @@ import { KeyRange } from "./Const";
|
|
|
2
2
|
import Database from "./Database";
|
|
3
3
|
declare class Driver extends Database {
|
|
4
4
|
insert(table: string, data: Array<any>): Promise<unknown>;
|
|
5
|
-
|
|
5
|
+
query(table: string, keyRange?: KeyRange, limit?: number): any;
|
|
6
|
+
select(table: string, where: any, options?: any): any;
|
|
6
7
|
selectByKey(table: string, key: any): any;
|
|
7
8
|
count(table: string, keyRange?: KeyRange): any;
|
|
8
9
|
update(table: string, modify: any, where: any): Promise<unknown> | undefined;
|
|
9
|
-
delete(table: string, key: any):
|
|
10
|
-
truncate(table: string):
|
|
10
|
+
delete(table: string, key: any): any;
|
|
11
|
+
truncate(table: string): any;
|
|
11
12
|
}
|
|
12
13
|
export default Driver;
|
package/lib/Driver.js
CHANGED
|
@@ -3,9 +3,12 @@ class Driver extends Database {
|
|
|
3
3
|
insert(table, data) {
|
|
4
4
|
return this.table(table).insert(data);
|
|
5
5
|
}
|
|
6
|
-
|
|
6
|
+
query(table, keyRange, limit) {
|
|
7
7
|
return this.table(table).query(keyRange, limit);
|
|
8
8
|
}
|
|
9
|
+
select(table, where, options) {
|
|
10
|
+
return this.table(table).select(where, options);
|
|
11
|
+
}
|
|
9
12
|
selectByKey(table, key) {
|
|
10
13
|
return this.table(table).queryByKey(key);
|
|
11
14
|
}
|
package/lib/Table.d.ts
CHANGED
|
@@ -17,9 +17,9 @@ export default class Table {
|
|
|
17
17
|
insert(data: Array<any>): Promise<unknown>;
|
|
18
18
|
update(modify: any, where?: any): Promise<unknown> | undefined;
|
|
19
19
|
merge(row: any): Promise<unknown> | undefined;
|
|
20
|
-
delete(key: any):
|
|
21
|
-
clear():
|
|
22
|
-
dropIndex(name: string):
|
|
20
|
+
delete(key: any): any;
|
|
21
|
+
clear(): any;
|
|
22
|
+
dropIndex(name: string): any;
|
|
23
23
|
keys(keyRange?: KeyRange, limit?: number): any;
|
|
24
24
|
count(keyRange?: KeyRange): any;
|
|
25
25
|
query(keyRange?: KeyRange, limit?: number): any;
|
package/lib/Table.js
CHANGED
|
@@ -82,13 +82,13 @@ export default class Table {
|
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
delete(key) {
|
|
85
|
-
_request(_getObjectStore(this, TransactionMode.READ_WRITE).delete(key));
|
|
85
|
+
return _request(_getObjectStore(this, TransactionMode.READ_WRITE).delete(key));
|
|
86
86
|
}
|
|
87
87
|
clear() {
|
|
88
|
-
_request(_getObjectStore(this, TransactionMode.READ_WRITE).clear());
|
|
88
|
+
return _request(_getObjectStore(this, TransactionMode.READ_WRITE).clear());
|
|
89
89
|
}
|
|
90
90
|
dropIndex(name) {
|
|
91
|
-
_getObjectStore(this, TransactionMode.READ_WRITE).deleteIndex(name);
|
|
91
|
+
return _getObjectStore(this, TransactionMode.READ_WRITE).deleteIndex(name);
|
|
92
92
|
}
|
|
93
93
|
keys(keyRange, limit) {
|
|
94
94
|
const store = _getObjectStore(this);
|
|
@@ -107,7 +107,7 @@ export default class Table {
|
|
|
107
107
|
if (!where) {
|
|
108
108
|
return this.query();
|
|
109
109
|
}
|
|
110
|
-
let { index = '', limit = void 0, useIndex = false } = options;
|
|
110
|
+
let { index = '', limit = void 0, useIndex = false } = options || {};
|
|
111
111
|
if (useIndex && index) {
|
|
112
112
|
return this.queryByIndex(index, where, limit);
|
|
113
113
|
}
|