Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pubtypes option to edgeql-go #318

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/edgeql-go/endtoend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ var tests = []struct {
directory: "testdata/pubfuncs",
args: []string{"-pubfuncs"},
},
{
description: "invoke edgeql-go with -pubtypes",
directory: "testdata/pubtypes",
args: []string{"-pubtypes"},
},
}

func TestMain(m *testing.M) {
Expand Down
4 changes: 4 additions & 0 deletions cmd/edgeql-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func usage() {
type cmdConfig struct {
mixedCaps bool
pubfuncs bool
pubtypes bool
}

func main() {
Expand All @@ -73,11 +74,14 @@ func main() {
"to MixedCaps names in go structs")
pubfuncs := flag.Bool("pubfuncs", false,
"Make generated functions public.")
pubtypes := flag.Bool("pubtypes", false,
"Make generated types public.")
flag.Parse()

cfg := &cmdConfig{
mixedCaps: *mixedCaps,
pubfuncs: *pubfuncs,
pubtypes: *pubtypes,
}

timer := time.AfterFunc(200*time.Millisecond, func() {
Expand Down
3 changes: 3 additions & 0 deletions cmd/edgeql-go/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ func queryName(qryFile string, cmdCfg *cmdConfig) string {
func typeName(qryFile string, cmdCfg *cmdConfig) string {
name := filepath.Base(qryFile)
name = strings.TrimSuffix(name, ".edgeql")
if cmdCfg.pubtypes {
return snakeToUpperMixedCase(name)
}
return snakeToLowerMixedCase(name)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[edgedb]
server-version = "3.3"

[project]
schema-dir = "somewhere/else"
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module test

go 1.19

require (
github.com/certifi/gocertifi v0.0.0-20210507211836-431795d63e8d // indirect
github.com/edgedb/edgedb-go v0.12.0 // indirect
github.com/xdg/scram v1.0.5 // indirect
github.com/xdg/stringprep v1.0.3 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/text v0.3.7 // indirect
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
github.com/certifi/gocertifi v0.0.0-20210507211836-431795d63e8d h1:S2NE3iHSwP0XV47EEXL8mWmRdEfGscSJ+7EgePNgt0s=
github.com/certifi/gocertifi v0.0.0-20210507211836-431795d63e8d/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/edgedb/edgedb-go v0.12.0 h1:WQBe/+0kCoccnhsWw+O7cppemsVfy55rAk0EsLrmCHk=
github.com/edgedb/edgedb-go v0.12.0/go.mod h1:O+ZRO2juj+e0PaoK1u2iZmLe7jXko9MlODiHXwSxDYA=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/xdg/scram v1.0.5 h1:TuS0RFmt5Is5qm9Tm2SoD89OPqe4IRiFtyFY4iwWXsw=
github.com/xdg/scram v1.0.5/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I=
github.com/xdg/stringprep v1.0.3 h1:cmL5Enob4W83ti/ZHuZLuKD/xqJfus4fVPwE+/BDm+4=
github.com/xdg/stringprep v1.0.3/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e h1:T8NU3HyQ8ClP4SEE+KbFlg6n0NhuTsN4MyznaarGsZM=
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package main

func main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Code generated by github.com/edgedb/edgedb-go/cmd/edgeql-go DO NOT EDIT.

package main

import (
"context"
_ "embed"

"github.com/edgedb/edgedb-go"
)

//go:embed select_scalar.edgeql
var selectScalarCmd string

// selectScalar
// runs the query found in
// select_scalar.edgeql
func selectScalar(
ctx context.Context,
client *edgedb.Client,
) (int64, error) {
var result int64

err := client.QuerySingle(
ctx,
selectScalarCmd,
&result,
)

return result, err
}

// selectScalarJSON
// runs the query found in
// select_scalar.edgeql
// returning the results as json encoded bytes
func selectScalarJSON(
ctx context.Context,
client *edgedb.Client,
) ([]byte, error) {
var result []byte

err := client.QuerySingleJSON(
ctx,
selectScalarCmd,
&result,
)
if err != nil {
return nil, err
}

return result, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CREATE MIGRATION m1fqtauhtvc2w56wh2676x5g26aye22ghx7b7mtnbfekxpmxmnjx2a
ONTO initial
{
CREATE TYPE default::Person {
CREATE MULTI LINK friends -> default::Person {
CREATE PROPERTY strength -> std::float64;
};
CREATE REQUIRED PROPERTY name -> std::str {
CREATE CONSTRAINT std::exclusive;
};
};
};
Empty file.
13 changes: 13 additions & 0 deletions cmd/edgeql-go/testdata/pubtypes/test-project1/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module test

go 1.19

require (
github.com/certifi/gocertifi v0.0.0-20210507211836-431795d63e8d // indirect
github.com/edgedb/edgedb-go v0.12.0 // indirect
github.com/xdg/scram v1.0.5 // indirect
github.com/xdg/stringprep v1.0.3 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/text v0.3.7 // indirect
)
35 changes: 35 additions & 0 deletions cmd/edgeql-go/testdata/pubtypes/test-project1/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
github.com/certifi/gocertifi v0.0.0-20210507211836-431795d63e8d h1:S2NE3iHSwP0XV47EEXL8mWmRdEfGscSJ+7EgePNgt0s=
github.com/certifi/gocertifi v0.0.0-20210507211836-431795d63e8d/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/edgedb/edgedb-go v0.12.0 h1:WQBe/+0kCoccnhsWw+O7cppemsVfy55rAk0EsLrmCHk=
github.com/edgedb/edgedb-go v0.12.0/go.mod h1:O+ZRO2juj+e0PaoK1u2iZmLe7jXko9MlODiHXwSxDYA=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/xdg/scram v1.0.5 h1:TuS0RFmt5Is5qm9Tm2SoD89OPqe4IRiFtyFY4iwWXsw=
github.com/xdg/scram v1.0.5/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I=
github.com/xdg/stringprep v1.0.3 h1:cmL5Enob4W83ti/ZHuZLuKD/xqJfus4fVPwE+/BDm+4=
github.com/xdg/stringprep v1.0.3/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e h1:T8NU3HyQ8ClP4SEE+KbFlg6n0NhuTsN4MyznaarGsZM=
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
3 changes: 3 additions & 0 deletions cmd/edgeql-go/testdata/pubtypes/test-project1/ignore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package main

func main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Code generated by github.com/edgedb/edgedb-go/cmd/edgeql-go DO NOT EDIT.

package main

import (
"context"
_ "embed"

"github.com/edgedb/edgedb-go"
)

//go:embed select_scalar.edgeql
var selectScalarCmd string

// selectScalar
// runs the query found in
// select_scalar.edgeql
func selectScalar(
ctx context.Context,
client *edgedb.Client,
) (int64, error) {
var result int64

err := client.QuerySingle(
ctx,
selectScalarCmd,
&result,
)

return result, err
}

// selectScalarJSON
// runs the query found in
// select_scalar.edgeql
// returning the results as json encoded bytes
func selectScalarJSON(
ctx context.Context,
client *edgedb.Client,
) ([]byte, error) {
var result []byte

err := client.QuerySingleJSON(
ctx,
selectScalarCmd,
&result,
)
if err != nil {
return nil, err
}

return result, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select <int64>$arg_name_with_underscores
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Code generated by github.com/edgedb/edgedb-go/cmd/edgeql-go DO NOT EDIT.

package argnames

import (
"context"
_ "embed"

"github.com/edgedb/edgedb-go"
)

//go:embed query_one.edgeql
var queryOneCmd string

// queryOne
// runs the query found in
// query_one.edgeql
func queryOne(
ctx context.Context,
client *edgedb.Client,
arg_name_with_underscores int64,
) (int64, error) {
var result int64

err := client.QuerySingle(
ctx,
queryOneCmd,
&result,
map[string]interface{}{
"arg_name_with_underscores": arg_name_with_underscores,
},
)

return result, err
}

// queryOneJSON
// runs the query found in
// query_one.edgeql
// returning the results as json encoded bytes
func queryOneJSON(
ctx context.Context,
client *edgedb.Client,
arg_name_with_underscores int64,
) ([]byte, error) {
var result []byte

err := client.QuerySingleJSON(
ctx,
queryOneCmd,
&result,
map[string]interface{}{
"arg_name_with_underscores": arg_name_with_underscores,
},
)
if err != nil {
return nil, err
}

return result, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CREATE MIGRATION m1fqtauhtvc2w56wh2676x5g26aye22ghx7b7mtnbfekxpmxmnjx2a
ONTO initial
{
CREATE TYPE default::Person {
CREATE MULTI LINK friends -> default::Person {
CREATE PROPERTY strength -> std::float64;
};
CREATE REQUIRED PROPERTY name -> std::str {
CREATE CONSTRAINT std::exclusive;
};
};
};
Empty file.
13 changes: 13 additions & 0 deletions cmd/edgeql-go/testdata/pubtypes/test-project2/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module test

go 1.19

require (
github.com/certifi/gocertifi v0.0.0-20210507211836-431795d63e8d // indirect
github.com/edgedb/edgedb-go v0.12.0 // indirect
github.com/xdg/scram v1.0.5 // indirect
github.com/xdg/stringprep v1.0.3 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/text v0.3.7 // indirect
)
Loading
Loading