remult 0.22.7-exp.0 → 0.22.7
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/SseSubscriptionServer.d.ts +25 -25
- package/SseSubscriptionServer.js +145 -145
- package/ably.d.ts +13 -13
- package/ably.js +59 -59
- package/assign.d.ts +1 -1
- package/assign.js +9 -9
- package/classType.d.ts +3 -3
- package/classType.js +2 -2
- package/esm/SseSubscriptionServer.d.ts +25 -25
- package/esm/SseSubscriptionServer.js +107 -104
- package/esm/ably.d.ts +13 -13
- package/esm/ably.js +30 -28
- package/esm/assign.d.ts +1 -1
- package/esm/assign.js +5 -5
- package/esm/classType.d.ts +3 -3
- package/esm/classType.js +1 -1
- package/esm/graphql.d.ts +14 -14
- package/esm/graphql.js +785 -785
- package/esm/index.d.ts +31 -31
- package/esm/index.js +25 -25
- package/esm/inputTypes.d.ts +9 -9
- package/esm/inputTypes.js +9 -9
- package/esm/live-query/data-provider-live-query-storage.d.ts +23 -23
- package/esm/live-query/data-provider-live-query-storage.js +91 -93
- package/esm/myLog.d.ts +1 -1
- package/esm/myLog.js +5 -5
- package/esm/postgres/index.d.ts +2 -2
- package/esm/postgres/index.js +2 -2
- package/esm/postgres/postgres-data-provider.d.ts +36 -36
- package/esm/postgres/postgres-data-provider.js +126 -122
- package/esm/postgres/schema-builder.d.ts +19 -19
- package/esm/postgres/schema-builder.js +197 -196
- package/esm/remult-express.d.ts +9 -9
- package/esm/remult-express.js +26 -25
- package/esm/remult-fastify.d.ts +6 -6
- package/esm/remult-fastify.js +68 -68
- package/esm/remult-fresh.d.ts +17 -17
- package/esm/remult-fresh.js +26 -26
- package/esm/remult-knex/index.d.ts +30 -30
- package/esm/remult-knex/index.js +466 -460
- package/esm/remult-mongo.d.ts +24 -24
- package/esm/remult-mongo.js +269 -262
- package/esm/remult-next.d.ts +25 -25
- package/esm/remult-next.js +114 -114
- package/esm/remult-sveltekit.d.ts +4 -4
- package/esm/remult-sveltekit.js +71 -71
- package/esm/server/JsonEntityFileStorage.d.ts +11 -11
- package/esm/server/JsonEntityFileStorage.js +27 -26
- package/esm/server/core.d.ts +4 -4
- package/esm/server/core.js +4 -4
- package/esm/server/expressBridge.d.ts +128 -128
- package/esm/server/expressBridge.js +988 -971
- package/esm/server/index.d.ts +6 -6
- package/esm/server/index.js +12 -12
- package/esm/server/initAsyncHooks.d.ts +1 -1
- package/esm/server/initAsyncHooks.js +9 -9
- package/esm/server/initDataProvider.d.ts +2 -2
- package/esm/server/initDataProvider.js +14 -14
- package/esm/src/CompoundIdField.d.ts +27 -27
- package/esm/src/CompoundIdField.js +54 -41
- package/esm/src/__EntityValueProvider.d.ts +11 -11
- package/esm/src/__EntityValueProvider.js +1 -1
- package/esm/src/__RowsOfDataForTesting.d.ts +3 -3
- package/esm/src/__RowsOfDataForTesting.js +1 -1
- package/esm/src/buildRestDataProvider.d.ts +31 -31
- package/esm/src/buildRestDataProvider.js +121 -120
- package/esm/src/column-interfaces.d.ts +160 -160
- package/esm/src/column-interfaces.js +7 -7
- package/esm/src/column.d.ts +31 -31
- package/esm/src/column.js +108 -101
- package/esm/src/context.d.ts +134 -134
- package/esm/src/context.js +287 -282
- package/esm/src/data-api.d.ts +38 -38
- package/esm/src/data-api.js +281 -279
- package/esm/src/data-interfaces.d.ts +41 -41
- package/esm/src/data-interfaces.js +12 -12
- package/esm/src/data-providers/array-entity-data-provider.d.ts +22 -22
- package/esm/src/data-providers/array-entity-data-provider.js +252 -249
- package/esm/src/data-providers/in-memory-database.d.ts +9 -9
- package/esm/src/data-providers/in-memory-database.js +16 -18
- package/esm/src/data-providers/json-data-provider.d.ts +12 -12
- package/esm/src/data-providers/json-data-provider.js +55 -52
- package/esm/src/data-providers/rest-data-provider.d.ts +39 -39
- package/esm/src/data-providers/rest-data-provider.js +272 -267
- package/esm/src/data-providers/sql-database.d.ts +33 -33
- package/esm/src/data-providers/sql-database.js +401 -394
- package/esm/src/data-providers/web-sql-data-provider.d.ts +21 -21
- package/esm/src/data-providers/web-sql-data-provider.js +145 -137
- package/esm/src/entity.d.ts +95 -95
- package/esm/src/entity.js +1 -1
- package/esm/src/filter/filter-consumer-bridge-to-sql-request.d.ts +50 -50
- package/esm/src/filter/filter-consumer-bridge-to-sql-request.js +165 -162
- package/esm/src/filter/filter-interfaces.d.ts +86 -86
- package/esm/src/filter/filter-interfaces.js +524 -515
- package/esm/src/live-query/LiveQueryClient.d.ts +1 -1
- package/esm/src/live-query/LiveQueryClient.js +196 -192
- package/esm/src/live-query/SseSubscriptionClient.d.ts +5 -5
- package/esm/src/live-query/SseSubscriptionClient.js +86 -86
- package/esm/src/live-query/SubscriptionChannel.d.ts +41 -41
- package/esm/src/live-query/SubscriptionChannel.js +126 -121
- package/esm/src/live-query/SubscriptionServer.d.ts +38 -38
- package/esm/src/live-query/SubscriptionServer.js +114 -112
- package/esm/src/remult-proxy.d.ts +2 -2
- package/esm/src/remult-proxy.js +177 -178
- package/esm/src/remult3/DecoratorReplacer.d.ts +10 -10
- package/esm/src/remult3/DecoratorReplacer.js +20 -20
- package/esm/src/remult3/RepositoryImplementation.d.ts +332 -332
- package/esm/src/remult3/RepositoryImplementation.js +2122 -2051
- package/esm/src/remult3/__updateEntityBasedOnWhere.d.ts +2 -2
- package/esm/src/remult3/__updateEntityBasedOnWhere.js +24 -24
- package/esm/src/remult3/entity.d.ts +28 -28
- package/esm/src/remult3/entity.js +70 -70
- package/esm/src/remult3/getEntityRef.d.ts +9 -9
- package/esm/src/remult3/getEntityRef.js +27 -27
- package/esm/src/remult3/remult3.d.ts +397 -397
- package/esm/src/remult3/remult3.js +1 -1
- package/esm/src/resultCompoundIdFilter.d.ts +3 -3
- package/esm/src/resultCompoundIdFilter.js +16 -16
- package/esm/src/server-action-info.d.ts +10 -10
- package/esm/src/server-action-info.js +12 -12
- package/esm/src/server-action.d.ts +79 -79
- package/esm/src/server-action.js +397 -387
- package/esm/src/sort.d.ts +16 -16
- package/esm/src/sort.js +105 -104
- package/esm/src/sql-command.d.ts +19 -19
- package/esm/src/sql-command.js +1 -1
- package/esm/src/validators.d.ts +14 -14
- package/esm/src/validators.js +36 -36
- package/esm/src/valueConverters.d.ts +13 -13
- package/esm/src/valueConverters.js +210 -210
- package/esm/urlBuilder.d.ts +6 -6
- package/esm/urlBuilder.js +20 -19
- package/graphql.d.ts +14 -14
- package/graphql.js +953 -953
- package/index.d.ts +31 -31
- package/index.js +67 -67
- package/inputTypes.d.ts +9 -9
- package/inputTypes.js +16 -16
- package/live-query/data-provider-live-query-storage.d.ts +23 -23
- package/live-query/data-provider-live-query-storage.js +263 -263
- package/myLog.d.ts +1 -1
- package/myLog.js +20 -20
- package/package.json +1 -1
- package/postgres/index.d.ts +2 -2
- package/postgres/index.js +5 -5
- package/postgres/postgres-data-provider.d.ts +36 -36
- package/postgres/postgres-data-provider.js +191 -191
- package/postgres/schema-builder.d.ts +19 -19
- package/postgres/schema-builder.js +369 -369
- package/remult-express.d.ts +9 -9
- package/remult-express.js +34 -33
- package/remult-fastify.d.ts +6 -6
- package/remult-fastify.js +79 -79
- package/remult-fresh.d.ts +17 -17
- package/remult-fresh.js +41 -41
- package/remult-knex/index.d.ts +30 -30
- package/remult-knex/index.js +917 -915
- package/remult-mongo.d.ts +24 -24
- package/remult-mongo.js +515 -515
- package/remult-next.d.ts +25 -25
- package/remult-next.js +171 -171
- package/remult-sveltekit.d.ts +4 -4
- package/remult-sveltekit.js +110 -110
- package/server/JsonEntityFileStorage.d.ts +11 -11
- package/server/JsonEntityFileStorage.js +35 -35
- package/server/core.d.ts +4 -4
- package/server/core.js +12 -12
- package/server/expressBridge.d.ts +128 -128
- package/server/expressBridge.js +1401 -1402
- package/server/index.d.ts +6 -6
- package/server/index.js +24 -24
- package/server/initAsyncHooks.d.ts +1 -1
- package/server/initAsyncHooks.js +13 -13
- package/server/initDataProvider.d.ts +2 -2
- package/server/initDataProvider.js +26 -26
- package/src/CompoundIdField.d.ts +27 -27
- package/src/CompoundIdField.js +54 -54
- package/src/__EntityValueProvider.d.ts +11 -11
- package/src/__EntityValueProvider.js +2 -2
- package/src/__RowsOfDataForTesting.d.ts +3 -3
- package/src/__RowsOfDataForTesting.js +2 -2
- package/src/buildRestDataProvider.d.ts +31 -31
- package/src/buildRestDataProvider.js +177 -174
- package/src/column-interfaces.d.ts +160 -160
- package/src/column-interfaces.js +11 -11
- package/src/column.d.ts +31 -31
- package/src/column.js +132 -132
- package/src/context.d.ts +134 -134
- package/src/context.js +451 -451
- package/src/data-api.d.ts +38 -38
- package/src/data-api.js +524 -524
- package/src/data-interfaces.d.ts +41 -41
- package/src/data-interfaces.js +16 -16
- package/src/data-providers/array-entity-data-provider.d.ts +22 -22
- package/src/data-providers/array-entity-data-provider.js +364 -364
- package/src/data-providers/in-memory-database.d.ts +9 -9
- package/src/data-providers/in-memory-database.js +33 -33
- package/src/data-providers/json-data-provider.d.ts +12 -12
- package/src/data-providers/json-data-provider.js +106 -106
- package/src/data-providers/rest-data-provider.d.ts +39 -39
- package/src/data-providers/rest-data-provider.js +388 -388
- package/src/data-providers/sql-database.d.ts +33 -33
- package/src/data-providers/sql-database.js +653 -653
- package/src/data-providers/web-sql-data-provider.d.ts +21 -21
- package/src/data-providers/web-sql-data-provider.js +229 -229
- package/src/entity.d.ts +95 -95
- package/src/entity.js +2 -2
- package/src/filter/filter-consumer-bridge-to-sql-request.d.ts +50 -50
- package/src/filter/filter-consumer-bridge-to-sql-request.js +307 -307
- package/src/filter/filter-interfaces.d.ts +86 -86
- package/src/filter/filter-interfaces.js +693 -685
- package/src/live-query/LiveQueryClient.d.ts +1 -1
- package/src/live-query/LiveQueryClient.js +293 -293
- package/src/live-query/SseSubscriptionClient.d.ts +5 -5
- package/src/live-query/SseSubscriptionClient.js +154 -154
- package/src/live-query/SubscriptionChannel.d.ts +41 -41
- package/src/live-query/SubscriptionChannel.js +189 -189
- package/src/live-query/SubscriptionServer.d.ts +38 -38
- package/src/live-query/SubscriptionServer.js +264 -264
- package/src/remult-proxy.d.ts +2 -2
- package/src/remult-proxy.js +307 -307
- package/src/remult3/DecoratorReplacer.d.ts +10 -10
- package/src/remult3/DecoratorReplacer.js +24 -24
- package/src/remult3/RepositoryImplementation.d.ts +332 -332
- package/src/remult3/RepositoryImplementation.js +3391 -3373
- package/src/remult3/__updateEntityBasedOnWhere.d.ts +2 -2
- package/src/remult3/__updateEntityBasedOnWhere.js +28 -28
- package/src/remult3/entity.d.ts +28 -28
- package/src/remult3/entity.js +88 -88
- package/src/remult3/getEntityRef.d.ts +9 -9
- package/src/remult3/getEntityRef.js +35 -35
- package/src/remult3/remult3.d.ts +397 -397
- package/src/remult3/remult3.js +2 -2
- package/src/resultCompoundIdFilter.d.ts +3 -3
- package/src/resultCompoundIdFilter.js +20 -20
- package/src/server-action-info.d.ts +10 -10
- package/src/server-action-info.js +15 -15
- package/src/server-action.d.ts +79 -79
- package/src/server-action.js +632 -632
- package/src/sort.d.ts +16 -16
- package/src/sort.js +161 -161
- package/src/sql-command.d.ts +19 -19
- package/src/sql-command.js +2 -2
- package/src/validators.d.ts +14 -14
- package/src/validators.js +71 -69
- package/src/valueConverters.d.ts +13 -13
- package/src/valueConverters.js +213 -213
- package/urlBuilder.d.ts +6 -6
- package/urlBuilder.js +25 -25
package/esm/remult-knex/index.js
CHANGED
|
@@ -1,460 +1,466 @@
|
|
|
1
|
-
import { allEntities } from '../src/context';
|
|
2
|
-
import { dbNamesOf, isDbReadonly, } from '../src/filter/filter-consumer-bridge-to-sql-request';
|
|
3
|
-
import { customDatabaseFilterToken, Filter, } from '../src/filter/filter-interfaces';
|
|
4
|
-
import { CompoundIdField } from '../src/CompoundIdField';
|
|
5
|
-
import { remult as remultContext } from '../src/remult-proxy';
|
|
6
|
-
import { getRepository, isAutoIncrement, } from '../src/remult3/RepositoryImplementation';
|
|
7
|
-
import { Sort } from '../src/sort';
|
|
8
|
-
import { ValueConverters } from '../src/valueConverters';
|
|
9
|
-
import { resultCompoundIdFilter as resultCompoundIdFilter } from '../src/resultCompoundIdFilter';
|
|
10
|
-
export class KnexDataProvider {
|
|
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
|
-
await t
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
b
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const
|
|
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
|
-
await this.
|
|
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
|
-
let result = await insert
|
|
203
|
-
newId = result[0]
|
|
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
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
this.
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
let
|
|
361
|
-
if (
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
let c = b.
|
|
401
|
-
if (!x.allowNull) {
|
|
402
|
-
c.defaultTo(0).notNullable();
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
else
|
|
406
|
-
b.
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
return result;
|
|
460
|
-
}
|
|
1
|
+
import { allEntities } from '../src/context';
|
|
2
|
+
import { dbNamesOf, isDbReadonly, } from '../src/filter/filter-consumer-bridge-to-sql-request';
|
|
3
|
+
import { customDatabaseFilterToken, Filter, } from '../src/filter/filter-interfaces';
|
|
4
|
+
import { CompoundIdField } from '../src/CompoundIdField';
|
|
5
|
+
import { remult as remultContext } from '../src/remult-proxy';
|
|
6
|
+
import { getRepository, isAutoIncrement, } from '../src/remult3/RepositoryImplementation';
|
|
7
|
+
import { Sort } from '../src/sort';
|
|
8
|
+
import { ValueConverters } from '../src/valueConverters';
|
|
9
|
+
import { resultCompoundIdFilter as resultCompoundIdFilter } from '../src/resultCompoundIdFilter';
|
|
10
|
+
export class KnexDataProvider {
|
|
11
|
+
knex;
|
|
12
|
+
constructor(knex) {
|
|
13
|
+
this.knex = knex;
|
|
14
|
+
}
|
|
15
|
+
static getDb(remult) {
|
|
16
|
+
const r = (remult || remultContext).dataProvider;
|
|
17
|
+
if (!r.knex)
|
|
18
|
+
throw 'the data provider is not an KnexDataProvider';
|
|
19
|
+
return r.knex;
|
|
20
|
+
}
|
|
21
|
+
getEntityDataProvider(entity) {
|
|
22
|
+
if (!supportsJson(this.knex))
|
|
23
|
+
for (const f of entity.fields.toArray()) {
|
|
24
|
+
if (f.valueConverter.fieldTypeInDb === 'json') {
|
|
25
|
+
//@ts-ignore
|
|
26
|
+
f.valueConverter = {
|
|
27
|
+
...f.valueConverter,
|
|
28
|
+
toDb: ValueConverters.JsonString.toDb,
|
|
29
|
+
fromDb: ValueConverters.JsonString.fromDb,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return new KnexEntityDataProvider(entity, this.knex);
|
|
34
|
+
}
|
|
35
|
+
async transaction(action) {
|
|
36
|
+
let t = await this.knex.transaction();
|
|
37
|
+
try {
|
|
38
|
+
await action(new KnexDataProvider(t));
|
|
39
|
+
await t.commit();
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
await t.rollback();
|
|
43
|
+
throw err;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
static rawFilter(build) {
|
|
47
|
+
return {
|
|
48
|
+
[customDatabaseFilterToken]: {
|
|
49
|
+
buildKnex: build,
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
static async filterToRaw(entity, condition) {
|
|
54
|
+
const repo = getRepository(entity);
|
|
55
|
+
var b = new FilterConsumerBridgeToKnexRequest(await dbNamesOf(repo.metadata));
|
|
56
|
+
b._addWhere = false;
|
|
57
|
+
await (await repo.translateWhereToFilter(condition)).__applyToConsumer(b);
|
|
58
|
+
let r = await b.resolveWhere();
|
|
59
|
+
return (knex) => r.forEach((y) => y(knex));
|
|
60
|
+
}
|
|
61
|
+
isProxy;
|
|
62
|
+
async ensureSchema(entities) {
|
|
63
|
+
var sb = new KnexSchemaBuilder(this.knex);
|
|
64
|
+
await sb.ensureSchema(entities);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
class KnexEntityDataProvider {
|
|
68
|
+
entity;
|
|
69
|
+
knex;
|
|
70
|
+
constructor(entity, knex) {
|
|
71
|
+
this.entity = entity;
|
|
72
|
+
this.knex = knex;
|
|
73
|
+
}
|
|
74
|
+
async count(where) {
|
|
75
|
+
const e = await this.init();
|
|
76
|
+
const br = new FilterConsumerBridgeToKnexRequest(e);
|
|
77
|
+
where.__applyToConsumer(br);
|
|
78
|
+
let r = await br.resolveWhere();
|
|
79
|
+
const result = await this.knex(e.$entityName)
|
|
80
|
+
.count()
|
|
81
|
+
.where((b) => r.forEach((w) => w(b)));
|
|
82
|
+
var row = result[0];
|
|
83
|
+
for (const key in row) {
|
|
84
|
+
if (Object.prototype.hasOwnProperty.call(row, key)) {
|
|
85
|
+
const element = row[key];
|
|
86
|
+
return +element;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
async find(options) {
|
|
91
|
+
const e = await this.init();
|
|
92
|
+
let cols = [];
|
|
93
|
+
let colKeys = [];
|
|
94
|
+
for (const x of this.entity.fields) {
|
|
95
|
+
if (x.isServerExpression) {
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
cols.push(e.$dbNameOf(x));
|
|
99
|
+
colKeys.push(x);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
let query = this.knex(e.$entityName).select(cols);
|
|
103
|
+
if (options?.where) {
|
|
104
|
+
const br = new FilterConsumerBridgeToKnexRequest(e);
|
|
105
|
+
options.where.__applyToConsumer(br);
|
|
106
|
+
let r = await br.resolveWhere();
|
|
107
|
+
query.where((b) => r.forEach((y) => y(b)));
|
|
108
|
+
}
|
|
109
|
+
if (!options.orderBy) {
|
|
110
|
+
options.orderBy = Sort.createUniqueSort(this.entity, new Sort());
|
|
111
|
+
}
|
|
112
|
+
if (options.orderBy) {
|
|
113
|
+
query = query.orderBy(options.orderBy.Segments.map((s) => ({
|
|
114
|
+
column: e.$dbNameOf(s.field),
|
|
115
|
+
order: s.isDescending ? 'desc' : 'asc',
|
|
116
|
+
})));
|
|
117
|
+
}
|
|
118
|
+
if (options.limit) {
|
|
119
|
+
query = query.limit(options.limit);
|
|
120
|
+
if (options.page)
|
|
121
|
+
query = query.offset((options.page - 1) * options.limit);
|
|
122
|
+
}
|
|
123
|
+
const r = await query;
|
|
124
|
+
return r.map((y) => {
|
|
125
|
+
let result = {};
|
|
126
|
+
let i = 0;
|
|
127
|
+
for (let m in y) {
|
|
128
|
+
let field = colKeys[i++];
|
|
129
|
+
try {
|
|
130
|
+
result[field.key] = field.valueConverter.fromDb(y[m]);
|
|
131
|
+
}
|
|
132
|
+
catch (err) {
|
|
133
|
+
throw new Error('Failed to load from db:' + field.key + '\r\n' + err);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return result;
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
async init() {
|
|
140
|
+
return (await dbNamesOf(this.entity));
|
|
141
|
+
}
|
|
142
|
+
async update(id, data) {
|
|
143
|
+
const e = await this.init();
|
|
144
|
+
let f = new FilterConsumerBridgeToKnexRequest(e);
|
|
145
|
+
Filter.fromEntityFilter(this.entity, this.entity.idMetadata.getIdFilter(id)).__applyToConsumer(f);
|
|
146
|
+
let resultFilter = this.entity.idMetadata.getIdFilter(id);
|
|
147
|
+
if (data.id != undefined)
|
|
148
|
+
resultFilter = this.entity.idMetadata.getIdFilter(data.id);
|
|
149
|
+
let updateObject = {};
|
|
150
|
+
for (const x of this.entity.fields) {
|
|
151
|
+
if (isDbReadonly(x, e)) {
|
|
152
|
+
}
|
|
153
|
+
else if (data[x.key] !== undefined) {
|
|
154
|
+
let v = translateValueAndHandleArrayAndHandleArray(x, data[x.key]);
|
|
155
|
+
if (v !== undefined) {
|
|
156
|
+
let key = await e.$dbNameOf(x);
|
|
157
|
+
updateObject[key] = v;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
let where = await f.resolveWhere();
|
|
162
|
+
await this.knex(e.$entityName)
|
|
163
|
+
.update(updateObject)
|
|
164
|
+
.where((b) => where.forEach((w) => w(b)));
|
|
165
|
+
return this.find({
|
|
166
|
+
where: Filter.fromEntityFilter(this.entity, resultFilter),
|
|
167
|
+
}).then((y) => y[0]);
|
|
168
|
+
}
|
|
169
|
+
async delete(id) {
|
|
170
|
+
const e = await this.init();
|
|
171
|
+
let f = new FilterConsumerBridgeToKnexRequest(e);
|
|
172
|
+
Filter.fromEntityFilter(this.entity, this.entity.idMetadata.getIdFilter(id)).__applyToConsumer(f);
|
|
173
|
+
let where = await f.resolveWhere();
|
|
174
|
+
await this.knex(e.$entityName)
|
|
175
|
+
.delete()
|
|
176
|
+
.where((b) => where.forEach((w) => w(b)));
|
|
177
|
+
}
|
|
178
|
+
async insert(data) {
|
|
179
|
+
const e = await this.init();
|
|
180
|
+
let resultFilter;
|
|
181
|
+
if (this.entity.idMetadata.field instanceof CompoundIdField)
|
|
182
|
+
resultFilter = resultCompoundIdFilter(this.entity.idMetadata.field, undefined, data);
|
|
183
|
+
else
|
|
184
|
+
resultFilter = Filter.fromEntityFilter(this.entity, this.entity.idMetadata.getIdFilter(data[this.entity.idMetadata.field.key]));
|
|
185
|
+
let insertObject = {};
|
|
186
|
+
for (const x of this.entity.fields) {
|
|
187
|
+
if (isDbReadonly(x, e)) {
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
let v = translateValueAndHandleArrayAndHandleArray(x, data[x.key]);
|
|
191
|
+
if (v != undefined) {
|
|
192
|
+
let key = await e.$dbNameOf(x);
|
|
193
|
+
insertObject[key] = v;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
let insert = this.knex(e.$entityName).insert(insertObject);
|
|
198
|
+
if (isAutoIncrement(this.entity.idMetadata.field)) {
|
|
199
|
+
let newId;
|
|
200
|
+
if (this.knex.client.config.client === 'mysql2' ||
|
|
201
|
+
this.knex.client.config.client === 'mysql') {
|
|
202
|
+
let result = await insert;
|
|
203
|
+
newId = result[0];
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
let result = await insert.returning(this.entity.idMetadata.field.key);
|
|
207
|
+
newId = result[0].id;
|
|
208
|
+
}
|
|
209
|
+
resultFilter = new Filter((x) => x.isEqualTo(this.entity.idMetadata.field, newId));
|
|
210
|
+
}
|
|
211
|
+
else
|
|
212
|
+
await insert;
|
|
213
|
+
return this.find({ where: resultFilter }).then((y) => {
|
|
214
|
+
return y[0];
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
class FilterConsumerBridgeToKnexRequest {
|
|
219
|
+
nameProvider;
|
|
220
|
+
_addWhere = true;
|
|
221
|
+
promises = [];
|
|
222
|
+
result = [];
|
|
223
|
+
async resolveWhere() {
|
|
224
|
+
while (this.promises.length > 0) {
|
|
225
|
+
let p = this.promises;
|
|
226
|
+
this.promises = [];
|
|
227
|
+
for (const pr of p) {
|
|
228
|
+
await pr;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return this.result;
|
|
232
|
+
}
|
|
233
|
+
constructor(nameProvider) {
|
|
234
|
+
this.nameProvider = nameProvider;
|
|
235
|
+
}
|
|
236
|
+
custom(key, customItem) {
|
|
237
|
+
throw new Error('Custom filter should be translated before it gets here');
|
|
238
|
+
}
|
|
239
|
+
or(orElements) {
|
|
240
|
+
this.promises.push((async () => {
|
|
241
|
+
const result = [];
|
|
242
|
+
for (const element of orElements) {
|
|
243
|
+
let f = new FilterConsumerBridgeToKnexRequest(this.nameProvider);
|
|
244
|
+
f._addWhere = false;
|
|
245
|
+
element.__applyToConsumer(f);
|
|
246
|
+
let where = await f.resolveWhere();
|
|
247
|
+
if (where.length > 0) {
|
|
248
|
+
result.push((b) => {
|
|
249
|
+
b.orWhere((b) => {
|
|
250
|
+
where.forEach((x) => x(b));
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
else
|
|
255
|
+
return; //empty or means all rows
|
|
256
|
+
}
|
|
257
|
+
if (result.length > 0) {
|
|
258
|
+
this.result.push((b) => b.where((x) => result.find((y) => y(x))));
|
|
259
|
+
}
|
|
260
|
+
})());
|
|
261
|
+
}
|
|
262
|
+
isNull(col) {
|
|
263
|
+
this.result.push((b) => b.whereNull(this.nameProvider.$dbNameOf(col)));
|
|
264
|
+
}
|
|
265
|
+
isNotNull(col) {
|
|
266
|
+
this.result.push((b) => b.whereNotNull(this.nameProvider.$dbNameOf(col)));
|
|
267
|
+
}
|
|
268
|
+
isIn(col, val) {
|
|
269
|
+
this.result.push((knex) => knex.whereIn(this.nameProvider.$dbNameOf(col), val.map((x) => translateValueAndHandleArrayAndHandleArray(col, x))));
|
|
270
|
+
}
|
|
271
|
+
isEqualTo(col, val) {
|
|
272
|
+
this.add(col, val, '=');
|
|
273
|
+
}
|
|
274
|
+
isDifferentFrom(col, val) {
|
|
275
|
+
this.add(col, val, '<>');
|
|
276
|
+
}
|
|
277
|
+
isGreaterOrEqualTo(col, val) {
|
|
278
|
+
this.add(col, val, '>=');
|
|
279
|
+
}
|
|
280
|
+
isGreaterThan(col, val) {
|
|
281
|
+
this.add(col, val, '>');
|
|
282
|
+
}
|
|
283
|
+
isLessOrEqualTo(col, val) {
|
|
284
|
+
this.add(col, val, '<=');
|
|
285
|
+
}
|
|
286
|
+
isLessThan(col, val) {
|
|
287
|
+
this.add(col, val, '<');
|
|
288
|
+
}
|
|
289
|
+
containsCaseInsensitive(col, val) {
|
|
290
|
+
this.result.push((b) => b.whereRaw('lower (' +
|
|
291
|
+
b.client.ref(this.nameProvider.$dbNameOf(col)) +
|
|
292
|
+
") like lower ('%" +
|
|
293
|
+
val.replace(/'/g, "''") +
|
|
294
|
+
"%')"));
|
|
295
|
+
this.promises.push((async () => { })());
|
|
296
|
+
}
|
|
297
|
+
add(col, val, operator) {
|
|
298
|
+
this.result.push((b) => b.where(this.nameProvider.$dbNameOf(col), operator, translateValueAndHandleArrayAndHandleArray(col, val)));
|
|
299
|
+
}
|
|
300
|
+
databaseCustom(databaseCustom) {
|
|
301
|
+
this.promises.push((async () => {
|
|
302
|
+
if (databaseCustom?.buildKnex) {
|
|
303
|
+
this.result.push(await databaseCustom.buildKnex());
|
|
304
|
+
}
|
|
305
|
+
})());
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
export class KnexSchemaBuilder {
|
|
309
|
+
knex;
|
|
310
|
+
//@internal
|
|
311
|
+
static logToConsole = true;
|
|
312
|
+
async verifyStructureOfAllEntities(remult) {
|
|
313
|
+
if (!remult)
|
|
314
|
+
remult = remultContext;
|
|
315
|
+
const entities = allEntities.map((x) => remult.repo(x).metadata);
|
|
316
|
+
this.ensureSchema(entities);
|
|
317
|
+
}
|
|
318
|
+
async ensureSchema(entities) {
|
|
319
|
+
for (const entity of entities) {
|
|
320
|
+
let e = await dbNamesOf(entity);
|
|
321
|
+
try {
|
|
322
|
+
if (!entity.options.sqlExpression) {
|
|
323
|
+
if (e.$entityName.toLowerCase().indexOf('from ') < 0) {
|
|
324
|
+
await this.createIfNotExist(entity);
|
|
325
|
+
await this.verifyAllColumns(entity);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
catch (err) {
|
|
330
|
+
console.error('failed ensure schema of ' + e.$entityName + ' ', err);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
async createIfNotExist(entity) {
|
|
335
|
+
const e = await dbNamesOf(entity);
|
|
336
|
+
if (!(await this.knex.schema.hasTable(e.$entityName))) {
|
|
337
|
+
let cols = new Map();
|
|
338
|
+
for (const f of entity.fields) {
|
|
339
|
+
cols.set(f, {
|
|
340
|
+
name: e.$dbNameOf(f),
|
|
341
|
+
readonly: isDbReadonly(f, e),
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
await logSql(this.knex.schema.createTable(e.$entityName, (b) => {
|
|
345
|
+
for (const x of entity.fields) {
|
|
346
|
+
if (!cols.get(x).readonly || isAutoIncrement(x)) {
|
|
347
|
+
if (isAutoIncrement(x))
|
|
348
|
+
b.increments(cols.get(x).name);
|
|
349
|
+
else {
|
|
350
|
+
buildColumn(x, cols.get(x).name, b, supportsJson(this.knex));
|
|
351
|
+
if (x == entity.idMetadata.field)
|
|
352
|
+
b.primary([cols.get(x).name]);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}));
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
async addColumnIfNotExist(entity, c) {
|
|
360
|
+
let e = await dbNamesOf(entity);
|
|
361
|
+
if (isDbReadonly(c(entity), e))
|
|
362
|
+
return;
|
|
363
|
+
let col = c(entity);
|
|
364
|
+
let colName = e.$dbNameOf(col);
|
|
365
|
+
if (!(await this.knex.schema.hasColumn(e.$entityName, colName))) {
|
|
366
|
+
await logSql(this.knex.schema.alterTable(e.$entityName, (b) => {
|
|
367
|
+
buildColumn(col, colName, b, supportsJson(this.knex));
|
|
368
|
+
}));
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
async verifyAllColumns(entity) {
|
|
372
|
+
let e = await dbNamesOf(entity);
|
|
373
|
+
try {
|
|
374
|
+
for (const col of entity.fields.toArray()) {
|
|
375
|
+
if (!isDbReadonly(col, e)) {
|
|
376
|
+
await this.addColumnIfNotExist(entity, () => col);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
catch (err) {
|
|
381
|
+
console.error(err);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
additionalWhere = '';
|
|
385
|
+
constructor(knex) {
|
|
386
|
+
this.knex = knex;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
function supportsJson(knex) {
|
|
390
|
+
const client = knex.client.config.client;
|
|
391
|
+
if (client?.includes('sqlite3') ||
|
|
392
|
+
client?.includes('mssql') ||
|
|
393
|
+
client?.includes('mysql'))
|
|
394
|
+
return false;
|
|
395
|
+
return true;
|
|
396
|
+
}
|
|
397
|
+
export function buildColumn(x, dbName, b, supportsJson = true) {
|
|
398
|
+
if (x.valueType == Number) {
|
|
399
|
+
if (!x.valueConverter.fieldTypeInDb) {
|
|
400
|
+
let c = b.decimal(dbName);
|
|
401
|
+
if (!x.allowNull) {
|
|
402
|
+
c.defaultTo(0).notNullable();
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
else if (x.valueConverter.fieldTypeInDb == 'integer') {
|
|
406
|
+
let c = b.integer(dbName);
|
|
407
|
+
if (!x.allowNull) {
|
|
408
|
+
c.defaultTo(0).notNullable();
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
else
|
|
412
|
+
b.specificType(dbName, x.valueConverter.fieldTypeInDb);
|
|
413
|
+
}
|
|
414
|
+
else if (x.valueType == Date) {
|
|
415
|
+
if (!x.valueConverter.fieldTypeInDb)
|
|
416
|
+
if (x.valueConverter == ValueConverters.DateOnly)
|
|
417
|
+
b.date(dbName);
|
|
418
|
+
else
|
|
419
|
+
b.dateTime(dbName);
|
|
420
|
+
else if (x.valueConverter.fieldTypeInDb == 'date')
|
|
421
|
+
b.date(dbName);
|
|
422
|
+
else
|
|
423
|
+
b.specificType(dbName, x.valueConverter.fieldTypeInDb);
|
|
424
|
+
}
|
|
425
|
+
else if (x.valueType == Boolean) {
|
|
426
|
+
let c = b.boolean(dbName);
|
|
427
|
+
if (!x.allowNull)
|
|
428
|
+
c.defaultTo(false).notNullable();
|
|
429
|
+
}
|
|
430
|
+
else if (x.valueConverter.fieldTypeInDb) {
|
|
431
|
+
if (x.valueConverter.fieldTypeInDb == 'integer') {
|
|
432
|
+
let c = b.integer(dbName);
|
|
433
|
+
if (!x.allowNull) {
|
|
434
|
+
c.defaultTo(0).notNullable();
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
else if (x.valueConverter.fieldTypeInDb == 'json')
|
|
438
|
+
if (supportsJson)
|
|
439
|
+
b.json(dbName);
|
|
440
|
+
else
|
|
441
|
+
b.text(dbName);
|
|
442
|
+
else
|
|
443
|
+
b.specificType(dbName, x.valueConverter.fieldTypeInDb);
|
|
444
|
+
}
|
|
445
|
+
else {
|
|
446
|
+
let c = b.string(dbName, x.options.maxLength);
|
|
447
|
+
if (!x.allowNull)
|
|
448
|
+
c.defaultTo('').notNullable();
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
function logSql(who) {
|
|
452
|
+
if (KnexSchemaBuilder.logToConsole)
|
|
453
|
+
console.info(who.toSQL());
|
|
454
|
+
return who;
|
|
455
|
+
}
|
|
456
|
+
export async function createKnexDataProvider(config) {
|
|
457
|
+
let k = (await import('knex')).default(config);
|
|
458
|
+
let result = new KnexDataProvider(k);
|
|
459
|
+
return result;
|
|
460
|
+
}
|
|
461
|
+
function translateValueAndHandleArrayAndHandleArray(field, val) {
|
|
462
|
+
let result = field.valueConverter.toDb(val);
|
|
463
|
+
if (Array.isArray(result))
|
|
464
|
+
return JSON.stringify(result);
|
|
465
|
+
return result;
|
|
466
|
+
}
|