xdriver 1.0.1 → 1.0.5

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/Const.d.ts CHANGED
@@ -20,7 +20,7 @@ export declare class KeyRange {
20
20
  static gt_lt(x: any, y: any): any;
21
21
  static gt_leq(x: any, y: any): any;
22
22
  static geq_lt(x: any, y: any): any;
23
- static eq(x: any, y: any): any;
23
+ static eq(x: any): any;
24
24
  }
25
25
  export declare enum IndexdbStatus {
26
26
  CONNECT_ING = 0,
package/lib/Const.js CHANGED
@@ -42,7 +42,7 @@ export class KeyRange {
42
42
  static geq_lt(x, y) {
43
43
  return DBKeyRange.bound(x, y, false, true);
44
44
  }
45
- static eq(x, y) {
45
+ static eq(x) {
46
46
  return DBKeyRange.only(x);
47
47
  }
48
48
  }
package/lib/Database.d.ts CHANGED
@@ -10,7 +10,8 @@ export default class Database {
10
10
  open(name?: string | undefined, version?: number | undefined): Promise<unknown>;
11
11
  drop(): Promise<unknown>;
12
12
  close(): void;
13
- createTable(tab: string | object): Table;
13
+ createTable(tab: string | object, options?: object): Table;
14
+ createTables(tables: Array<string | object>, options?: object): Table[];
14
15
  dropTable(tableName: string): any;
15
16
  table(tableName: string): Table;
16
17
  exists(table: string): any;
package/lib/Database.js CHANGED
@@ -92,13 +92,25 @@ export default class Database {
92
92
  this.connect = null;
93
93
  }
94
94
  }
95
- createTable(tab) {
95
+ createTable(tab, options) {
96
96
  let table = tab;
97
97
  if (_instance(tab, String)) {
98
- table = { name: tab };
98
+ table = Object.assign({ name: tab }, options);
99
99
  }
100
100
  return new Table(table, this);
101
101
  }
102
+ createTables(tables, options) {
103
+ return tables.map(table => {
104
+ let opts = Object.assign({}, options);
105
+ if (_instance(table, String)) {
106
+ Object.assign(opts, { name: table });
107
+ }
108
+ else {
109
+ Object.assign(opts, table);
110
+ }
111
+ return new Table(opts, this);
112
+ });
113
+ }
102
114
  dropTable(tableName) {
103
115
  return this.connect.deleteObjectStore(tableName);
104
116
  }
package/lib/Table.d.ts CHANGED
@@ -22,9 +22,10 @@ export default class Table {
22
22
  keys(keyRange?: KeyRange, limit?: number): any;
23
23
  count(keyRange?: KeyRange): any;
24
24
  query(keyRange?: KeyRange, limit?: number): any;
25
+ select(where: any, options?: any): any;
25
26
  queryByKey(key: any): any;
26
27
  fetch(keyRange?: KeyRange, direction?: CursorDirection): Promise<unknown>;
27
- queryByIndex(name: string, key: any): any;
28
+ queryByIndex(name: string, key: any, count?: number): any;
28
29
  deplete(direction?: any): Promise<unknown>;
29
30
  multiple(indexName: string, each: Function, keyRange?: KeyRange, cursorDirection?: CursorDirection): Promise<unknown>;
30
31
  }
package/lib/Table.js CHANGED
@@ -90,6 +90,13 @@ export default class Table {
90
90
  const request = _getObjectStore(this).getAll(keyRange, limit);
91
91
  return _request(request);
92
92
  }
93
+ select(where, options) {
94
+ let { index = '', limit = void 0, useIndex = false } = options;
95
+ if (useIndex && index) {
96
+ return this.queryByIndex(index, where, limit);
97
+ }
98
+ return this.query(where, limit);
99
+ }
93
100
  queryByKey(key) {
94
101
  const request = _getObjectStore(this).get(key);
95
102
  return _request(request);
@@ -111,10 +118,10 @@ export default class Table {
111
118
  });
112
119
  });
113
120
  }
114
- queryByIndex(name, key) {
121
+ queryByIndex(name, key, count) {
115
122
  const store = _getObjectStore(this);
116
123
  const index = store.index(name);
117
- return _request(index.getAll(key));
124
+ return _request(index.getAll(key, count));
118
125
  }
119
126
  deplete(direction = CursorDirection.NEXT) {
120
127
  const store = _getObjectStore(this, TransactionMode.READ_WRITE);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "xdriver",
3
- "version": "1.0.01",
4
- "description": "xdriver",
3
+ "version": "1.0.05",
4
+ "description": "A simple driver for IndexDB",
5
5
  "main": "./lib/index",
6
6
  "files": [
7
7
  "lib/"