Skip to content

Commit

Permalink
add test for array field
Browse files Browse the repository at this point in the history
  • Loading branch information
imperfect-fourth committed Dec 9, 2024
1 parent 87a41d1 commit 30e42f8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 36 deletions.
39 changes: 16 additions & 23 deletions cmd/eywagen/eywatest/eywa_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
package eywatest

import (
"github.com/imperfect-fourth/eywa"
"fmt"
"bytes"
"github.com/google/uuid"
"github.com/imperfect-fourth/eywa"
"fmt"
)


Expand Down Expand Up @@ -111,21 +111,6 @@ func testTable_JsonBColVar[T interface{eywa.JSONValue | eywa.JSONBValue;eywa.Typ
Value: eywa.QueryVar("testTable_JsonBCol", T{val}),
}
}
const testTable_RR eywa.FieldName[testTable] = "r"

func testTable_RRField(val R) eywa.Field[testTable] {
return eywa.Field[testTable]{
Name: "r",
Value: val,
}
}

func testTable_RRVar(val R) eywa.Field[testTable] {
return eywa.Field[testTable]{
Name: "r",
Value: eywa.QueryVar("testTable_RR", eywa.StringVar[R](val)),
}
}
const testTable_Status eywa.FieldName[testTable] = "status"

func testTable_StatusField(val eywa.Enum[status]) eywa.Field[testTable] {
Expand All @@ -141,19 +126,27 @@ func testTable_StatusVar(val eywa.Enum[status]) eywa.Field[testTable] {
Value: eywa.QueryVar("testTable_Status", eywa.StringVar[eywa.Enum[status]](val)),
}
}
const testTable_F eywa.FieldName[testTable] = "f"
const testTable_Generic eywa.FieldName[testTable] = "generic_type"

func testTable_FField(val X[string, int]) eywa.Field[testTable] {
func testTable_GenericField(val GenericType[string, int]) eywa.Field[testTable] {
return eywa.Field[testTable]{
Name: "f",
Name: "generic_type",
Value: val,
}
}

func testTable_FVar(val X[string, int]) eywa.Field[testTable] {
func testTable_GenericVar(val GenericType[string, int]) eywa.Field[testTable] {
return eywa.Field[testTable]{
Name: "f",
Value: eywa.QueryVar("testTable_F", eywa.StringVar[X[string, int]](val)),
Name: "generic_type",
Value: eywa.QueryVar("testTable_Generic", eywa.StringVar[GenericType[string, int]](val)),
}
}
const testTable_ArrayCol eywa.FieldName[testTable] = "testarr"

func testTable_ArrayColField(val []string) eywa.Field[testTable] {
return eywa.Field[testTable]{
Name: "testarr",
Value: val,
}
}

Expand Down
15 changes: 15 additions & 0 deletions cmd/eywagen/eywatest/eywa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ name
}
}

func TestSelectArrayColumn(t *testing.T) {
accessKey := os.Getenv("TEST_HGE_ACCESS_KEY")
c := eywa.NewClient("https://aware-cowbird-80.hasura.app/v1/graphql", &eywa.ClientOpts{
Headers: map[string]string{
"x-hasura-access-key": accessKey,
},
})
out, err := eywa.Get[testTable]().Where(
eywa.Eq[testTable](testTable_IDField(1)),
).Select(
testTable_ArrayCol,
).Exec(c)
fmt.Println(out[0].ArrayCol, err)
}

func TestRelationshipSelectQuery(t *testing.T) {
age := 10
q := eywa.Get[testTable]().Limit(2).Offset(1).DistinctOn(testTable_Name).OrderBy(
Expand Down
24 changes: 11 additions & 13 deletions cmd/eywagen/eywatest/eywatest.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,26 @@ import (

//go:generate ../eywagen -types testTable,testTable2
type testTable struct {
Name string `json:"name"`
Age *int `json:"age"`
ID int `json:"id,omitempty",eywa:"pkey"`
IDd int32 `json:"idd,omitempty"`
custom *customType `json:"custom"`
testTable2 *testTable2 `json:"testTable2"`
JsonBCol jsonbcol `json:"jsonb_col"`
RR R `json:"r"`
Status eywa.Enum[status] `json:"status"`
F X[string, int] `json:"f"`
Name string `json:"name"`
Age *int `json:"age"`
ID int `json:"id,omitempty",eywa:"pkey"`
IDd int32 `json:"idd,omitempty"`
custom *customType `json:"custom"`
testTable2 *testTable2 `json:"testTable2"`
JsonBCol jsonbcol `json:"jsonb_col"`
Status eywa.Enum[status] `json:"status"`
Generic GenericType[string, int] `json:"generic_type"`
ArrayCol []string `json:"testarr"`
}

type status string

type X[T ~string, U ~int] string
type GenericType[T ~string, U ~int] string

var (
state1 eywa.Enum[status] = "state1"
)

type R string

func (t testTable) TableName() string {
return "test_table"
}
Expand Down

0 comments on commit 30e42f8

Please sign in to comment.