-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataSourceQuerier.ts
175 lines (156 loc) · 4.41 KB
/
dataSourceQuerier.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
import { QueryLanguage } from './queryLanguage';
import { Dictionary } from 'lodash';
export interface IDataSourceQuerier<
TIn,
TOut extends TIn,
TQuery = QueryLanguage.SelectQueryOrCondition,
TOptions = QueryLanguage.IQueryOptions
> {
// -----
// ### Insert
/**
* Insert a single entity in the data store.
*
* @summary At least one of {@link insertOne} or {@link insertMany} must be reimplemented by adapter.
* @author gerkin
*/
insertOne( table: string, entity: TIn ): Promise<TOut | undefined>;
/**
* Insert several entities in the data store.
*
* @summary At least one of {@link insertOne} or {@link insertMany} must be reimplemented by adapter.
* @author gerkin
*/
insertMany( table: string, entities: TIn[] ): Promise<TOut[]>;
// -----
// ### Find
/**
* Retrieve a single entity from the data store.
*
* @summary At least one of {@link findOne} or {@link findMany} must be reimplemented by adapter.
* @author gerkin
*/
findOne(
table: string,
queryFind: TQuery,
options: TOptions
): Promise<TOut | undefined>;
/**
* Retrieve several entities from the data store.
*
* @summary At least one of {@link findOne} or {@link findMany} must be reimplemented by adapter.
* @author gerkin
*/
findMany(
table: string,
queryFind: TQuery,
options: TOptions
): Promise<TOut[]>;
// -----
// ### Update
/**
* Update a single entity from the data store.
*
* @summary At least one of {@link updateOne} or {@link updateMany} must be reimplemented by adapter.
* @author gerkin
*/
updateOne(
table: string,
queryFind: TQuery,
update: TIn,
options: TOptions
): Promise<TOut | undefined>;
/**
* Update several entities from the data store.
*
* @summary At least one of {@link updateOne} or {@link updateMany} must be reimplemented by adapter.
* @author gerkin
*/
updateMany(
table: string,
queryFind: TQuery,
update: TIn,
options: TOptions
): Promise<TOut[]>;
// -----
// ### Delete
/**
* Delete a single entity from the data store.
*
* @summary At least one of {@link deleteOne} or {@link deleteMany} must be reimplemented by adapter.
* @author gerkin
*/
deleteOne( table: string, queryFind: TQuery, options: TOptions ): Promise<void>;
/**
* Delete several entities from the data store.
*
* @summary At least one of {@link deleteOne} or {@link deleteMany} must be reimplemented by adapter.
* @author gerkin
* @param table - Name of the table to delete data from.
* @param queryFind - Hash representing the entities to find.
* @param options - Hash of options.
* @returns Promise resolved once item is found. Called with (*{@link DataStoreEntity}[]* `entities`).
*/
deleteMany(
table: string,
queryFind: TQuery,
options: TOptions
): Promise<void>;
// -----
// ### Utils
/**
* Check if the data store contains at least one element matching the query.
*
* @param collectionName - Name of the data store to search entities in
* @param queryFind - Description of the entities to match
* @param options - Options to apply to the query
*/
contains(
table: string,
queryFind: TQuery,
options: TOptions
): Promise<boolean>;
/**
* Get the number of elements in a data store matching the query.
*
* @param collectionName - Name of the data store to search entities in
* @param queryFind - Description of the entities to match
* @param options - Options to apply to the query
*/
count(
table: string,
queryFind: TQuery,
options: TOptions
): Promise<number>;
/**
* Check if every elements in the data store matches the query.
*
* @param collectionName - Name of the data store to search entities in
* @param queryFind - Description of the entities to match
* @param options - Options to apply to the query
*/
every(
table: string,
queryFind: TQuery,
options: TOptions
): Promise<boolean>;
// -----
// ### Various
/**
* Returns a promise resolved once the data source querier is ready.
*
* @author gerkin
* @returns Promise resolved when the data source is ready, and rejected if an error occured.
*/
waitReady(): Promise<this>;
/**
* Saves the remapping table, the reversed remapping table and the filter table in the adapter. Those tables will be used later when manipulating models & entities.
*
* @author gerkin
*/
configureCollection(
tableName: string,
remaps: Dictionary<string>,
filters: Dictionary<any>
): this;
}