@subsquid/openreader 0.3.3 → 0.5.0
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/dist/gql/opencrud.d.ts.map +1 -1
- package/dist/gql/opencrud.js +10 -0
- package/dist/gql/opencrud.js.map +1 -1
- package/dist/gql/schema.d.ts.map +1 -1
- package/dist/gql/schema.js +116 -17
- package/dist/gql/schema.js.map +1 -1
- package/dist/model.d.ts +8 -0
- package/dist/model.d.ts.map +1 -1
- package/dist/model.tools.d.ts +1 -0
- package/dist/model.tools.d.ts.map +1 -1
- package/dist/model.tools.js +27 -1
- package/dist/model.tools.js.map +1 -1
- package/dist/queryBuilder.d.ts.map +1 -1
- package/dist/queryBuilder.js +17 -3
- package/dist/queryBuilder.js.map +1 -1
- package/dist/test/isNull.test.d.ts +2 -0
- package/dist/test/isNull.test.d.ts.map +1 -0
- package/dist/test/isNull.test.js +75 -0
- package/dist/test/isNull.test.js.map +1 -0
- package/dist/where.d.ts +1 -1
- package/dist/where.d.ts.map +1 -1
- package/dist/where.js +1 -0
- package/dist/where.js.map +1 -1
- package/package.json +9 -9
- package/src/gql/opencrud.ts +10 -0
- package/src/gql/schema.ts +145 -19
- package/src/model.tools.ts +28 -0
- package/src/model.ts +12 -0
- package/src/queryBuilder.ts +16 -4
- package/src/test/isNull.test.ts +79 -0
- package/src/where.ts +2 -0
package/src/queryBuilder.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {toSnakeCase} from "@subsquid/util"
|
|
2
2
|
import assert from "assert"
|
|
3
|
-
import type {ClientBase, QueryArrayResult} from "pg"
|
|
4
3
|
import {Database} from "./db"
|
|
5
4
|
import type {Entity, JsonObject, Model} from "./model"
|
|
6
5
|
import {getEntity, getFtsQuery, getObject, getUnionProps} from "./model.tools"
|
|
@@ -81,7 +80,7 @@ export class QueryBuilder {
|
|
|
81
80
|
break
|
|
82
81
|
default:
|
|
83
82
|
if (columns.size()) {
|
|
84
|
-
out += `SELECT ${columns.render()}\n`
|
|
83
|
+
out += `SELECT ${columns.render(true)}\n`
|
|
85
84
|
}
|
|
86
85
|
}
|
|
87
86
|
|
|
@@ -304,6 +303,15 @@ export class QueryBuilder {
|
|
|
304
303
|
|
|
305
304
|
private addPropCondition(exps: string[], cursor: Cursor, field: string, op: WhereOp, arg: any): void {
|
|
306
305
|
let propType = cursor.object.properties[field].type
|
|
306
|
+
if (op == 'isNull') {
|
|
307
|
+
let lhs = propType.kind == 'fk' ? cursor.fk(field) : cursor.field(field)
|
|
308
|
+
if (arg) {
|
|
309
|
+
exps.push(`${lhs} IS NULL`)
|
|
310
|
+
} else {
|
|
311
|
+
exps.push(`${lhs} IS NOT NULL`)
|
|
312
|
+
}
|
|
313
|
+
return
|
|
314
|
+
}
|
|
307
315
|
switch(propType.kind) {
|
|
308
316
|
case 'scalar':
|
|
309
317
|
case 'enum': {
|
|
@@ -724,8 +732,12 @@ class ColumnSet {
|
|
|
724
732
|
return idx
|
|
725
733
|
}
|
|
726
734
|
|
|
727
|
-
render(): string {
|
|
728
|
-
|
|
735
|
+
render(withAliases?: boolean): string {
|
|
736
|
+
let cols = Array.from(this.columns.keys())
|
|
737
|
+
if (withAliases) {
|
|
738
|
+
cols = cols.map((col, idx) => `${col} AS _c${idx}`)
|
|
739
|
+
}
|
|
740
|
+
return cols.join(', ')
|
|
729
741
|
}
|
|
730
742
|
|
|
731
743
|
size(): number {
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import {useDatabase, useServer} from "./util/setup"
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
describe('isNull operator', function() {
|
|
5
|
+
useDatabase([
|
|
6
|
+
`create table meta (id text primary key)`,
|
|
7
|
+
`create table entity (id text primary key, scalar text, json jsonb, meta_id text)`,
|
|
8
|
+
`insert into meta (id) values ('1')`,
|
|
9
|
+
`insert into entity (id, json, meta_id) values ('1', '{"a": 1}', '1')`,
|
|
10
|
+
`insert into entity (id, scalar, meta_id) values ('2', 'foo', '1')`,
|
|
11
|
+
`insert into entity (id, scalar, json) values ('3', 'foo', '{"a": 2}')`,
|
|
12
|
+
`insert into entity (id, scalar, json, meta_id) values ('4', 'foo', '{}', '1')`,
|
|
13
|
+
])
|
|
14
|
+
|
|
15
|
+
const client = useServer(`
|
|
16
|
+
type Meta @entity {
|
|
17
|
+
id: ID!
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type Entity @entity {
|
|
21
|
+
id: ID!
|
|
22
|
+
scalar: String
|
|
23
|
+
json: JsonObject
|
|
24
|
+
meta: Meta
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type JsonObject {
|
|
28
|
+
a: Int
|
|
29
|
+
}
|
|
30
|
+
`)
|
|
31
|
+
|
|
32
|
+
it("on scalar", function() {
|
|
33
|
+
return client.test(`
|
|
34
|
+
query {
|
|
35
|
+
entities(where: {scalar_isNull: true}) {
|
|
36
|
+
id
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
`, {
|
|
40
|
+
entities: [{id: '1'}]
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it("on json", function() {
|
|
45
|
+
return client.test(`
|
|
46
|
+
query {
|
|
47
|
+
entities(where: {json_isNull: true}) {
|
|
48
|
+
id
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
`, {
|
|
52
|
+
entities: [{id: '2'}]
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it("on nested json prop", function() {
|
|
57
|
+
return client.test(`
|
|
58
|
+
query {
|
|
59
|
+
entities(where: {json: {a_isNull: true}} orderBy: id_ASC) {
|
|
60
|
+
id
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
`, {
|
|
64
|
+
entities: [{id: '2'}, {id: '4'}]
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it("on fk", function() {
|
|
69
|
+
return client.test(`
|
|
70
|
+
query {
|
|
71
|
+
entities(where: {meta_isNull: true}) {
|
|
72
|
+
id
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
`, {
|
|
76
|
+
entities: [{id: '3'}]
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
})
|