UNPKG

9.02 kBTypeScriptView Raw
1/// <reference types="@fxjs/sql-query" />
2
3declare namespace FxOrmQuery {
4 /* query conditions :start */
5 type QueryConditionInTypeType = string | number
6
7 type QueryCondition_SimpleEq = { [key: string]: FxSqlQueryComparator.SimpleEqValueType }
8
9 type QueryCondition_eq = { [key: string]: FxSqlQueryComparator.SimpleEqValueType | FxSqlQueryComparator.InputValue_eq }
10 type QueryCondition_ne = { [key: string]: FxSqlQueryComparator.InputValue_ne }
11 type QueryCondition_gt = { [key: string]: FxSqlQueryComparator.InputValue_gt }
12 type QueryCondition_gte = { [key: string]: FxSqlQueryComparator.InputValue_gte }
13 type QueryCondition_lt = { [key: string]: FxSqlQueryComparator.InputValue_lt }
14 type QueryCondition_lte = { [key: string]: FxSqlQueryComparator.InputValue_lte }
15 type QueryCondition_like = { [key: string]: FxSqlQueryComparator.InputValue_like }
16 type QueryCondition_not_like = { [key: string]: FxSqlQueryComparator.InputValue_not_like }
17 type QueryCondition_between = { [key: string]: FxSqlQueryComparator.InputValue_between }
18 type QueryCondition_not_between = { [key: string]: FxSqlQueryComparator.InputValue_not_between }
19
20 type QueryCondition_in = { [key: string]: FxSqlQueryComparator.InputValue_in }
21 type QueryCondition_not_in = { [key: string]: FxSqlQueryComparator.InputValue_not_in }
22
23 type QueryConditionAtomicType =
24 QueryCondition_eq |
25 QueryCondition_ne |
26 QueryCondition_gt |
27 QueryCondition_gte |
28 QueryCondition_lt |
29 QueryCondition_lte |
30 QueryCondition_like |
31 QueryCondition_not_like |
32 QueryCondition_between |
33 QueryCondition_not_between |
34 QueryCondition_in |
35 QueryCondition_not_in
36
37 type QueryConditions = FxSqlQuerySubQuery.SubQueryConditions
38 /* query conditions :end */
39
40 type OrderNormalizedTuple = FxSqlQuery.OrderNormalizedTuple
41 type OrderSqlStyleTuple = FxSqlQuery.OrderSqlStyleTuple
42 type OrderNormalizedResult = FxSqlQuery.OrderNormalizedResult
43
44 type OrderSeqRawTuple = (OrderNormalizedTupleWithoutTable[0] | OrderNormalizedTupleWithoutTable[1])[]
45 type OrderRawInput = string | OrderSeqRawTuple
46 type OrderNormalizedTupleWithoutTable = [string, "Z" | "A"]
47 type OrderNormalizedTupleMixin = (OrderNormalizedTupleWithoutTable|FxSqlQuery.OrderNormalizedResult)[]
48
49 interface ChainFindMergeInfo {
50 from: {
51 table: string
52 field: string[]
53 }
54 to: {
55 table?: string
56 field: string[]
57 }
58 select: FxSqlQueryColumns.SelectInputArgType[]
59 where: [string, FxOrmModel.ModelQueryConditions__Find]
60 table: string
61 }
62
63 interface ChainWhereExistsInfo {
64 table: string
65 link: FxSqlQuerySql.WhereExistsLinkTuple
66 conditions: FxSqlQuerySubQuery.SubQueryConditions
67 }
68
69 interface InsertResult {
70 insertId?: string | number
71
72 [extra_key: string]: any
73 }
74
75 interface CountResult {
76 c: number
77
78 [extra_key: string]: any
79 }
80
81 interface RemoveResult {
82 [extra_key: string]: any
83 }
84
85 interface AggregationMethod {
86 (...args: string[]): IAggregated
87 (arg: string[]): IAggregated
88 }
89
90 interface IAggregated {
91 groupBy: {
92 (...columns: string[]): IAggregated;
93 }
94 limit: {
95 (limit: number): IAggregated;
96 (offset: number, limit: number): IAggregated;
97 }
98 order: {
99 (...order: string[]): IAggregated;
100 }
101 select: {
102 (columns: string[]): IAggregated;
103 (...columns: string[]): IAggregated;
104 }
105 as: {
106 (alias: string): IAggregated;
107 }
108 call: {
109 (fun: FxOrmDb.AGGREGATION_METHOD_COMPLEX, args: string[]): IAggregated;
110 }
111 getSync: {
112 <T = any>(): FxOrmNS.ExecutionCallback<T[]>
113 }
114 get: {
115 <T = any>(cb?: FxOrmNS.ExecutionCallback<T[]>): void
116 }
117
118 // [ext_method: string]: AggregationMethod
119
120 [ext_k: string]: any
121 }
122
123 type KeyOfIAggregated = keyof IAggregated
124 type AggregationFuncTuple = FxOrmDb.AGGREGATION_METHOD_TUPLE__COMMON
125
126 interface SqlSelectFieldsDescriptor extends FxSqlQuerySql.SqlSelectFieldsDescriptor {
127 args?: string | string[]
128 }
129
130 interface AggregateConstructorOptions {
131 driver: FxOrmDMLDriver.DMLDriver
132 driver_name?: string
133 limit?: [number, number]
134 order?: FxOrmQuery.ChainFindOptions['order']
135 // property name's list
136 propertyList?: string[]
137 table?: string
138 conditions?: FxOrmQuery.QueryConditions
139 properties: FxOrmProperty.NormalizedPropertyHash
140 }
141
142 type AggregateConstructor = new (opts: AggregateConstructorOptions) => IAggregated
143
144 type ChainFindGenerator = new (Model: FxOrmModel.Model, opts: FxOrmQuery.ChainFindOptions) => IChainFind
145
146 interface IChainFind {
147 model: FxOrmModel.Model;
148 options: ChainFindInstanceOptions
149
150 only(...args: (string|string[])[]): IChainFind;
151 omit(...args: (string|string[])[]): IChainFind;
152 skip(offset: number): IChainFind;
153 offset(offset: number): IChainFind;
154
155 order(propertyOrderDesc: string, order?: FxOrmQuery.OrderNormalizedTuple[1]): IChainFind;
156 order(...orders: FxOrmQuery.OrderSeqRawTuple): IChainFind;
157 orderRaw(str: FxOrmQuery.OrderSqlStyleTuple[0], args?: FxOrmQuery.OrderSqlStyleTuple[1]): IChainFind;
158 limit(limit: number): IChainFind;
159
160 count(callback?: FxOrmNS.ExecutionCallback<number>): IChainFind;
161 countSync(): number;
162
163 remove(callback?: FxOrmNS.ExecutionCallback<FxOrmQuery.RemoveResult>): IChainFind;
164 removeSync(): FxOrmQuery.RemoveResult;
165
166 find: {
167 (...conditions: (FxOrmModel.ModelQueryConditionsItem | FxOrmNS.ExecutionCallback<FxOrmInstance.Instance[]>)[]): IChainFind;
168 }
169 findSync: {
170 (...conditions: (FxOrmModel.ModelQueryConditionsItem | FxOrmNS.ExecutionCallback<FxOrmInstance.Instance[]>)[]): FxOrmInstance.Instance[]
171 }
172 all: IChainFind['find']
173 allSync: IChainFind['findSync']
174
175 where: IChainFind['find']
176 whereSync: IChainFind['findSync']
177
178 whereExists: {
179 (...exists: FxOrmQuery.ChainWhereExistsInfo[]): IChainFind;
180 (exists: FxOrmQuery.ChainWhereExistsInfo[]): IChainFind;
181 }
182
183 run(callback?: FxOrmQuery.IChainInstanceCallbackFn): IChainFind;
184 runSync(): FxOrmInstance.Instance[]
185
186 // removed in commit 717ee65a7a23ed6762856cf3c187700e36c9ba70
187 // success(callback?: FxOrmModel.ModelMethodCallback__Find): void;
188 // fail(callback?: FxOrmModel.ModelMethodCallback__Find): void;
189
190 first(callback?: FxOrmNS.GenericCallback<FxOrmInstance.Instance>): IChainFind;
191 firstSync(): FxOrmInstance.Instance;
192 last(callback?: FxOrmNS.GenericCallback<FxOrmInstance.Instance>): IChainFind;
193 lastSync(): FxOrmInstance.Instance;
194
195 each: {
196 (cb?: FxOrmNS.ExecutionCallback<FxOrmInstance.Instance>): IChainInstance;
197 }
198
199 eager: {
200 (...assocs: string[]): IChainFind;
201 (assocs: string[]): IChainFind;
202 }
203
204 [extraProperty: string]: any;
205 }
206
207 interface IChainInstanceCallbackFn {
208 (...args: any[]): any | FxOrmQuery.IChainInstance
209 }
210 interface IChainInstance {
211 _each (cb: IChainInstanceCallbackFn): IChainInstance
212 filter (cb: IChainInstanceCallbackFn): IChainInstance
213 sort (cb: IChainInstanceCallbackFn): IChainInstance
214 count (cb: IChainInstanceCallbackFn): IChainInstance
215 get (cb: IChainInstanceCallbackFn): IChainInstance
216 save (cb: IChainInstanceCallbackFn): IChainInstance
217 }
218
219
220 interface ChainFindOptions {
221 keys: FxOrmModel.ModelConstructorOptions['keys']
222 table: FxOrmModel.ModelConstructorOptions['table']
223 driver: FxOrmModel.ModelConstructorOptions['driver']
224
225 conditions: QueryConditions
226 properties: FxOrmProperty.NormalizedPropertyHash
227 keyProperties: FxOrmProperty.NormalizedProperty[]
228 order: (FxOrmQuery.OrderNormalizedTuple | FxOrmQuery.OrderSqlStyleTuple)[]
229 // only: string|FxSqlQueryColumns.SelectInputArgType[]
230 only: (string|FxSqlQueryColumns.SelectInputArgType)[]
231 limit: number
232 offset: number
233 merge: FxOrmQuery.ChainFindMergeInfo | FxOrmQuery.ChainFindMergeInfo[]
234 newInstanceSync: {
235 (data: FxOrmInstance.InstanceDataPayload): FxOrmInstance.Instance
236 }
237 associations: FxOrmAssociation.InstanceAssociationItem[]
238
239 /* in instance */
240 exists?: FxOrmQuery.ChainWhereExistsInfo[]
241 __eager?: FxOrmAssociation.InstanceAssociationItem[]
242 }
243
244 interface ChainFindInstanceOptions extends ChainFindOptions {
245 }
246}
\No newline at end of file