Expand typed SQL DSL
This commit is contained in:
parent
72606e7818
commit
314c8fb207
17 changed files with 1082 additions and 498 deletions
|
|
@ -133,9 +133,9 @@ import pgxpool "github.com/jackc/pgx/v5/pgxpool"
|
|||
fun claim(id: String, payload: String, pool: *pgxpool.Pool, ctx: context.Context): EventProjection {
|
||||
return sql.update<EventRow>()
|
||||
.set { row ->
|
||||
set(row.payload, payload)
|
||||
set(row.attempts, row.attempts + 1)
|
||||
set(row.claimedUntil, now())
|
||||
row.payload = payload
|
||||
row.attempts = row.attempts + 1
|
||||
row.claimedUntil = now()
|
||||
}
|
||||
.where { it.id == id && it.publishedAt == null }
|
||||
.returning { row -> EventProjection(row.id, row.payload) }
|
||||
|
|
@ -210,7 +210,7 @@ func TestRejectExpandedInvalidSQLQueries(t *testing.T) {
|
|||
{
|
||||
name: "projection type mismatch",
|
||||
src: eventSQLSource + `fun query(): GotlinSQLQuery { return sql.from<EventRow>().select { WrongProjection(it.id) }.build() }`,
|
||||
want: "has type Int but row field id has type String",
|
||||
want: "has type Int but expression has type String",
|
||||
},
|
||||
{
|
||||
name: "projection arity mismatch",
|
||||
|
|
@ -220,7 +220,7 @@ func TestRejectExpandedInvalidSQLQueries(t *testing.T) {
|
|||
{
|
||||
name: "projection after where",
|
||||
src: eventSQLSource + `fun query(): GotlinSQLQuery { return sql.from<EventRow>().where { it.id == "x" }.select { EventProjection(it.id, it.payload) }.build() }`,
|
||||
want: "must be the first sql.from method",
|
||||
want: "after joins and before filtering",
|
||||
},
|
||||
{
|
||||
name: "update missing set",
|
||||
|
|
@ -229,22 +229,22 @@ func TestRejectExpandedInvalidSQLQueries(t *testing.T) {
|
|||
},
|
||||
{
|
||||
name: "update incompatible value",
|
||||
src: eventSQLSource + `fun query(): GotlinSQLQuery { return sql.update<EventRow>().set { set(it.attempts, "bad") }.build() }`,
|
||||
src: eventSQLSource + `fun query(): GotlinSQLQuery { return sql.update<EventRow>().set { it.attempts = "bad" }.build() }`,
|
||||
want: "has type Int but value has type String",
|
||||
},
|
||||
{
|
||||
name: "update null non nullable",
|
||||
src: eventSQLSource + `fun query(): GotlinSQLQuery { return sql.update<EventRow>().set { set(it.payload, null) }.build() }`,
|
||||
src: eventSQLSource + `fun query(): GotlinSQLQuery { return sql.update<EventRow>().set { it.payload = null }.build() }`,
|
||||
want: "has non-nullable type String",
|
||||
},
|
||||
{
|
||||
name: "update nullable into non nullable",
|
||||
src: eventSQLSource + `fun query(value: String?): GotlinSQLQuery { return sql.update<EventRow>().set { set(it.payload, value) }.build() }`,
|
||||
src: eventSQLSource + `fun query(value: String?): GotlinSQLQuery { return sql.update<EventRow>().set { it.payload = value }.build() }`,
|
||||
want: "has type String but value has type String?",
|
||||
},
|
||||
{
|
||||
name: "duplicate update target",
|
||||
src: eventSQLSource + `fun query(): GotlinSQLQuery { return sql.update<EventRow>().set { set(it.payload, "a"); set(it.payload, "b") }.build() }`,
|
||||
src: eventSQLSource + `fun query(): GotlinSQLQuery { return sql.update<EventRow>().set { it.payload = "a"; it.payload = "b" }.build() }`,
|
||||
want: "duplicate set target payload",
|
||||
},
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue