@reventlessdev/reventless-postgres 3.0.0-alpha.4 → 3.0.0-alpha.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/CHANGELOG.md +9 -0
- package/lib/bs/.compiler.log +2 -2
- package/lib/bs/ReventlessPostgres.cmi +0 -0
- package/lib/bs/ReventlessPostgres.cmt +0 -0
- package/lib/bs/ReventlessPostgres.mlmap +1 -0
- package/lib/bs/compiler-info.json +1 -1
- package/lib/bs/src/DcbEventLogStorage_Postgres-ReventlessPostgres.cmi +0 -0
- package/lib/bs/src/DcbEventLogStorage_Postgres-ReventlessPostgres.cmt +0 -0
- package/lib/bs/src/EventLogChangeFeed-ReventlessPostgres.cmi +0 -0
- package/lib/bs/src/EventLogChangeFeed-ReventlessPostgres.cmt +0 -0
- package/lib/bs/src/EventLogStorage_Postgres-ReventlessPostgres.cmi +0 -0
- package/lib/bs/src/EventLogStorage_Postgres-ReventlessPostgres.cmt +0 -0
- package/lib/bs/src/PgChangeFeed-ReventlessPostgres.cmi +0 -0
- package/lib/bs/src/PgChangeFeed-ReventlessPostgres.cmt +0 -0
- package/lib/bs/src/QueryDbStorage_Postgres-ReventlessPostgres.cmi +0 -0
- package/lib/bs/src/QueryDbStorage_Postgres-ReventlessPostgres.cmj +0 -0
- package/lib/bs/src/QueryDbStorage_Postgres-ReventlessPostgres.cmt +0 -0
- package/lib/bs/src/QueryDbStorage_Postgres.ast +0 -0
- package/lib/bs/src/QueryDbStorage_Postgres.res +35 -14
- package/lib/bs/src/QueryDbStorage_Postgres.res.mjs +23 -8
- package/lib/bs/src/QueryEnginePostgres-ReventlessPostgres.cmi +0 -0
- package/lib/bs/src/QueryEnginePostgres-ReventlessPostgres.cmt +0 -0
- package/lib/bs/src/QueryEnginePostgres.ast +0 -0
- package/lib/bs/src/QueryEnginePostgres.res +175 -0
- package/lib/bs/src/QueryEnginePostgres.res.mjs +91 -0
- package/lib/bs/tests/PostgresIntegrationTest-ReventlessPostgres.cmi +0 -0
- package/lib/bs/tests/PostgresIntegrationTest-ReventlessPostgres.cmt +0 -0
- package/lib/bs/tests/QueryEnginePostgresListPageTest-ReventlessPostgres.cmi +0 -0
- package/lib/bs/tests/QueryEnginePostgresListPageTest-ReventlessPostgres.cmj +0 -0
- package/lib/bs/tests/QueryEnginePostgresListPageTest-ReventlessPostgres.cmt +0 -0
- package/lib/bs/tests/QueryEnginePostgresListPageTest.ast +0 -0
- package/lib/bs/tests/QueryEnginePostgresListPageTest.res +236 -0
- package/lib/bs/tests/QueryEnginePostgresListPageTest.res.mjs +325 -0
- package/lib/ocaml/.compiler.log +2 -2
- package/lib/ocaml/DcbEventLogStorage_Postgres-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/DcbEventLogStorage_Postgres-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/EventLogChangeFeed-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/EventLogChangeFeed-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/EventLogStorage_Postgres-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/EventLogStorage_Postgres-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/PgChangeFeed-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/PgChangeFeed-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/PostgresIntegrationTest-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/PostgresIntegrationTest-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/QueryDbStorage_Postgres-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/QueryDbStorage_Postgres-ReventlessPostgres.cmj +0 -0
- package/lib/ocaml/QueryDbStorage_Postgres-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/QueryDbStorage_Postgres.ast +0 -0
- package/lib/ocaml/QueryDbStorage_Postgres.res +35 -14
- package/lib/ocaml/QueryEnginePostgres-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/QueryEnginePostgres-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/QueryEnginePostgres.ast +0 -0
- package/lib/ocaml/QueryEnginePostgres.res +175 -0
- package/lib/ocaml/QueryEnginePostgresListPageTest-ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/QueryEnginePostgresListPageTest-ReventlessPostgres.cmj +0 -0
- package/lib/ocaml/QueryEnginePostgresListPageTest-ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/QueryEnginePostgresListPageTest.ast +0 -0
- package/lib/ocaml/QueryEnginePostgresListPageTest.res +236 -0
- package/lib/ocaml/ReventlessPostgres.cmi +0 -0
- package/lib/ocaml/ReventlessPostgres.cmt +0 -0
- package/lib/ocaml/ReventlessPostgres.mlmap +1 -0
- package/package.json +7 -7
- package/src/QueryDbStorage_Postgres.res +35 -14
- package/src/QueryDbStorage_Postgres.res.mjs +23 -8
- package/src/QueryEnginePostgres.res +175 -0
- package/src/QueryEnginePostgres.res.mjs +91 -0
- package/tests/QueryEnginePostgresListPageTest.res +236 -0
- package/tests/QueryEnginePostgresListPageTest.res.mjs +325 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,15 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# 3.0.0-alpha.5 (2026-07-06)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **reventless-aws:** classic EventLog Postgres deploy-time wiring + relay (B1 vertical) ([8235ba4](https://github.com/ReventlessDev/reventless-core/commit/8235ba44e506f7094d17251405c6a05c39789805))
|
|
11
|
+
* **reventless-aws:** Postgres QueryDb storage vertical (B3.1) ([51a7993](https://github.com/ReventlessDev/reventless-core/commit/51a79934c1d9f59bb6f61233a90651d5eadf9f4e))
|
|
12
|
+
* **reventless-postgres:** QueryEnginePostgres list/index/byIds resolver push-downs (B3.2a-1) ([8cb09e4](https://github.com/ReventlessDev/reventless-core/commit/8cb09e40cffa9698a251f1ee3fb17b016c4f8b07))
|
|
13
|
+
|
|
14
|
+
|
|
6
15
|
# 3.0.0-alpha.4 (2026-07-05)
|
|
7
16
|
|
|
8
17
|
### Features
|
package/lib/bs/.compiler.log
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#Start(
|
|
2
|
-
#Done(
|
|
1
|
+
#Start(1783298008858)
|
|
2
|
+
#Done(1783298010813)
|
|
Binary file
|
|
Binary file
|
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
"bsc_hash": "75e3a59c95cc953608fd3dd6ea6ed68141bba4414a20a52f114261b8a48385fa",
|
|
5
5
|
"rescript_config_hash": "48ea15db3d741cf15a2ff49dd0b47d86badf2b548ecb3859a896faf1e3a82a15",
|
|
6
6
|
"runtime_path": "/home/runner/work/reventless-core/reventless-core/node_modules/@rescript/runtime",
|
|
7
|
-
"generated_at": "
|
|
7
|
+
"generated_at": "1783298010821"
|
|
8
8
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -97,23 +97,36 @@ let withId = (item: JSON.t, partitionKey: string): JSON.t =>
|
|
|
97
97
|
| _ => item
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
|
|
100
|
+
// Plain operation set for a read model's qdb table. Exposed separately from
|
|
101
|
+
// `makeStorage` so the deployed-Lambda runtime (reventless-aws) can bind ops
|
|
102
|
+
// without touching the Pulumi-shaped `storage` record.
|
|
103
|
+
let makeOperations = (
|
|
101
104
|
~pool: PgDriver.pool,
|
|
102
105
|
~name: string,
|
|
103
106
|
~indexes: array<indexConfig>,
|
|
104
107
|
~subIdField: option<string>,
|
|
105
|
-
): QueryDb_Adapter.
|
|
108
|
+
): QueryDb_Adapter.operations => {
|
|
106
109
|
let table = tableName(name)
|
|
107
|
-
// Schema setup is async
|
|
108
|
-
//
|
|
109
|
-
//
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
110
|
+
// Schema setup is async and LAZY: kicked off by the first operation, not at
|
|
111
|
+
// construction. A deploy-time caller may build the ops on a machine that
|
|
112
|
+
// cannot reach the database (VPC-private RDS) — only the runtime, which
|
|
113
|
+
// actually calls an operation, may open a connection. Subsequent operations
|
|
114
|
+
// await the same promise (table + index creation runs exactly once).
|
|
115
|
+
let readyRef: ref<option<promise<unit>>> = ref(None)
|
|
116
|
+
let ready = () =>
|
|
117
|
+
switch readyRef.contents {
|
|
118
|
+
| Some(p) => p
|
|
119
|
+
| None =>
|
|
120
|
+
let p = {
|
|
121
|
+
open Promise
|
|
122
|
+
ensureTable(~pool, ~table)->then(() => ensureIndexes(~pool, ~table, ~indexes))
|
|
123
|
+
}
|
|
124
|
+
readyRef := Some(p)
|
|
125
|
+
p
|
|
126
|
+
}
|
|
114
127
|
|
|
115
128
|
let rowsFor = async (id: string): array<JSON.t> => {
|
|
116
|
-
await ready
|
|
129
|
+
await ready()
|
|
117
130
|
(await pool->PgDriver.query(
|
|
118
131
|
`SELECT item FROM ${table} WHERE partition_key = $1 AND ${notExpiredClause} ORDER BY sub_key ASC`,
|
|
119
132
|
[JSON.Encode.string(id)],
|
|
@@ -121,7 +134,7 @@ let makeStorage = (
|
|
|
121
134
|
}
|
|
122
135
|
|
|
123
136
|
let saveOne = async (id: string, state: JSON.t, ttl: option<int>) => {
|
|
124
|
-
await ready
|
|
137
|
+
await ready()
|
|
125
138
|
let subKey = computeSubKey(state, subIdField)
|
|
126
139
|
let expiresAt = switch ttl {
|
|
127
140
|
| Some(t) => JSON.Encode.int(t)
|
|
@@ -167,7 +180,7 @@ let makeStorage = (
|
|
|
167
180
|
// Mirror DynamoDB's `ADD #field :inc`: read the counter on the partition item
|
|
168
181
|
// (counters are single-state, sub_key=""), add inc, upsert, return NEW total.
|
|
169
182
|
let count: QueryDb.count<string> = async (id, fieldName, inc) => {
|
|
170
|
-
await ready
|
|
183
|
+
await ready()
|
|
171
184
|
let existing = (await rowsFor(id))->Array.get(0)->Option.flatMap(JSON.Decode.object)
|
|
172
185
|
let current =
|
|
173
186
|
existing
|
|
@@ -186,7 +199,7 @@ let makeStorage = (
|
|
|
186
199
|
}
|
|
187
200
|
|
|
188
201
|
let delete: QueryDb.delete<string> = async (id, subIdOpt) => {
|
|
189
|
-
await ready
|
|
202
|
+
await ready()
|
|
190
203
|
let _ = switch subIdOpt {
|
|
191
204
|
| None =>
|
|
192
205
|
await pool->PgDriver.query(
|
|
@@ -219,11 +232,19 @@ let makeStorage = (
|
|
|
219
232
|
delete,
|
|
220
233
|
deleteBatch,
|
|
221
234
|
}
|
|
235
|
+
ops
|
|
236
|
+
}
|
|
222
237
|
|
|
238
|
+
let makeStorage = (
|
|
239
|
+
~pool: PgDriver.pool,
|
|
240
|
+
~name: string,
|
|
241
|
+
~indexes: array<indexConfig>,
|
|
242
|
+
~subIdField: option<string>,
|
|
243
|
+
): QueryDb_Adapter.storage => {
|
|
223
244
|
{
|
|
224
245
|
QueryDb_Adapter.resources: [],
|
|
225
246
|
dataSourceName: ""->Pulumi.Output.make,
|
|
226
|
-
operations: Pulumi.Output.make(
|
|
247
|
+
operations: Pulumi.Output.make(makeOperations(~pool, ~name, ~indexes, ~subIdField)),
|
|
227
248
|
}
|
|
228
249
|
}
|
|
229
250
|
|
|
@@ -102,15 +102,26 @@ function withId(item, partitionKey) {
|
|
|
102
102
|
return copy;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
function
|
|
105
|
+
function makeOperations(pool, name, indexes, subIdField) {
|
|
106
106
|
let table = tableName(name);
|
|
107
|
-
let
|
|
107
|
+
let readyRef = {
|
|
108
|
+
contents: undefined
|
|
109
|
+
};
|
|
110
|
+
let ready = () => {
|
|
111
|
+
let p = readyRef.contents;
|
|
112
|
+
if (p !== undefined) {
|
|
113
|
+
return p;
|
|
114
|
+
}
|
|
115
|
+
let p$1 = ensureTable(pool, table).then(() => ensureIndexes(pool, table, indexes));
|
|
116
|
+
readyRef.contents = p$1;
|
|
117
|
+
return p$1;
|
|
118
|
+
};
|
|
108
119
|
let rowsFor = async id => {
|
|
109
|
-
await ready;
|
|
120
|
+
await ready();
|
|
110
121
|
return (await PgDriver$ReventlessPostgres.query(pool, `SELECT item FROM ` + table + ` WHERE partition_key = $1 AND ` + notExpiredClause + ` ORDER BY sub_key ASC`, [id])).map(decodeItem);
|
|
111
122
|
};
|
|
112
123
|
let saveOne = async (id, state, ttl) => {
|
|
113
|
-
await ready;
|
|
124
|
+
await ready();
|
|
114
125
|
let subKey = computeSubKey(state, subIdField);
|
|
115
126
|
let expiresAt = ttl !== undefined ? ttl : null;
|
|
116
127
|
await PgDriver$ReventlessPostgres.query(pool, `INSERT INTO ` + table + `(partition_key, sub_key, item, expires_at)
|
|
@@ -146,7 +157,7 @@ function makeStorage(pool, name, indexes, subIdField) {
|
|
|
146
157
|
};
|
|
147
158
|
};
|
|
148
159
|
let count = async (id, fieldName, inc) => {
|
|
149
|
-
await ready;
|
|
160
|
+
await ready();
|
|
150
161
|
let existing = Stdlib_Option.flatMap((await rowsFor(id))[0], Stdlib_JSON.Decode.object);
|
|
151
162
|
let current = Stdlib_Option.mapOr(Stdlib_Option.flatMap(Stdlib_Option.flatMap(existing, o => o[fieldName]), Stdlib_JSON.Decode.float), 0, prim => prim | 0);
|
|
152
163
|
let next = current + inc | 0;
|
|
@@ -160,7 +171,7 @@ function makeStorage(pool, name, indexes, subIdField) {
|
|
|
160
171
|
};
|
|
161
172
|
};
|
|
162
173
|
let $$delete = async (id, subIdOpt) => {
|
|
163
|
-
await ready;
|
|
174
|
+
await ready();
|
|
164
175
|
if (subIdOpt !== undefined) {
|
|
165
176
|
await PgDriver$ReventlessPostgres.query(pool, `DELETE FROM ` + table + ` WHERE partition_key = $1 AND sub_key = $2`, [
|
|
166
177
|
id,
|
|
@@ -184,7 +195,7 @@ function makeStorage(pool, name, indexes, subIdField) {
|
|
|
184
195
|
_0: undefined
|
|
185
196
|
};
|
|
186
197
|
};
|
|
187
|
-
|
|
198
|
+
return {
|
|
188
199
|
load: load,
|
|
189
200
|
loadStream: loadStream,
|
|
190
201
|
save: save,
|
|
@@ -193,10 +204,13 @@ function makeStorage(pool, name, indexes, subIdField) {
|
|
|
193
204
|
delete: $$delete,
|
|
194
205
|
deleteBatch: deleteBatch
|
|
195
206
|
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function makeStorage(pool, name, indexes, subIdField) {
|
|
196
210
|
return {
|
|
197
211
|
resources: [],
|
|
198
212
|
dataSourceName: Pulumi.output(""),
|
|
199
|
-
operations: Pulumi.output(
|
|
213
|
+
operations: Pulumi.output(makeOperations(pool, name, indexes, subIdField))
|
|
200
214
|
};
|
|
201
215
|
}
|
|
202
216
|
|
|
@@ -219,6 +233,7 @@ export {
|
|
|
219
233
|
decodeItem,
|
|
220
234
|
computeSubKey,
|
|
221
235
|
withId,
|
|
236
|
+
makeOperations,
|
|
222
237
|
makeStorage,
|
|
223
238
|
Make,
|
|
224
239
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -122,6 +122,181 @@ module Make = (P: {let pool: PgDriver.pool}) => {
|
|
|
122
122
|
(await P.pool->PgDriver.query(sql, b.params))->Array.map(decodeRow(~withId=true, ...))
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
+
// ---------------------------------------------------------------------------
|
|
126
|
+
// GraphQL resolver push-downs (B3.2). The Postgres resolver Lambda dispatches
|
|
127
|
+
// these; they parallel the SQLite backend's `lookupByField` / `listPage` (the
|
|
128
|
+
// ones registered on LocalBus). All return `id`-carrying items (COALESCE from
|
|
129
|
+
// partition_key), matching the shape `QueryDbListQuery.run` operates over so
|
|
130
|
+
// the connection helpers agree.
|
|
131
|
+
//
|
|
132
|
+
// Text comparisons use `COLLATE "C"` (byte order — memcmp), the Postgres
|
|
133
|
+
// analogue of SQLite's BINARY collation, so cursor/order comparisons match
|
|
134
|
+
// JS string `<` for the ASCII id/status/name fields used as sort/filter keys.
|
|
135
|
+
// ---------------------------------------------------------------------------
|
|
136
|
+
|
|
137
|
+
// Equality lookup on an indexed JSON field — rides the expression index
|
|
138
|
+
// (`ensureIndexes`) instead of scanning. String comparison mirrors the
|
|
139
|
+
// resolver's JS path (which only matched string-typed fields).
|
|
140
|
+
let indexLookup = async (~readModelName, field: string, value: string): array<JSON.t> => {
|
|
141
|
+
let table = QueryDbStorage_Postgres.tableName(readModelName)
|
|
142
|
+
let b = {params: []}
|
|
143
|
+
let sql = `SELECT partition_key, item FROM ${table} WHERE ${col(field)} = ${b->param(
|
|
144
|
+
JSON.Encode.string(value),
|
|
145
|
+
)} AND ${notExpired}`
|
|
146
|
+
(await P.pool->PgDriver.query(sql, b.params))->Array.map(decodeRow(~withId=true, ...))
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Batched-by-ids lookup: BatchGetItem analogue over the projection's own
|
|
150
|
+
// table. Single-key projections only (partition_key = the id). Missing ids
|
|
151
|
+
// drop out of the response (no cardinality preservation), matching
|
|
152
|
+
// BatchGetItem semantics.
|
|
153
|
+
let byIds = async (~readModelName, ids: array<string>): array<JSON.t> => {
|
|
154
|
+
if ids->Array.length == 0 {
|
|
155
|
+
[]
|
|
156
|
+
} else {
|
|
157
|
+
let table = QueryDbStorage_Postgres.tableName(readModelName)
|
|
158
|
+
let b = {params: []}
|
|
159
|
+
let idsJson = JSON.Encode.array(ids->Array.map(JSON.Encode.string))
|
|
160
|
+
let sql = `SELECT partition_key, item FROM ${table} WHERE partition_key = ANY(${b->param(
|
|
161
|
+
idsJson,
|
|
162
|
+
)}::text[]) AND ${notExpired}`
|
|
163
|
+
(await P.pool->PgDriver.query(sql, b.params))->Array.map(decodeRow(~withId=true, ...))
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// COALESCE(item->>'id', partition_key) — the effective id, byte-ordered.
|
|
168
|
+
let idExprC = `COALESCE(item->>'id', partition_key) COLLATE "C"`
|
|
169
|
+
let jsonTextC = (field: string): string => `${col(field)} COLLATE "C"`
|
|
170
|
+
|
|
171
|
+
// Connection-list push-down. Builds `item->>'field'` predicates + keyset
|
|
172
|
+
// WHERE + `ORDER BY … LIMIT pageSize+1` so a page reads only what it returns
|
|
173
|
+
// rather than the whole read model. Reproduces `QueryDbListQuery` semantics
|
|
174
|
+
// exactly for the shapes it handles; returns `None` (→ the resolver Lambda
|
|
175
|
+
// falls back to `scan` + the shared spec) for shapes not bit-exact in SQL:
|
|
176
|
+
// case-insensitive search/searchPrefix, Relay-global-id `ids`, and backward
|
|
177
|
+
// pagination (last/before). Cursor values, edges, and pageInfo are built by
|
|
178
|
+
// the SAME `QueryDbListQuery` helpers the fallback uses, so only the
|
|
179
|
+
// WHERE/ORDER/LIMIT needs to match — the parity harness asserts it does
|
|
180
|
+
// (SQLite ≡ Postgres ≡ spec). Mirrors QueryDbStorage_Sqlite.listPage.
|
|
181
|
+
let listPage = async (
|
|
182
|
+
~readModelName,
|
|
183
|
+
~argsDict: dict<JSON.t>,
|
|
184
|
+
~capability: GraphQL_FragmentGenerator.serverCapability,
|
|
185
|
+
~labelField as _,
|
|
186
|
+
): option<JSON.t> => {
|
|
187
|
+
let table = QueryDbStorage_Postgres.tableName(readModelName)
|
|
188
|
+
let filterDict =
|
|
189
|
+
argsDict->Dict.get("filter")->Option.flatMap(JSON.Decode.object)->Option.getOr(Dict.make())
|
|
190
|
+
let strNonEmpty = k =>
|
|
191
|
+
filterDict
|
|
192
|
+
->Dict.get(k)
|
|
193
|
+
->Option.flatMap(JSON.Decode.string)
|
|
194
|
+
->Option.mapOr(false, s => s->String.length > 0)
|
|
195
|
+
let hasIds =
|
|
196
|
+
filterDict
|
|
197
|
+
->Dict.get("ids")
|
|
198
|
+
->Option.flatMap(JSON.Decode.array)
|
|
199
|
+
->Option.mapOr(false, a => a->Array.length > 0)
|
|
200
|
+
let last = argsDict->Dict.get("last")->Option.flatMap(JSON.Decode.float)
|
|
201
|
+
let before = argsDict->Dict.get("before")->Option.flatMap(JSON.Decode.string)
|
|
202
|
+
if (
|
|
203
|
+
strNonEmpty("search") ||
|
|
204
|
+
strNonEmpty("searchPrefix") ||
|
|
205
|
+
hasIds ||
|
|
206
|
+
last->Option.isSome ||
|
|
207
|
+
before->Option.isSome
|
|
208
|
+
) {
|
|
209
|
+
None
|
|
210
|
+
} else {
|
|
211
|
+
let b = {params: []}
|
|
212
|
+
let whereParts = [notExpired]
|
|
213
|
+
let valString = v =>
|
|
214
|
+
switch v->JSON.Decode.string {
|
|
215
|
+
| Some(s) => Some(s)
|
|
216
|
+
| None => v->JSON.Decode.float->Option.map(f => Float.toString(f))
|
|
217
|
+
}
|
|
218
|
+
capability.filterFields->Array.forEach(f => {
|
|
219
|
+
switch filterDict->Dict.get(f.name ++ "Eq") {
|
|
220
|
+
| Some(v) when v != JSON.Encode.null =>
|
|
221
|
+
whereParts->Array.push(
|
|
222
|
+
`${jsonTextC(f.name)} = ${b->param(JSON.Encode.string(valString(v)->Option.getOr("")))}`,
|
|
223
|
+
)
|
|
224
|
+
| _ => ()
|
|
225
|
+
}
|
|
226
|
+
if f.range {
|
|
227
|
+
switch filterDict->Dict.get(f.name ++ "From") {
|
|
228
|
+
| Some(v) when v != JSON.Encode.null =>
|
|
229
|
+
whereParts->Array.push(
|
|
230
|
+
`${jsonTextC(f.name)} >= ${b->param(
|
|
231
|
+
JSON.Encode.string(valString(v)->Option.getOr("")),
|
|
232
|
+
)}`,
|
|
233
|
+
)
|
|
234
|
+
| _ => ()
|
|
235
|
+
}
|
|
236
|
+
switch filterDict->Dict.get(f.name ++ "To") {
|
|
237
|
+
| Some(v) when v != JSON.Encode.null =>
|
|
238
|
+
whereParts->Array.push(
|
|
239
|
+
`${jsonTextC(f.name)} <= ${b->param(
|
|
240
|
+
JSON.Encode.string(valString(v)->Option.getOr("")),
|
|
241
|
+
)}`,
|
|
242
|
+
)
|
|
243
|
+
| _ => ()
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
})
|
|
247
|
+
let orderByDict = argsDict->Dict.get("orderBy")->Option.flatMap(JSON.Decode.object)
|
|
248
|
+
let orderByField =
|
|
249
|
+
orderByDict->Option.flatMap(ob => ob->Dict.get("field"))->Option.flatMap(JSON.Decode.string)
|
|
250
|
+
let isDesc =
|
|
251
|
+
orderByDict
|
|
252
|
+
->Option.flatMap(ob => ob->Dict.get("direction"))
|
|
253
|
+
->Option.flatMap(JSON.Decode.string)
|
|
254
|
+
->Option.getOr("ASC") == "DESC"
|
|
255
|
+
let cursorExpr = switch orderByField {
|
|
256
|
+
| Some(f) => jsonTextC(f)
|
|
257
|
+
| None => idExprC
|
|
258
|
+
}
|
|
259
|
+
switch argsDict->Dict.get("after")->Option.flatMap(JSON.Decode.string) {
|
|
260
|
+
| Some(c) =>
|
|
261
|
+
whereParts->Array.push(
|
|
262
|
+
`${cursorExpr} ${isDesc ? "<" : ">"} ${b->param(
|
|
263
|
+
JSON.Encode.string(ReventlessCore.QueryDbListQuery.decodeCursor(c)),
|
|
264
|
+
)}`,
|
|
265
|
+
)
|
|
266
|
+
| None => ()
|
|
267
|
+
}
|
|
268
|
+
let orderClause = switch orderByField {
|
|
269
|
+
| Some(f) => `${jsonTextC(f)} ${isDesc ? "DESC" : "ASC"}, ${idExprC} ASC`
|
|
270
|
+
| None => `${idExprC} ASC`
|
|
271
|
+
}
|
|
272
|
+
let pageSize =
|
|
273
|
+
argsDict
|
|
274
|
+
->Dict.get("first")
|
|
275
|
+
->Option.flatMap(JSON.Decode.float)
|
|
276
|
+
->Option.map(Float.toInt)
|
|
277
|
+
->Option.getOr(ReventlessCore.QueryDbListQuery.defaultListPageSize)
|
|
278
|
+
let sql = `SELECT partition_key, item FROM ${table} WHERE ${whereParts->Array.join(
|
|
279
|
+
" AND ",
|
|
280
|
+
)} ORDER BY ${orderClause} LIMIT ${b->param(JSON.Encode.int(pageSize + 1))}`
|
|
281
|
+
let rows = (await P.pool->PgDriver.query(sql, b.params))->Array.map(decodeRow(~withId=true, ...))
|
|
282
|
+
let hasMore = rows->Array.length > pageSize
|
|
283
|
+
let pageItems = rows->Array.slice(~start=0, ~end=pageSize)
|
|
284
|
+
let cursorField = orderByField->Option.getOr("id")
|
|
285
|
+
let cursorValueOf = item =>
|
|
286
|
+
ReventlessCore.QueryDbListQuery.getFieldString(item, cursorField)->Option.getOr(
|
|
287
|
+
ReventlessCore.QueryDbListQuery.getId(item),
|
|
288
|
+
)
|
|
289
|
+
Some(
|
|
290
|
+
ReventlessCore.QueryDbListQuery.buildConnection(
|
|
291
|
+
~pageItems,
|
|
292
|
+
~hasNextPage=hasMore,
|
|
293
|
+
~hasPreviousPage=false,
|
|
294
|
+
~cursorValueOf,
|
|
295
|
+
),
|
|
296
|
+
)
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
125
300
|
let make: QueryDb_Adapter.queryEngineMaker = _allQueryDbs =>
|
|
126
301
|
Pulumi.Output.make({QueryEngine.scan, query})
|
|
127
302
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
+
import * as Stdlib_JSON from "@rescript/runtime/lib/es6/Stdlib_JSON.js";
|
|
3
4
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
4
5
|
import * as Pulumi from "@pulumi/pulumi";
|
|
5
6
|
import * as PgDriver$ReventlessPostgres from "./PgDriver.res.mjs";
|
|
7
|
+
import * as QueryDbListQuery$ReventlessCore from "@reventlessdev/reventless-core/src/components/Api/QueryDbListQuery.res.mjs";
|
|
6
8
|
import * as QueryDbStorage_Postgres$ReventlessPostgres from "./QueryDbStorage_Postgres.res.mjs";
|
|
7
9
|
|
|
8
10
|
function valueToText(v) {
|
|
@@ -145,6 +147,90 @@ function Make(P) {
|
|
|
145
147
|
let sql = `SELECT partition_key, item FROM ` + table + ` WHERE ` + where.join(" AND ") + ` ORDER BY partition_key, sub_key LIMIT ` + param(b, limit);
|
|
146
148
|
return (await PgDriver$ReventlessPostgres.query(P.pool, sql, b.params)).map(extra => decodeRow(true, extra));
|
|
147
149
|
};
|
|
150
|
+
let indexLookup = async (readModelName, field, value) => {
|
|
151
|
+
let table = QueryDbStorage_Postgres$ReventlessPostgres.tableName(readModelName);
|
|
152
|
+
let b = {
|
|
153
|
+
params: []
|
|
154
|
+
};
|
|
155
|
+
let sql = `SELECT partition_key, item FROM ` + table + ` WHERE ` + col(field) + ` = ` + param(b, value) + ` AND ` + QueryDbStorage_Postgres$ReventlessPostgres.notExpiredClause;
|
|
156
|
+
return (await PgDriver$ReventlessPostgres.query(P.pool, sql, b.params)).map(extra => decodeRow(true, extra));
|
|
157
|
+
};
|
|
158
|
+
let byIds = async (readModelName, ids) => {
|
|
159
|
+
if (ids.length === 0) {
|
|
160
|
+
return [];
|
|
161
|
+
}
|
|
162
|
+
let table = QueryDbStorage_Postgres$ReventlessPostgres.tableName(readModelName);
|
|
163
|
+
let b = {
|
|
164
|
+
params: []
|
|
165
|
+
};
|
|
166
|
+
let idsJson = ids.map(prim => prim);
|
|
167
|
+
let sql = `SELECT partition_key, item FROM ` + table + ` WHERE partition_key = ANY(` + param(b, idsJson) + `::text[]) AND ` + QueryDbStorage_Postgres$ReventlessPostgres.notExpiredClause;
|
|
168
|
+
return (await PgDriver$ReventlessPostgres.query(P.pool, sql, b.params)).map(extra => decodeRow(true, extra));
|
|
169
|
+
};
|
|
170
|
+
let idExprC = `COALESCE(item->>'id', partition_key) COLLATE "C"`;
|
|
171
|
+
let jsonTextC = field => col(field) + ` COLLATE "C"`;
|
|
172
|
+
let listPage = async (readModelName, argsDict, capability, param$1) => {
|
|
173
|
+
let table = QueryDbStorage_Postgres$ReventlessPostgres.tableName(readModelName);
|
|
174
|
+
let filterDict = Stdlib_Option.getOr(Stdlib_Option.flatMap(argsDict["filter"], Stdlib_JSON.Decode.object), {});
|
|
175
|
+
let strNonEmpty = k => Stdlib_Option.mapOr(Stdlib_Option.flatMap(filterDict[k], Stdlib_JSON.Decode.string), false, s => s.length > 0);
|
|
176
|
+
let hasIds = Stdlib_Option.mapOr(Stdlib_Option.flatMap(filterDict["ids"], Stdlib_JSON.Decode.array), false, a => a.length !== 0);
|
|
177
|
+
let last = Stdlib_Option.flatMap(argsDict["last"], Stdlib_JSON.Decode.float);
|
|
178
|
+
let before = Stdlib_Option.flatMap(argsDict["before"], Stdlib_JSON.Decode.string);
|
|
179
|
+
if (strNonEmpty("search") || strNonEmpty("searchPrefix") || hasIds || Stdlib_Option.isSome(last) || Stdlib_Option.isSome(before)) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
let b = {
|
|
183
|
+
params: []
|
|
184
|
+
};
|
|
185
|
+
let whereParts = [QueryDbStorage_Postgres$ReventlessPostgres.notExpiredClause];
|
|
186
|
+
let valString = v => {
|
|
187
|
+
let s = Stdlib_JSON.Decode.string(v);
|
|
188
|
+
if (s !== undefined) {
|
|
189
|
+
return s;
|
|
190
|
+
} else {
|
|
191
|
+
return Stdlib_Option.map(Stdlib_JSON.Decode.float(v), f => f.toString());
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
capability.filterFields.forEach(f => {
|
|
195
|
+
let v = filterDict[f.name + "Eq"];
|
|
196
|
+
if (v !== undefined && v !== null) {
|
|
197
|
+
whereParts.push(jsonTextC(f.name) + ` = ` + param(b, Stdlib_Option.getOr(valString(v), "")));
|
|
198
|
+
}
|
|
199
|
+
if (!f.range) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
let v$1 = filterDict[f.name + "From"];
|
|
203
|
+
if (v$1 !== undefined && v$1 !== null) {
|
|
204
|
+
whereParts.push(jsonTextC(f.name) + ` >= ` + param(b, Stdlib_Option.getOr(valString(v$1), "")));
|
|
205
|
+
}
|
|
206
|
+
let v$2 = filterDict[f.name + "To"];
|
|
207
|
+
if (v$2 !== undefined && v$2 !== null) {
|
|
208
|
+
whereParts.push(jsonTextC(f.name) + ` <= ` + param(b, Stdlib_Option.getOr(valString(v$2), "")));
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
let orderByDict = Stdlib_Option.flatMap(argsDict["orderBy"], Stdlib_JSON.Decode.object);
|
|
213
|
+
let orderByField = Stdlib_Option.flatMap(Stdlib_Option.flatMap(orderByDict, ob => ob["field"]), Stdlib_JSON.Decode.string);
|
|
214
|
+
let isDesc = Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_Option.flatMap(orderByDict, ob => ob["direction"]), Stdlib_JSON.Decode.string), "ASC") === "DESC";
|
|
215
|
+
let cursorExpr = orderByField !== undefined ? jsonTextC(orderByField) : idExprC;
|
|
216
|
+
let c = Stdlib_Option.flatMap(argsDict["after"], Stdlib_JSON.Decode.string);
|
|
217
|
+
if (c !== undefined) {
|
|
218
|
+
whereParts.push(cursorExpr + ` ` + (
|
|
219
|
+
isDesc ? "<" : ">"
|
|
220
|
+
) + ` ` + param(b, QueryDbListQuery$ReventlessCore.decodeCursor(c)));
|
|
221
|
+
}
|
|
222
|
+
let orderClause = orderByField !== undefined ? jsonTextC(orderByField) + ` ` + (
|
|
223
|
+
isDesc ? "DESC" : "ASC"
|
|
224
|
+
) + `, ` + idExprC + ` ASC` : idExprC + ` ASC`;
|
|
225
|
+
let pageSize = Stdlib_Option.getOr(Stdlib_Option.map(Stdlib_Option.flatMap(argsDict["first"], Stdlib_JSON.Decode.float), prim => prim | 0), QueryDbListQuery$ReventlessCore.defaultListPageSize);
|
|
226
|
+
let sql = `SELECT partition_key, item FROM ` + table + ` WHERE ` + whereParts.join(" AND ") + ` ORDER BY ` + orderClause + ` LIMIT ` + param(b, pageSize + 1 | 0);
|
|
227
|
+
let rows = (await PgDriver$ReventlessPostgres.query(P.pool, sql, b.params)).map(extra => decodeRow(true, extra));
|
|
228
|
+
let hasMore = rows.length > pageSize;
|
|
229
|
+
let pageItems = rows.slice(0, pageSize);
|
|
230
|
+
let cursorField = Stdlib_Option.getOr(orderByField, "id");
|
|
231
|
+
let cursorValueOf = item => Stdlib_Option.getOr(QueryDbListQuery$ReventlessCore.getFieldString(item, cursorField), QueryDbListQuery$ReventlessCore.getId(item));
|
|
232
|
+
return QueryDbListQuery$ReventlessCore.buildConnection(pageItems, hasMore, false, cursorValueOf);
|
|
233
|
+
};
|
|
148
234
|
let make = _allQueryDbs => Pulumi.output({
|
|
149
235
|
scan: scan,
|
|
150
236
|
query: query
|
|
@@ -152,6 +238,11 @@ function Make(P) {
|
|
|
152
238
|
return {
|
|
153
239
|
query: query,
|
|
154
240
|
scan: scan,
|
|
241
|
+
indexLookup: indexLookup,
|
|
242
|
+
byIds: byIds,
|
|
243
|
+
idExprC: idExprC,
|
|
244
|
+
jsonTextC: jsonTextC,
|
|
245
|
+
listPage: listPage,
|
|
155
246
|
make: make
|
|
156
247
|
};
|
|
157
248
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|