-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtinyDB.d.ts
287 lines (276 loc) · 8.78 KB
/
tinyDB.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/**
* ITableDefine 数据表的结构定义
*
*/
export interface ITableDefine {
/**
* 表名称
*/
TableName: string;
/**
* 索引定义列表
*/
IndexDefines?: ITableIndexDefine[]
}
/**
* ITableIndexDefine 数据表结构的索引结构定义
* example:
* [
* {
* TableName: "Person",
* IndexDefines: [
* {
* IndexName: "Id",
* FieldName: "Id",
* IsUnique: true
* }
* ]
* },
* {
* TableName: "Account",
* IndexDefines: [
* {
* IndexName: "Id",
* FieldName: "Id",
* IsUnique: true
* }
* ]
* }
*]
*/
export interface ITableIndexDefine {
/**
* 索引名称
*/
IndexName: string;
/**
* 索引对应的字段名称
*/
FieldName: string;
/**
* 是否是Unique
*/
IsUnique: boolean;
}
/**
* IIndexedDBDriver indexedDB数据库驱动定义
*/
interface IIndexedDBDriver {
/**
* 打开数据库
* @param {string} dbName
* @param {number} dbVersion
* @param {ITableDefine[]} tbsObj
*/
Open(dbName: string, dbVersion: number, tbsObj: ITableDefine[]): void;
/**
* 获取一个事务
* @param {[string]} tbNames 表名称列表
* @param {DBTranscationModel} mode
* @returns IDBTransaction
*/
GetTransaction(tbNames: string[], mode: DBTranscationModel): IDBTransaction;
/**
* 获取一个store
* @param {string} tbName 表名称
* @param {IDBTransaction} trans 事务对象
* @returns IDBObjectStore
*/
GetStore(tbName: string, trans: IDBTransaction): IDBObjectStore;
/**
* 获取一个索引
* @param {IDBObjectStore} store
* @param {string} indexName
* @returns IDBIndex
*/
GetStoreIndex(store: IDBObjectStore, indexName: string): IDBIndex;
/**
* 获取一个索引游标
* @param {IDBIndex} index
* @param {(x:IDBCursor)=>void} fn
* @param {IDBKeyRange} range?
* @returns void
*/
GetIndexCursor(index: IDBIndex, fn: (x: IDBCursor) => void, range?: IDBKeyRange): void;
/**
* 获取一个游标
* @param {IDBObjectStore} store
* @param {(x:IDBCursor)=>void} fn
* @param {IDBKeyRange} range?
* @returns void
*/
GetCursor(store: IDBObjectStore, fn: (x: IDBCursor) => void, range?: IDBKeyRange): void;
GetById(store: IDBObjectStore, value, fn?): void;
/**
* 关闭数据库
*/
Close();
/**
* 删除数据库
* @param {string} dbName
* @returns void
*/
DeleteDataBase(dbName: string): void;
}
/**
* 实体对象接口定义
*/
export interface IEntityObject {
id: string | number;
/**
* 返回实体名称
* @returns string
*/
toString(): string;
clone(source: any, destination, isDeep: boolean): any;
}
/**
* 查询对象接口定义
*/
export interface IQueryObject<T> {
/**
* 查询,最后通过toList方法提交查询。
* @param {(x:T)=>boolean} qFn 查询条件函数
* @param {string[]} paramsKey? 参数名称列表
* @param {any[]} paramsValue? 参数值列表
* @returns IQueryObject 查询对象
*/
Where(qFn: (x: T) => boolean, paramsKey?: string[], paramsValue?: any[]): IQueryObject<T>;
Where<K extends IEntityObject>(qFn: (x: K) => boolean, paramsKey?: string[], paramsValue?: any[], entity?: K): IQueryObject<T>;
/**
* 左外连接查询
*
* @template K
* @param {(x: K) => void} qFn
* @param {K} entity
*
* @memberOf IQueryObject
*/
Join<K extends IEntityObject>(qFn: (x: K) => void, entity: K, mainFeild?: string, isMainTable?: boolean): IQueryObject<T>;
LeftJoin<F extends IEntityObject>(fEntity: F): IJoinQueryObject<T>;
/**
* 从集合中查找是否有符合匹配的项,存在任何一项返回true,不存在返回false
* @param {(entityObject:T)=>boolean} qFn 查询条件函数
* @param {string[]} paramsKey? 参数名称列表
* @param {any[]} paramsValue? 参数值列表
* @param {(result:boolean)=>void} queryCallback? 结果回调函数
* @returns boolean
*/
Any(qFn: (entityObject: T) => boolean, paramsKey?: string[], paramsValue?: any[], queryCallback?: (result: boolean) => void): Promise<boolean>;
/**
* 根据查询条件返回第一项结果,存在返回实体对象,不存在返回null
* @param {(entityObject:T)=>boolean} qFn? 查询条件函数
* @param {string[]} paramsKey? 参数名称列表
* @param {any[]} paramsValue? 参数值列表
* @param {(result:T)=>void} queryCallback? 结果回调函数
* @returns T
*/
First(qFn?: (entityObject: T) => boolean,
paramsKey?: string[],
paramsValue?: any[],
queryCallback?: (result: T) => void): Promise<T>;
/**
* 执行查询条件,查询结果集
*
* @returns {Promise<T[]>}
*
* @memberOf IQueryObject
*/
ToList(): Promise<T[]>;
/**
* 执行查询条件。
* @param {(result:T[])=>void} queryCallback? 结果集回调函数
* @returns T[]
*/
ToList<TResult>(queryCallback?: (result: TResult[]) => void): Promise<TResult[]>;
/**
* 获取查询结果集中的结果条数
* @param {(entityObject:T)=>boolean} qFn? 查询条件函数
* @param {string[]} paramsKey? 参数名称列表
* @param {any[]} paramsValue? 参数值列表
* @param {(result:number)=>void} queryCallback? 结果回调函数
* @returns number
*/
Count(qFn?: (entityObject: T) => boolean, paramsKey?: string[], paramsValue?: any[], queryCallback?: (result: number) => void): Promise<number>;
/**
*
*
* @param {(entityObject: T) => void} [qFn]
* @returns {Promise<number>}
* @memberof IQueryObject
*/
Sum(qFn?: (entityObject: T) => void): Promise<number>;
/**
* 查询排序
* @param {(x:T)=>void} qFn 查询条件函数
* @returns IQueryObject 查询对象
*/
OrderBy(qFn: (x: T) => void): IQueryObject<T>;
OrderBy<K extends IEntityObject>(qFn: (x: K) => void, entity?: K): IQueryObject<T>;
/**
* 查询排序,倒序
* @param {(x:T)=>void} qFn 查询条件函数
* @returns IQueryObject 查询对象
*/
OrderByDesc(qFn: (x: T) => void): IQueryObject<T>;
OrderByDesc<K extends IEntityObject>(qFn: (x: K) => void, entity?: K): IQueryObject<T>;
GroupBy(qFn: (x: T) => void): IQueryObject<T>;
/**
* 设置需要查询的字段
* @param {(x:T)=>void} qFn 查询条件函数
* @returns IQueryObject 查询对象
*/
Select(qFn: (x: T) => void): IQueryObject<T>;
/**
* 获取的结果条数
* @param {number} count 获取的数目
* @returns IQueryObject 查询对象
*/
Take(count: number): IQueryObject<T>;
/**
* 跳过的结果条数
* @param {number} count 跳过查询的数目
* @returns IQueryObject 查询对象
*/
Skip(count: number): IQueryObject<T>;
Max(qFn: (x: T) => void): Promise<number>;
Min(qFn: (x: T) => void): Promise<number>;
Contains(feild: (x: T) => void, values: any[]): IQueryObject<T>;
Contains<K extends IEntityObject>(feild: (x: K) => void, values: any[], entity: K): IQueryObject<T>;
}
export interface IJoinQueryObject<T> {
On<F extends IEntityObject>(func: (m: T, f: F) => void): IQueryObject<T>;
On<M extends IEntityObject, F extends IEntityObject>(func: (m: M, f: F) => void, mEntity: M): IQueryObject<T>;
}
interface DBTranscationModel { }
export interface IDataContext {
Create(obj: IEntityObject, exclude?: string[]);
Update(obj: IEntityObject, exclude?: string[]);
Delete(obj: IEntityObject);
Delete<T extends IEntityObject>(obj: IEntityObject, func: (x: T) => boolean);
Delete<T extends IEntityObject>(obj: IEntityObject, func: (x: T) => boolean, paramsKey: string[], paramsValue: any[]);
BeginTranscation();
Commit();
Query(...args);
RollBack();
}
/*~ This is the global-modifying module template file. You should rename it to index.d.ts
*~ and place it in a folder with the same name as the module.
*~ For example, if you were writing a file for "super-greeter", this
*~ file should be 'super-greeter/index.d.ts'
*/
/*~ Note: If your global-modifying module is callable or constructable, you'll
*~ need to combine the patterns here with those in the module-class or module-function
*~ template files
*/
declare global {
/*~ Here, declare things that go in the global namespace, or augment
*~ existing declarations in the global namespace
*/
interface String {
IndexOf(str: string): boolean;
}
interface Array<T> {
IndexOf(str: string): boolean;
}
}