diff --git a/README.md b/README.md index ac95d86..6fba66d 100644 --- a/README.md +++ b/README.md @@ -28,18 +28,24 @@ go install github.com/tkcrm/pgxgen/cmd/pgxgen@latest Print all available commands -```bash +```shell pgxgen help -``` -### Version - -```bash -# Print current version -pgxgen version - -# Check for new version -pgxgen check-version +COMMANDS: + crud Generate crud sql's + gomodels Generate golang models based on existed structs + keystone Generate mobx keystone models + ts Generate types for typescript, based on go structs + sqlc Generate sqlc code + check-version Check for a new version + version Print the version + help, h Shows a list of commands or help for one command + +GLOBAL OPTIONS: + --pgxgen-config value Absolute or relative path to pgxgen.yaml file (default: "pgxgen.yaml") + --sqlc-config value Absolute or relative path to sqlc.yaml file (default: "sqlc.yaml") + --help, -h show help + --version, -v print the version ``` ### Configure `pgxgen` @@ -253,25 +259,7 @@ gen_typescript_from_structs: - "GetOrganizationRequest" ``` -### Generate `CRUD` queries for existing tables - -```bash -pgxgen crud -``` - -### Generate models based on sqlc models - -```bash -pgxgen gomodels -``` - -### Generate keystone models based on go models - -```bash -pgxgen keystone -``` - -#### Install `@tkcrm/ui` in your frontend +### Install `@tkcrm/ui` in your frontend If you generate mobx keystone models install `@tkcrm/ui` in your frontend project @@ -279,12 +267,6 @@ If you generate mobx keystone models install `@tkcrm/ui` in your frontend projec npm i @tkcrm/ui --save-dev ``` -### Generate typescript types based on go structs - -```bash -pgxgen ts -``` - ### Configure `sqlc` At root of your project create a `sqlc.yaml` file with the configuration described below. @@ -319,14 +301,3 @@ sql: emit_enum_valid_method: true emit_all_enum_values: true ``` - -### Generate `sqlc` - -```bash -pgxgen sqlc generate -``` - -## Roadmap - -- Generate models without sqlc -- Generate `.proto` files with CRUD services diff --git a/cmd/pgxgen/main.go b/cmd/pgxgen/main.go index 9ce203c..751c77e 100644 --- a/cmd/pgxgen/main.go +++ b/cmd/pgxgen/main.go @@ -1,10 +1,10 @@ package main import ( + "fmt" "os" + "runtime" - "github.com/cristalhq/acmd" - "github.com/cristalhq/flagx" "github.com/tkcrm/pgxgen/internal/config" "github.com/tkcrm/pgxgen/internal/crud" "github.com/tkcrm/pgxgen/internal/gomodels" @@ -13,6 +13,7 @@ import ( "github.com/tkcrm/pgxgen/internal/typescript" "github.com/tkcrm/pgxgen/internal/ver" "github.com/tkcrm/pgxgen/pkg/logger" + "github.com/urfave/cli/v2" ) var ( @@ -20,67 +21,127 @@ var ( version = "v0.3.5" ) -func main() { - logger := logger.New() - - // custom config file path - var cf config.Flags - fset := flagx.NewFlagSet(appName, os.Stdout) - fset.String(&cf.PgxgenConfigFilePath, "pgxgen-config", "", "pgxgen.yaml", "absolute or relative path to sqlc.yaml file") - fset.String(&cf.SqlcConfigFilePath, "sqlc-config", "", "sqlc.yaml", "absolute or relative path to pgxgen.yaml file") +func getBuildVersion() string { + return fmt.Sprintf( + "\nrelease: %s\ngo version: %s", + version, + runtime.Version(), + ) +} - // parse flags - if err := fset.Parse(os.Args[1:]); err != nil { - logger.Fatalf("failed to parse flags: %s", err) +func loadConfig(c *cli.Context) (config.Config, error) { + cf := config.Flags{ + PgxgenConfigFilePath: c.String("pgxgen-config"), + SqlcConfigFilePath: c.String("sqlc-config"), } cfg, err := config.LoadConfig(cf, version) if err != nil { - logger.Fatalf("load config error: %s", err) + return cfg, fmt.Errorf("load config error: %w", err) } - cmds := []acmd.Command{ - { - Name: "crud", - Description: "generate crud sql's", - ExecFunc: crud.CmdFunc(logger, cfg), - }, - { - Name: "gomodels", - Description: "generate golang models based on existed structs", - ExecFunc: gomodels.CmdFunc(logger, cfg), - }, - { - Name: "keystone", - Description: "generate mobx keystone models", - ExecFunc: keystone.CmdFunc(logger, cfg), - }, - { - Name: "ts", - Description: "generate types for typescript, based on go structs", - ExecFunc: typescript.CmdFunc(logger, cfg), - }, - { - Name: "sqlc", - Description: "generate sqlc code", - ExecFunc: sqlc.CmdFunc(logger, cfg), + return cfg, nil +} + +func main() { + logger := logger.New() + + app := &cli.App{ + Name: appName, + Version: getBuildVersion(), + Usage: "Generate GO models, DB CRUD, Mobx Keystone models and typescript code based on DDL", + Suggest: true, + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "pgxgen-config", + Usage: "Absolute or relative path to pgxgen.yaml file", + Value: "pgxgen.yaml", + }, + &cli.StringFlag{ + Name: "sqlc-config", + Usage: "Absolute or relative path to sqlc.yaml file", + Value: "sqlc.yaml", + }, }, - { - Name: "check-version", - Description: "check for new version", - ExecFunc: ver.CmdFunc(logger, cfg), + Commands: []*cli.Command{ + { + Name: "crud", + Usage: "Generate crud sql's", + Action: func(c *cli.Context) error { + cfg, err := loadConfig(c) + if err != nil { + return err + } + return crud.CmdFunc(c, logger, cfg) + }, + }, + { + Name: "gomodels", + Usage: "Generate golang models based on existed structs", + Action: func(c *cli.Context) error { + cfg, err := loadConfig(c) + if err != nil { + return err + } + return gomodels.CmdFunc(c, logger, cfg) + }, + }, + { + Name: "keystone", + Usage: "Generate mobx keystone models", + Action: func(c *cli.Context) error { + cfg, err := loadConfig(c) + if err != nil { + return err + } + return keystone.CmdFunc(c, logger, cfg) + }, + }, + { + Name: "ts", + Usage: "Generate types for typescript, based on go structs", + Action: func(c *cli.Context) error { + cfg, err := loadConfig(c) + if err != nil { + return err + } + return typescript.CmdFunc(c, logger, cfg) + }, + }, + { + Name: "sqlc", + Usage: "Generate sqlc code", + Action: func(c *cli.Context) error { + cfg, err := loadConfig(c) + if err != nil { + return err + } + return sqlc.CmdFunc(c, logger, cfg) + }, + }, + { + Name: "check-version", + Usage: "Check for a new version", + Action: func(c *cli.Context) error { + cfg, err := loadConfig(c) + if err != nil { + return err + } + return ver.CmdFunc(c, logger, cfg) + }, + }, + { + Name: "version", + Usage: "Print the version", + Action: func(c *cli.Context) error { + fmt.Printf("%s version%s\n", appName, c.App.Version) + return nil + }, + }, }, } - r := acmd.RunnerOf(cmds, acmd.Config{ - AppName: "pgxgen", - AppDescription: "Generate GO models, DB CRUD, Mobx Keystone models and typescript code based on DDL", - PostDescription: "pgxgen crud", - Version: version, - Args: append([]string{os.Args[0]}, fset.Args()...), - }) - - if err := r.Run(); err != nil { + if err := app.Run(os.Args); err != nil { logger.Fatalf("error: %s", err) } } diff --git a/go.mod b/go.mod index 795968b..e51f800 100644 --- a/go.mod +++ b/go.mod @@ -11,52 +11,53 @@ require ( github.com/jackc/pgx/v4 v4.18.3 github.com/jinzhu/inflection v1.0.0 github.com/lib/pq v1.10.9 - github.com/spf13/cobra v1.8.0 + github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.5 - github.com/tkcrm/modules v0.0.0-20240504201808-caa8f8d56cb5 - golang.org/x/sync v0.7.0 - golang.org/x/tools v0.20.0 - google.golang.org/protobuf v1.34.0 + github.com/tkcrm/modules v0.0.0-20240731155216-c9ed7e436ff1 + golang.org/x/sync v0.8.0 + golang.org/x/tools v0.24.0 + google.golang.org/protobuf v1.34.2 gopkg.in/yaml.v3 v3.0.1 ) -require ( - github.com/cristalhq/acmd v0.12.0 - gopkg.in/yaml.v2 v2.4.0 -) +require gopkg.in/yaml.v2 v2.4.0 require ( - github.com/a-h/templ v0.2.680 - github.com/antlr4-go/antlr/v4 v4.13.0 - github.com/cristalhq/flagx v0.5.0 + github.com/a-h/templ v0.2.747 + github.com/antlr4-go/antlr/v4 v4.13.1 github.com/fatih/structtag v1.2.0 - github.com/google/cel-go v0.20.1 - github.com/jackc/pgx/v5 v5.5.5 + github.com/google/cel-go v0.21.0 + github.com/jackc/pgx/v5 v5.6.0 github.com/pganalyze/pg_query_go/v5 v5.1.0 - github.com/pingcap/tidb/pkg/parser v0.0.0-20240501024732-600b2ed4bf0a + github.com/pingcap/tidb/pkg/parser v0.0.0-20240813085716-bab3667b40fe github.com/stretchr/testify v1.9.0 - github.com/tetratelabs/wazero v1.7.1 - github.com/wasilibs/go-pgquery v0.0.0-20240319230125-b9b2e95c69a7 - modernc.org/sqlite v1.29.8 + github.com/tetratelabs/wazero v1.7.3 + github.com/urfave/cli/v2 v2.27.4 + github.com/wasilibs/go-pgquery v0.0.0-20240606042535-c0843d6592cc + modernc.org/sqlite v1.32.0 ) require ( filippo.io/edwards25519 v1.1.0 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect github.com/dustin/go-humanize v1.0.1 // indirect github.com/google/uuid v1.6.0 // indirect github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect github.com/jackc/puddle/v2 v2.2.1 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/ncruces/go-strftime v0.1.9 // indirect - github.com/pingcap/failpoint v0.0.0-20240412033321-fd0796e60f86 // indirect + github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/stoewer/go-strcase v1.3.0 // indirect - golang.org/x/net v0.24.0 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20240429193739-8cf5692501f6 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240429193739-8cf5692501f6 // indirect - modernc.org/gc/v3 v3.0.0-20240304020402-f0dba7c97c2b // indirect - modernc.org/libc v1.50.5 // indirect + github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52 // indirect + github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect + golang.org/x/net v0.28.0 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240812133136-8ffd90a71988 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240812133136-8ffd90a71988 // indirect + modernc.org/gc/v3 v3.0.0-20240801135723-a856999a2e4a // indirect + modernc.org/libc v1.59.3 // indirect modernc.org/mathutil v1.6.0 // indirect modernc.org/memory v1.8.0 // indirect modernc.org/strutil v1.2.0 // indirect @@ -66,14 +67,14 @@ require ( require ( github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548 // indirect github.com/go-ozzo/ozzo-validation/v4 v4.3.0 - github.com/goccy/go-json v0.10.2 // indirect + github.com/goccy/go-json v0.10.3 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jackc/chunkreader/v2 v2.0.1 // indirect github.com/jackc/pgconn v1.14.3 // indirect github.com/jackc/pgio v1.0.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgproto3/v2 v2.3.3 // indirect - github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect + github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect github.com/jackc/pgtype v1.14.3 // indirect github.com/pingcap/errors v0.11.5-0.20240311024730-e056997136bb // indirect github.com/pingcap/log v1.1.0 // indirect @@ -82,11 +83,11 @@ require ( go.uber.org/atomic v1.11.0 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.27.0 // indirect - golang.org/x/crypto v0.22.0 // indirect - golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect - golang.org/x/mod v0.17.0 // indirect - golang.org/x/sys v0.20.0 // indirect - golang.org/x/text v0.15.0 // indirect - google.golang.org/grpc v1.63.2 + golang.org/x/crypto v0.26.0 // indirect + golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa // indirect + golang.org/x/mod v0.20.0 // indirect + golang.org/x/sys v0.24.0 // indirect + golang.org/x/text v0.17.0 // indirect + google.golang.org/grpc v1.65.0 gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect ) diff --git a/go.sum b/go.sum index b0cd4a2..00b466b 100644 --- a/go.sum +++ b/go.sum @@ -2,12 +2,10 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= -github.com/a-h/templ v0.2.663 h1:aa0WMm27InkYHGjimcM7us6hJ6BLhg98ZbfaiDPyjHE= -github.com/a-h/templ v0.2.663/go.mod h1:SA7mtYwVEajbIXFRh3vKdYm/4FYyLQAtPH1+KxzGPA8= -github.com/a-h/templ v0.2.680 h1:TflYFucxp5rmOxAXB9Xy3+QHTk8s8xG9+nCT/cLzjeE= -github.com/a-h/templ v0.2.680/go.mod h1:NQGQOycaPKBxRB14DmAaeIpcGC1AOBPJEMO4ozS7m90= -github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI= -github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g= +github.com/a-h/templ v0.2.747 h1:D0dQ2lxC3W7Dxl6fxQ/1zZHBQslSkTSvl5FxP/CfdKg= +github.com/a-h/templ v0.2.747/go.mod h1:69ObQIbrcuwPCU32ohNaWce3Cb7qM5GMiqN1K+2yop4= +github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYWrPrQ= +github.com/antlr4-go/antlr/v4 v4.13.1/go.mod h1:GKmUxMtwp6ZgGwZSva4eWPC5mS6vUAmOABFgjdkM7Nw= github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496/go.mod h1:oGkLhpf+kjZl6xBf758TQhh5XrAeiJv/7FRz/2spLIg= github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so= github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= @@ -16,12 +14,9 @@ github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= -github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4= +github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= -github.com/cristalhq/acmd v0.12.0 h1:RdlKnxjN+txbQosg8p/TRNZ+J1Rdne43MVQZ1zDhGWk= -github.com/cristalhq/acmd v0.12.0/go.mod h1:LG5oa43pE/BbxtfMoImHCQN++0Su7dzipdgBjMCBVDQ= -github.com/cristalhq/flagx v0.5.0 h1:cVLROsf96hbyh+U7IWNpGG1DkRcLS1FZT+23QzOz0BM= -github.com/cristalhq/flagx v0.5.0/go.mod h1:E6nWhZ4OInKjevZjFJQj99xwgM3tWLs1vaMZrsDtdUA= github.com/cubicdaiya/gonp v1.0.4 h1:ky2uIAJh81WiLcGKBVD5R7KsM/36W6IqqTy6Bo6rGws= github.com/cubicdaiya/gonp v1.0.4/go.mod h1:iWGuP/7+JVTn02OWhRemVbMmG1DOUnmrGTYYACpOI0I= github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548 h1:iwZdTE0PVqJCos1vaoKsclOGD3ADKpshg3SRtYBbwso= @@ -42,13 +37,13 @@ github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqw github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gobeam/stringy v0.0.7 h1:TD8SfhedUoiANhW88JlJqfrMsihskIRpU/VTsHGnAps= github.com/gobeam/stringy v0.0.7/go.mod h1:W3620X9dJHf2FSZF5fRnWekHcHQjwmCz8ZQ2d1qloqE= -github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= -github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA= +github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw= github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/google/cel-go v0.20.1 h1:nDx9r8S3L4pE61eDdt8igGj8rf5kjYR3ILxWIpWNi84= -github.com/google/cel-go v0.20.1/go.mod h1:kWcIzTsPX0zmQ+H3TirHstLLf9ep5QTsZBN9u4dOYLg= +github.com/google/cel-go v0.21.0 h1:cl6uW/gxN+Hy50tNYvI691+sXxioCnstFzLp2WO4GCI= +github.com/google/cel-go v0.21.0/go.mod h1:rHUlWCcBKgyEk+eV03RPdZUekPp6YcJwV0FxuUksYxc= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= @@ -92,8 +87,8 @@ github.com/jackc/pgproto3/v2 v2.3.3 h1:1HLSx5H+tXR9pW3in3zaztoEwQYRC9SQaYUHjTSUO github.com/jackc/pgproto3/v2 v2.3.3/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E= github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= -github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 h1:L0QtFUgDarD7Fpv9jeVMgy/+Ec0mtnmYuImjTz6dtDA= -github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= github.com/jackc/pgtype v0.0.0-20190421001408-4ed0de4755e0/go.mod h1:hdSHsc1V01CGwFsrv11mJRHWJ6aifDLfdV3aVjFF0zg= github.com/jackc/pgtype v0.0.0-20190824184912-ab885b375b90/go.mod h1:KcahbBH1nCMSo2DXpzsoWOAfFkdEtEJpPbVLq8eE+mc= github.com/jackc/pgtype v0.0.0-20190828014616-a8802b16cc59/go.mod h1:MWlu30kVJrUS8lot6TQqcg7mtthZ9T0EoIBFiJcmcyw= @@ -108,8 +103,8 @@ github.com/jackc/pgx/v4 v4.12.1-0.20210724153913-640aa07df17c/go.mod h1:1QD0+tgS github.com/jackc/pgx/v4 v4.18.2/go.mod h1:Ey4Oru5tH5sB6tV7hDmfWFahwF15Eb7DNXlRKx2CkVw= github.com/jackc/pgx/v4 v4.18.3 h1:dE2/TrEsGX3RBprb3qryqSV9Y60iZN1C6i8IrmW9/BA= github.com/jackc/pgx/v4 v4.18.3/go.mod h1:Ey4Oru5tH5sB6tV7hDmfWFahwF15Eb7DNXlRKx2CkVw= -github.com/jackc/pgx/v5 v5.5.5 h1:amBjrZVmksIdNjxGW/IiIMzxMKZFelXbUoPNb+8sjQw= -github.com/jackc/pgx/v5 v5.5.5/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A= +github.com/jackc/pgx/v5 v5.6.0 h1:SWJzexBzPL5jb0GEsrPMLIsi/3jOo7RHlzTjcAeDrPY= +github.com/jackc/pgx/v5 v5.6.0/go.mod h1:DNZ/vlrUnhWCoFGxHAG8U2ljioxukquj7utPDgtQdTw= github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= @@ -142,22 +137,19 @@ github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU= -github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4= github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= github.com/pganalyze/pg_query_go/v5 v5.1.0 h1:MlxQqHZnvA3cbRQYyIrjxEjzo560P6MyTgtlaf3pmXg= github.com/pganalyze/pg_query_go/v5 v5.1.0/go.mod h1:FsglvxidZsVN+Ltw3Ai6nTgPVcK2BPukH3jCDEqc1Ug= github.com/pingcap/errors v0.11.0/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= -github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= github.com/pingcap/errors v0.11.5-0.20240311024730-e056997136bb h1:3pSi4EDG6hg0orE1ndHkXvX6Qdq2cZn8gAPir8ymKZk= github.com/pingcap/errors v0.11.5-0.20240311024730-e056997136bb/go.mod h1:X2r9ueLEUZgtx2cIogM0v4Zj5uvvzhuuiu7Pn8HzMPg= -github.com/pingcap/failpoint v0.0.0-20240412033321-fd0796e60f86 h1:3uFyQWvFeByY1OhhmXNP0nYbTXfAv3VRLByp26n1Ppc= -github.com/pingcap/failpoint v0.0.0-20240412033321-fd0796e60f86/go.mod h1:cv98q58yGEqg4gkB3e8n2+8MEW4fo3kPTz6EoQBMG4o= +github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86 h1:tdMsjOqUR7YXHoBitzdebTvOjs/swniBTOLy5XiMtuE= +github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86/go.mod h1:exzhVYca3WRtd6gclGNErRWb1qEgff3LYta0LvRmON4= github.com/pingcap/log v1.1.0 h1:ELiPxACz7vdo1qAvvaWJg1NrYFoY6gqAh/+Uo6aXdD8= github.com/pingcap/log v1.1.0/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4= -github.com/pingcap/tidb/pkg/parser v0.0.0-20240501024732-600b2ed4bf0a h1:v3VUCppFcaZHGvGW/OrSi6N/zQRzyKSoa6dy2e0za3M= -github.com/pingcap/tidb/pkg/parser v0.0.0-20240501024732-600b2ed4bf0a/go.mod h1:c/4la2yfv1vBYvtIG8WCDyDinLMDIUC5+zLRHiafY+Y= +github.com/pingcap/tidb/pkg/parser v0.0.0-20240813085716-bab3667b40fe h1:Bago2h09AcIxk+MocV+4Gg9oYYJxgKkKQHV76hEow64= +github.com/pingcap/tidb/pkg/parser v0.0.0-20240813085716-bab3667b40fe/go.mod h1:c/4la2yfv1vBYvtIG8WCDyDinLMDIUC5+zLRHiafY+Y= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -173,16 +165,16 @@ github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99 github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU= github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= -github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4= github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ= github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= -github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= -github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= +github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= +github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stoewer/go-strcase v1.3.0 h1:g0eASXYtp+yvN9fK8sH94oCIk0fau9uV1/ZdJ0AVEzs= @@ -202,12 +194,18 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/tetratelabs/wazero v1.7.1 h1:QtSfd6KLc41DIMpDYlJdoMc6k7QTN246DM2+n2Y/Dx8= -github.com/tetratelabs/wazero v1.7.1/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y= -github.com/tkcrm/modules v0.0.0-20240504201808-caa8f8d56cb5 h1:O8YyCQ7VqCF6fsuvKO3gAG7cpxhwxXSyR5YMzkUZyfU= -github.com/tkcrm/modules v0.0.0-20240504201808-caa8f8d56cb5/go.mod h1:CbN4fWFAXt35R0CeOpenJ1MziN8n19MV6fV0Di8RMfw= -github.com/wasilibs/go-pgquery v0.0.0-20240319230125-b9b2e95c69a7 h1:sqqLVb63En4uTKFKBWSJ7c1aIFonhM1yn35/+KchOf4= -github.com/wasilibs/go-pgquery v0.0.0-20240319230125-b9b2e95c69a7/go.mod h1:ZAUjWnxivykc22k0TKFZylOV0WlVQ9nWMExfGFIBuF4= +github.com/tetratelabs/wazero v1.7.3 h1:PBH5KVahrt3S2AHgEjKu4u+LlDbbk+nsGE3KLucy6Rw= +github.com/tetratelabs/wazero v1.7.3/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y= +github.com/tkcrm/modules v0.0.0-20240731155216-c9ed7e436ff1 h1:cZomRKs22mfHELK2WZL+FXfy69zJV0PuSbz/eKpq7dc= +github.com/tkcrm/modules v0.0.0-20240731155216-c9ed7e436ff1/go.mod h1:mIpm1ubYnE7msqBjHg4i3gNQ5IcGl3hz7AtEpCd7uBU= +github.com/urfave/cli/v2 v2.27.4 h1:o1owoI+02Eb+K107p27wEX9Bb8eqIoZCfLXloLUSWJ8= +github.com/urfave/cli/v2 v2.27.4/go.mod h1:m4QzxcD2qpra4z7WhzEGn74WZLViBnMpb1ToCAKdGRQ= +github.com/wasilibs/go-pgquery v0.0.0-20240606042535-c0843d6592cc h1:Hgim1Xgk1+viV7p0aZh9OOrMRfG+E4mGA+JsI2uB0+k= +github.com/wasilibs/go-pgquery v0.0.0-20240606042535-c0843d6592cc/go.mod h1:ah6UfXIl/oA0K3SbourB/UHggVJOBXwPZ2XudDmmFac= +github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52 h1:OvLBa8SqJnZ6P+mjlzc2K7PM22rRUPE1x32G9DTPrC4= +github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52/go.mod h1:jMeV4Vpbi8osrE/pKUxRZkVaA0EX7NZN0A9/oRzgpgY= +github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4= +github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= @@ -245,21 +243,19 @@ golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWP golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= golang.org/x/crypto v0.20.0/go.mod h1:Xwo95rrVNIoSMx9wa1JroENMToLWn3RNVrTBpLHgZPQ= -golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= -golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= -golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f h1:99ci1mjWVBWwJiEKYY6jWa4d2nTQVIEhZIptnrVb1XY= -golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f/go.mod h1:/lliqkxwWAhPjf5oSOIJup2XcqJaw8RGS6k3TGEc7GI= +golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= +golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= +golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa h1:ELnwvuAXPNtPk1TJRuGkI9fDTwym6AYBu0qzT8AcHdI= +golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= -golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0= +golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -268,16 +264,14 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= -golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= -golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= +golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= +golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -295,16 +289,14 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= -golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= +golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= -golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= @@ -314,10 +306,9 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= -golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= +golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= @@ -330,28 +321,26 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= -golang.org/x/tools v0.20.0 h1:hz/CVckiOxybQvFw6h7b/q80NTr9IUQb4s1IIzW7KNY= -golang.org/x/tools v0.20.0/go.mod h1:WvitBU7JJf6A4jOdg4S1tviW9bhUxkgeCui/0JHctQg= +golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24= +golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ= golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto/googleapis/api v0.0.0-20240429193739-8cf5692501f6 h1:DTJM0R8LECCgFeUwApvcEJHz85HLagW8uRENYxHh1ww= -google.golang.org/genproto/googleapis/api v0.0.0-20240429193739-8cf5692501f6/go.mod h1:10yRODfgim2/T8csjQsMPgZOMvtytXKTDRzH6HRGzRw= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240429193739-8cf5692501f6 h1:DujSIu+2tC9Ht0aPNA7jgj23Iq8Ewi5sgkQ++wdvonE= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240429193739-8cf5692501f6/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= -google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM= -google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA= +google.golang.org/genproto/googleapis/api v0.0.0-20240812133136-8ffd90a71988 h1:+/tmTy5zAieooKIXfzDm9KiA3Bv6JBwriRN9LY+yayk= +google.golang.org/genproto/googleapis/api v0.0.0-20240812133136-8ffd90a71988/go.mod h1:4+X6GvPs+25wZKbQq9qyAXrwIRExv7w0Ea6MgZLZiDM= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240812133136-8ffd90a71988 h1:V71AcdLZr2p8dC9dbOIMCpqi4EmRl8wUwnJzXXLmbmc= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240812133136-8ffd90a71988/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY= +google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc= +google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -google.golang.org/protobuf v1.34.0 h1:Qo/qEd2RZPCf2nKuorzksSknv0d3ERwp1vFG38gSmH4= -google.golang.org/protobuf v1.34.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= @@ -360,7 +349,6 @@ gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24 gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= @@ -369,18 +357,18 @@ gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= -modernc.org/cc/v4 v4.21.0 h1:D/gLKtcztomvWbsbvBKo3leKQv+86f+DdqEZBBXhnag= -modernc.org/cc/v4 v4.21.0/go.mod h1:HM7VJTZbUCR3rV8EYBi9wxnJ0ZBRiGE5OeGXNA0IsLQ= -modernc.org/ccgo/v4 v4.17.3 h1:t2CQci84jnxKw3GGnHvjGKjiNZeZqyQx/023spkk4hU= -modernc.org/ccgo/v4 v4.17.3/go.mod h1:1FCbAtWYJoKuc+AviS+dH+vGNtYmFJqBeRWjmnDWsIg= +modernc.org/cc/v4 v4.21.4 h1:3Be/Rdo1fpr8GrQ7IVw9OHtplU4gWbb+wNgeoBMmGLQ= +modernc.org/cc/v4 v4.21.4/go.mod h1:HM7VJTZbUCR3rV8EYBi9wxnJ0ZBRiGE5OeGXNA0IsLQ= +modernc.org/ccgo/v4 v4.20.7 h1:skrinQsjxWfvj6nbC3ztZPJy+NuwmB3hV9zX/pthNYQ= +modernc.org/ccgo/v4 v4.20.7/go.mod h1:UOkI3JSG2zT4E2ioHlncSOZsXbuDCZLvPi3uMlZT5GY= modernc.org/fileutil v1.3.0 h1:gQ5SIzK3H9kdfai/5x41oQiKValumqNTDXMvKo62HvE= modernc.org/fileutil v1.3.0/go.mod h1:XatxS8fZi3pS8/hKG2GH/ArUogfxjpEKs3Ku3aK4JyQ= -modernc.org/gc/v2 v2.4.1 h1:9cNzOqPyMJBvrUipmynX0ZohMhcxPtMccYgGOJdOiBw= -modernc.org/gc/v2 v2.4.1/go.mod h1:wzN5dK1AzVGoH6XOzc3YZ+ey/jPgYHLuVckd62P0GYU= -modernc.org/gc/v3 v3.0.0-20240304020402-f0dba7c97c2b h1:BnN1t+pb1cy61zbvSUV7SeI0PwosMhlAEi/vBY4qxp8= -modernc.org/gc/v3 v3.0.0-20240304020402-f0dba7c97c2b/go.mod h1:Qz0X07sNOR1jWYCrJMEnbW/X55x206Q7Vt4mz6/wHp4= -modernc.org/libc v1.50.5 h1:ZzeUd0dIc/sUtoPTCYIrgypkuzoGzNu6kbEWj2VuEmk= -modernc.org/libc v1.50.5/go.mod h1:rhzrUx5oePTSTIzBgM0mTftwWHK8tiT9aNFUt1mldl0= +modernc.org/gc/v2 v2.5.0 h1:bJ9ChznK1L1mUtAQtxi0wi5AtAs5jQuw4PrPHO5pb6M= +modernc.org/gc/v2 v2.5.0/go.mod h1:wzN5dK1AzVGoH6XOzc3YZ+ey/jPgYHLuVckd62P0GYU= +modernc.org/gc/v3 v3.0.0-20240801135723-a856999a2e4a h1:CfbpOLEo2IwNzJdMvE8aiRbPMxoTpgAJeyePh0SmO8M= +modernc.org/gc/v3 v3.0.0-20240801135723-a856999a2e4a/go.mod h1:Qz0X07sNOR1jWYCrJMEnbW/X55x206Q7Vt4mz6/wHp4= +modernc.org/libc v1.59.3 h1:A4QAp1lRSn2/b4aU+wBtq+yeKgq/2BUevrj0p1ZNy2M= +modernc.org/libc v1.59.3/go.mod h1:EY/egGEU7Ju66eU6SBqCNYaFUDuc4npICkMWnU5EE3A= modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4= modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWPo= modernc.org/memory v1.8.0 h1:IqGTL6eFMaDZZhEWwcREgeMXYwmW83LYW8cROZYkg+E= @@ -389,8 +377,8 @@ modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4= modernc.org/opt v0.1.3/go.mod h1:WdSiB5evDcignE70guQKxYUl14mgWtbClRi5wmkkTX0= modernc.org/sortutil v1.2.0 h1:jQiD3PfS2REGJNzNCMMaLSp/wdMNieTbKX920Cqdgqc= modernc.org/sortutil v1.2.0/go.mod h1:TKU2s7kJMf1AE84OoiGppNHJwvB753OYfNl2WRb++Ss= -modernc.org/sqlite v1.29.8 h1:nGKglNx9K5v0As+zF0/Gcl1kMkmaU1XynYyq92PbsC8= -modernc.org/sqlite v1.29.8/go.mod h1:lQPm27iqa4UNZpmr4Aor0MH0HkCLbt1huYDfWylLZFk= +modernc.org/sqlite v1.32.0 h1:6BM4uGza7bWypsw4fdLRsLxut6bHe4c58VeqjRgST8s= +modernc.org/sqlite v1.32.0/go.mod h1:UqoylwmTb9F+IqXERT8bW9zzOWN8qwAIcLdzeBZs4hA= modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA= modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0= modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y= diff --git a/internal/assets/templates/constants_templ.go b/internal/assets/templates/constants_templ.go index e4ba4f3..c4fcc6b 100644 --- a/internal/assets/templates/constants_templ.go +++ b/internal/assets/templates/constants_templ.go @@ -1,14 +1,12 @@ // Code generated by templ - DO NOT EDIT. -// templ: version: v0.2.680 +// templ: version: v0.2.747 package templates //lint:file-ignore SA4006 This context is only used if a nested component is present. import "github.com/a-h/templ" -import "context" -import "io" -import "bytes" +import templruntime "github.com/a-h/templ/runtime" import ( "fmt" @@ -116,11 +114,16 @@ func (s ColumnNames) Strings() []string { } func Constatnts(p ConstantsParams) templ.Component { - return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { - templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) + return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { + templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context + templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) if !templ_7745c5c3_IsBuffer { - templ_7745c5c3_Buffer = templ.GetBuffer() - defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) + defer func() { + templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) + if templ_7745c5c3_Err == nil { + templ_7745c5c3_Err = templ_7745c5c3_BufErr + } + }() } ctx = templ.InitializeContext(ctx) templ_7745c5c3_Var1 := templ.GetChildren(ctx) @@ -144,9 +147,6 @@ func Constatnts(p ConstantsParams) templ.Component { return templ_7745c5c3_Err } } - if !templ_7745c5c3_IsBuffer { - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) - } return templ_7745c5c3_Err }) } diff --git a/internal/crud/cmd.go b/internal/crud/cmd.go index 9209dc1..fdcd814 100644 --- a/internal/crud/cmd.go +++ b/internal/crud/cmd.go @@ -1,15 +1,12 @@ package crud import ( - "context" - "github.com/tkcrm/pgxgen/internal/config" "github.com/tkcrm/pgxgen/pkg/logger" + "github.com/urfave/cli/v2" ) -func CmdFunc(l logger.Logger, cfg config.Config) func(ctx context.Context, args []string) error { - return func(ctx context.Context, args []string) error { - cfg.CheckErrors(l) - return New(l, cfg).Generate(ctx, args) - } +func CmdFunc(c *cli.Context, l logger.Logger, cfg config.Config) error { + cfg.CheckErrors(l) + return New(l, cfg).Generate(c.Context, c.Args().Slice()) } diff --git a/internal/gomodels/cmd.go b/internal/gomodels/cmd.go index 164dabf..9102a78 100644 --- a/internal/gomodels/cmd.go +++ b/internal/gomodels/cmd.go @@ -1,15 +1,12 @@ package gomodels import ( - "context" - "github.com/tkcrm/pgxgen/internal/config" "github.com/tkcrm/pgxgen/pkg/logger" + "github.com/urfave/cli/v2" ) -func CmdFunc(l logger.Logger, cfg config.Config) func(ctx context.Context, args []string) error { - return func(ctx context.Context, args []string) error { - cfg.CheckErrors(l) - return New(l, cfg).Generate(ctx, args) - } +func CmdFunc(c *cli.Context, l logger.Logger, cfg config.Config) error { + cfg.CheckErrors(l) + return New(l, cfg).Generate(c.Context, c.Args().Slice()) } diff --git a/internal/gomodels/gomodels.go b/internal/gomodels/gomodels.go index f94317e..9f59533 100644 --- a/internal/gomodels/gomodels.go +++ b/internal/gomodels/gomodels.go @@ -146,7 +146,7 @@ func (s *gomodels) generateModels(cfg config.GenModels) error { return fmt.Errorf("processStructs error: %w", err) } - if err := s.compileGoModels(config, _structs, filePath); err != nil { + if err := s.compileGoModels(config, _structs); err != nil { return fmt.Errorf("compileGoModels error: %w", err) } @@ -403,7 +403,7 @@ func (s *gomodels) processStructs(c config.GenModels, st *structs.Structs) error return nil } -func (s *gomodels) compileGoModels(c config.GenModels, st structs.Structs, path string) error { +func (s *gomodels) compileGoModels(c config.GenModels, st structs.Structs) error { if c.OutputDir == "" { return fmt.Errorf("config error: undefined output_dir") } diff --git a/internal/keystone/cmd.go b/internal/keystone/cmd.go index ec86769..451463a 100644 --- a/internal/keystone/cmd.go +++ b/internal/keystone/cmd.go @@ -1,15 +1,12 @@ package keystone import ( - "context" - "github.com/tkcrm/pgxgen/internal/config" "github.com/tkcrm/pgxgen/pkg/logger" + "github.com/urfave/cli/v2" ) -func CmdFunc(l logger.Logger, cfg config.Config) func(ctx context.Context, args []string) error { - return func(ctx context.Context, args []string) error { - cfg.CheckErrors(l) - return New(l, cfg).Generate(ctx, args) - } +func CmdFunc(c *cli.Context, l logger.Logger, cfg config.Config) error { + cfg.CheckErrors(l) + return New(l, cfg).Generate(c.Context, c.Args().Slice()) } diff --git a/internal/sqlc/cmd.go b/internal/sqlc/cmd.go index 1c599ca..9462fcc 100644 --- a/internal/sqlc/cmd.go +++ b/internal/sqlc/cmd.go @@ -1,15 +1,12 @@ package sqlc import ( - "context" - "github.com/tkcrm/pgxgen/internal/config" "github.com/tkcrm/pgxgen/pkg/logger" + "github.com/urfave/cli/v2" ) -func CmdFunc(l logger.Logger, cfg config.Config) func(ctx context.Context, args []string) error { - return func(ctx context.Context, args []string) error { - cfg.CheckErrors(l) - return New(l, cfg).Generate(ctx, args) - } +func CmdFunc(c *cli.Context, l logger.Logger, cfg config.Config) error { + cfg.CheckErrors(l) + return New(l, cfg).Generate(c.Context, c.Args().Slice()) } diff --git a/internal/typescript/cmd.go b/internal/typescript/cmd.go index 875fa11..ae6bb1a 100644 --- a/internal/typescript/cmd.go +++ b/internal/typescript/cmd.go @@ -1,15 +1,12 @@ package typescript import ( - "context" - "github.com/tkcrm/pgxgen/internal/config" "github.com/tkcrm/pgxgen/pkg/logger" + "github.com/urfave/cli/v2" ) -func CmdFunc(l logger.Logger, cfg config.Config) func(ctx context.Context, args []string) error { - return func(ctx context.Context, args []string) error { - cfg.CheckErrors(l) - return New(l, cfg).Generate(ctx, args) - } +func CmdFunc(c *cli.Context, l logger.Logger, cfg config.Config) error { + cfg.CheckErrors(l) + return New(l, cfg).Generate(c.Context, c.Args().Slice()) } diff --git a/internal/typescript/typescript.go b/internal/typescript/typescript.go index 0afaea5..3e90faf 100644 --- a/internal/typescript/typescript.go +++ b/internal/typescript/typescript.go @@ -39,11 +39,11 @@ type tmplTypescriptCtx struct { ExportTypeSuffix string } -func (s *typescript) Generate(_ context.Context, args []string) error { +func (s *typescript) Generate(_ context.Context, _ []string) error { s.logger.Infof("generate typescript code") timeStart := time.Now() - if err := s.generateTypescript(args); err != nil { + if err := s.generateTypescript(); err != nil { return err } @@ -52,7 +52,7 @@ func (s *typescript) Generate(_ context.Context, args []string) error { return nil } -func (s *typescript) generateTypescript(args []string) error { +func (s *typescript) generateTypescript() error { for _, config := range s.config.Pgxgen.GenTypescriptFromStructs { if config.OutputDir == "" { return fmt.Errorf("output dir is empty") @@ -149,7 +149,7 @@ func (s *typescript) compileTypescript(c config.GenTypescriptFromStructs, st str return strings.Contains(t, "*") }) tpl.AddFunc("getType", func(t string) string { - return getTypescriptType(st, t) + return getTypescriptType(t) }) // tmpl := template.Must( @@ -211,7 +211,7 @@ func (s *typescript) compileTypescript(c config.GenTypescriptFromStructs, st str return nil } -func getTypescriptType(st structs.StructSlice, t string) (tp string) { +func getTypescriptType(t string) (tp string) { t = strings.ReplaceAll(t, "*", "") tp = "" diff --git a/internal/ver/cmd.go b/internal/ver/cmd.go index 10a4aa2..d0388db 100644 --- a/internal/ver/cmd.go +++ b/internal/ver/cmd.go @@ -1,26 +1,24 @@ package ver import ( - "context" "fmt" "github.com/tkcrm/pgxgen/internal/config" "github.com/tkcrm/pgxgen/pkg/logger" + "github.com/urfave/cli/v2" ) -func CmdFunc(l logger.Logger, cfg config.Config) func(ctx context.Context, args []string) error { - return func(ctx context.Context, args []string) error { - resp, err := CheckLastestReleaseVersion(ctx, cfg.Pgxgen.Version) - if err != nil { - return fmt.Errorf("check latest release version error: %s", err) - } - - if resp != nil && !resp.IsLatest { - l.Info(resp.Message) - } else { - l.Info("Congratulations! You are using the latest version") - } +func CmdFunc(c *cli.Context, l logger.Logger, cfg config.Config) error { + resp, err := CheckLastestReleaseVersion(c.Context, cfg.Pgxgen.Version) + if err != nil { + return fmt.Errorf("check latest release version error: %s", err) + } - return nil + if resp != nil && !resp.IsLatest { + l.Info(resp.Message) + } else { + l.Info("Congratulations! You are using the latest version") } + + return nil } diff --git a/pkg/logger/types.go b/pkg/logger/types.go index 26021a5..a8b7879 100644 --- a/pkg/logger/types.go +++ b/pkg/logger/types.go @@ -6,23 +6,11 @@ import ( ) type Logger interface { - // Debug(...any) - // Debugf(template string, args ...any) - Info(...any) Infof(template string, args ...any) - // Warn(...any) - // Warnf(template string, args ...any) - - // Error(...any) - // Errorf(template string, args ...any) - Fatal(...any) Fatalf(template string, args ...any) - - // Panic(...any) - // Panicf(template string, args ...any) } type logger struct { diff --git a/pkg/sqlc/cmd/cmd.go b/pkg/sqlc/cmd/cmd.go index 7319c32..a2d4425 100644 --- a/pkg/sqlc/cmd/cmd.go +++ b/pkg/sqlc/cmd/cmd.go @@ -149,7 +149,7 @@ func ParseEnv(c *cobra.Command) Env { return Env{ DryRun: dr != nil && dr.Changed, Debug: opts.DebugFromEnv(), - Remote: r != nil && nr.Value.String() == "true", + Remote: r != nil && r.Value.String() == "true", NoRemote: nr != nil && nr.Value.String() == "true", } } diff --git a/pkg/sqlc/cmd/createdb.go b/pkg/sqlc/cmd/createdb.go index 7bfdee2..65e5406 100644 --- a/pkg/sqlc/cmd/createdb.go +++ b/pkg/sqlc/cmd/createdb.go @@ -5,12 +5,12 @@ import ( "fmt" "os" "runtime/trace" + "time" "github.com/spf13/cobra" "github.com/tkcrm/pgxgen/pkg/sqlc/config" + "github.com/tkcrm/pgxgen/pkg/sqlc/dbmanager" "github.com/tkcrm/pgxgen/pkg/sqlc/migrations" - "github.com/tkcrm/pgxgen/pkg/sqlc/quickdb" - pb "github.com/tkcrm/pgxgen/pkg/sqlc/quickdb/v1" "github.com/tkcrm/pgxgen/pkg/sqlc/sql/sqlpath" ) @@ -88,20 +88,16 @@ func CreateDB(ctx context.Context, dir, filename, querySetName string, o *Option ddl = append(ddl, migrations.RemoveRollbackStatements(string(contents))) } - client, err := quickdb.NewClientFromConfig(conf.Cloud) - if err != nil { - return fmt.Errorf("client error: %w", err) - } - - resp, err := client.CreateEphemeralDatabase(ctx, &pb.CreateEphemeralDatabaseRequest{ + now := time.Now().UTC().UnixNano() + client := dbmanager.NewClient(conf.Servers) + resp, err := client.CreateDatabase(ctx, &dbmanager.CreateDatabaseRequest{ Engine: string(queryset.Engine), - Region: quickdb.GetClosestRegion(), Migrations: ddl, + Prefix: fmt.Sprintf("sqlc_createdb_%d", now), }) if err != nil { return fmt.Errorf("managed: create database: %w", err) } - fmt.Fprintln(os.Stderr, "WARNING: This database will be removed in two minutes") fmt.Println(resp.Uri) return nil } diff --git a/pkg/sqlc/cmd/options.go b/pkg/sqlc/cmd/options.go index 35bcbd4..ed8fcd2 100644 --- a/pkg/sqlc/cmd/options.go +++ b/pkg/sqlc/cmd/options.go @@ -7,12 +7,14 @@ import ( ) type Options struct { - Env Env - Stderr io.Writer - MutateConfig func(*config.Config) + Env Env + Stderr io.Writer // TODO: Move these to a command-specific struct Tags []string Against string + + // Testing only + MutateConfig func(*config.Config) } func (o *Options) ReadConfig(dir, filename string) (string, *config.Config, error) { diff --git a/pkg/sqlc/cmd/verify.go b/pkg/sqlc/cmd/verify.go index 7e18420..74d3e7e 100644 --- a/pkg/sqlc/cmd/verify.go +++ b/pkg/sqlc/cmd/verify.go @@ -2,14 +2,23 @@ package cmd import ( "context" + "database/sql" + "errors" "fmt" + "log/slog" "os" + _ "github.com/jackc/pgx/v5/stdlib" "github.com/spf13/cobra" + "google.golang.org/protobuf/proto" - "github.com/tkcrm/pgxgen/pkg/sqlc/bundler" + "github.com/tkcrm/pgxgen/pkg/sqlc/config" + "github.com/tkcrm/pgxgen/pkg/sqlc/dbmanager" + "github.com/tkcrm/pgxgen/pkg/sqlc/migrations" + "github.com/tkcrm/pgxgen/pkg/sqlc/plugin" "github.com/tkcrm/pgxgen/pkg/sqlc/quickdb" - quickdbv1 "github.com/tkcrm/pgxgen/pkg/sqlc/quickdb/v1" + pb "github.com/tkcrm/pgxgen/pkg/sqlc/quickdb/v1" + "github.com/tkcrm/pgxgen/pkg/sqlc/sql/sqlpath" ) func init() { @@ -32,7 +41,7 @@ var verifyCmd = &cobra.Command{ Against: against, } if err := Verify(cmd.Context(), dir, name, opts); err != nil { - fmt.Fprintf(stderr, "error verifying: %s\n", err) + fmt.Fprintf(stderr, "Error verifying queries: %s\n", err) os.Exit(1) } return nil @@ -41,50 +50,107 @@ var verifyCmd = &cobra.Command{ func Verify(ctx context.Context, dir, filename string, opts *Options) error { stderr := opts.Stderr - configPath, conf, err := readConfig(stderr, dir, filename) + _, conf, err := readConfig(stderr, dir, filename) if err != nil { return err } + client, err := quickdb.NewClientFromConfig(conf.Cloud) if err != nil { return fmt.Errorf("client init failed: %w", err) } - p := &pusher{} - if err := Process(ctx, p, dir, filename, opts); err != nil { - return err - } - req, err := bundler.BuildRequest(ctx, dir, configPath, p.results, nil) - if err != nil { - return err - } - if val := os.Getenv("CI"); val != "" { - req.Annotations["env.ci"] = val - } - if val := os.Getenv("GITHUB_RUN_ID"); val != "" { - req.Annotations["github.run.id"] = val - } - resp, err := client.VerifyQuerySets(ctx, &quickdbv1.VerifyQuerySetsRequest{ - Against: opts.Against, - SqlcVersion: req.SqlcVersion, - QuerySets: req.QuerySets, - Config: req.Config, - Annotations: req.Annotations, + manager := dbmanager.NewClient(conf.Servers) + + // Get query sets from a previous archive by tag. If no tag is provided, get + // the latest query sets. + previous, err := client.GetQuerySets(ctx, &pb.GetQuerySetsRequest{ + Tag: opts.Against, }) if err != nil { return err } - summaryPath := os.Getenv("GITHUB_STEP_SUMMARY") - if resp.Summary != "" { - if _, err := os.Stat(summaryPath); err == nil { - if err := os.WriteFile(summaryPath, []byte(resp.Summary), 0644); err != nil { + + // Create a mapping of name to query set + existing := map[string]config.SQL{} + for _, qs := range conf.SQL { + existing[qs.Name] = qs + } + + var verr error + for _, qs := range previous.QuerySets { + // TODO: Create a function for this so that we can return early on errors + + check := func() error { + if qs.Name == "" { + return fmt.Errorf("unnamed query set") + } + + current, found := existing[qs.Name] + if !found { + return fmt.Errorf("unknown query set: %s", qs.Name) + } + + // Read the schema files into memory, removing rollback statements + var ddl []string + files, err := sqlpath.Glob(current.Schema) + if err != nil { return err } + for _, schema := range files { + contents, err := os.ReadFile(schema) + if err != nil { + return fmt.Errorf("read file: %w", err) + } + ddl = append(ddl, migrations.RemoveRollbackStatements(string(contents))) + } + + var codegen plugin.GenerateRequest + if err := proto.Unmarshal(qs.CodegenRequest.Contents, &codegen); err != nil { + return err + } + + // Create (or re-use) a database to verify against + resp, err := manager.CreateDatabase(ctx, &dbmanager.CreateDatabaseRequest{ + Engine: string(current.Engine), + Migrations: ddl, + }) + if err != nil { + return err + } + + db, err := sql.Open("pgx", resp.Uri) + if err != nil { + return err + } + defer db.Close() + + var qerr error + for _, query := range codegen.Queries { + stmt, err := db.PrepareContext(ctx, query.Text) + if err != nil { + fmt.Fprintf(stderr, "Failed to prepare the following query:\n") + fmt.Fprintf(stderr, "%s\n", query.Text) + fmt.Fprintf(stderr, "Error was: %s\n", err) + qerr = err + continue + } + if err := stmt.Close(); err != nil { + slog.Error("stmt.Close failed", "err", err) + } + } + + return qerr + } + + if err := check(); err != nil { + verr = errors.New("errored") + fmt.Fprintf(stderr, "FAIL\t%s\n", qs.Name) + fmt.Fprintf(stderr, " ERROR\t%s\n", err) + } else { + fmt.Fprintf(stderr, "ok\t%s\n", qs.Name) } } - fmt.Fprintf(stderr, resp.Output) - if resp.Errored { - return fmt.Errorf("BREAKING CHANGES DETECTED") - } - return nil + + return verr } diff --git a/pkg/sqlc/cmd/vet.go b/pkg/sqlc/cmd/vet.go index aa6abd8..8652705 100644 --- a/pkg/sqlc/cmd/vet.go +++ b/pkg/sqlc/cmd/vet.go @@ -22,12 +22,12 @@ import ( "google.golang.org/protobuf/encoding/protojson" "github.com/tkcrm/pgxgen/pkg/sqlc/config" + "github.com/tkcrm/pgxgen/pkg/sqlc/dbmanager" "github.com/tkcrm/pgxgen/pkg/sqlc/debug" "github.com/tkcrm/pgxgen/pkg/sqlc/migrations" "github.com/tkcrm/pgxgen/pkg/sqlc/opts" "github.com/tkcrm/pgxgen/pkg/sqlc/plugin" "github.com/tkcrm/pgxgen/pkg/sqlc/quickdb" - pb "github.com/tkcrm/pgxgen/pkg/sqlc/quickdb/v1" "github.com/tkcrm/pgxgen/pkg/sqlc/shfmt" "github.com/tkcrm/pgxgen/pkg/sqlc/sql/sqlpath" "github.com/tkcrm/pgxgen/pkg/sqlc/vet" @@ -386,7 +386,7 @@ type checker struct { Env *cel.Env Stderr io.Writer OnlyManagedDB bool - Client pb.QuickClient + Client dbmanager.Client Replacer *shfmt.Replacer } @@ -405,10 +405,7 @@ func (c *checker) fetchDatabaseUri(ctx context.Context, s config.SQL) (string, f if c.Client == nil { // FIXME: Eventual race condition - client, err := quickdb.NewClientFromConfig(c.Conf.Cloud) - if err != nil { - return "", cleanup, fmt.Errorf("managed: client: %w", err) - } + client := dbmanager.NewClient(c.Conf.Servers) c.Client = client } @@ -425,22 +422,14 @@ func (c *checker) fetchDatabaseUri(ctx context.Context, s config.SQL) (string, f ddl = append(ddl, migrations.RemoveRollbackStatements(string(contents))) } - resp, err := c.Client.CreateEphemeralDatabase(ctx, &pb.CreateEphemeralDatabaseRequest{ + resp, err := c.Client.CreateDatabase(ctx, &dbmanager.CreateDatabaseRequest{ Engine: string(s.Engine), - Region: quickdb.GetClosestRegion(), Migrations: ddl, }) if err != nil { return "", cleanup, fmt.Errorf("managed: create database: %w", err) } - cleanup = func() error { - _, err := c.Client.DropEphemeralDatabase(ctx, &pb.DropEphemeralDatabaseRequest{ - DatabaseId: resp.DatabaseId, - }) - return err - } - var uri string switch s.Engine { case config.EngineMySQL: diff --git a/pkg/sqlc/codegen/golang/result.go b/pkg/sqlc/codegen/golang/result.go index f21cdbe..2e93d66 100644 --- a/pkg/sqlc/codegen/golang/result.go +++ b/pkg/sqlc/codegen/golang/result.go @@ -259,7 +259,9 @@ func buildQueries(req *plugin.GenerateRequest, options *opts.Options, structs [] EmitPointer: options.EmitParamsStructPointers, } - if len(query.Params) <= qpl { + // if query params is 2, and query params limit is 4 AND this is a copyfrom, we still want to emit the query's model + // otherwise we end up with a copyfrom using a struct without the struct definition + if len(query.Params) <= qpl && query.Cmd != ":copyfrom" { gq.Arg.Emit = false } } diff --git a/pkg/sqlc/codegen/golang/templates/go-sql-driver-mysql/copyfromCopy.tmpl b/pkg/sqlc/codegen/golang/templates/go-sql-driver-mysql/copyfromCopy.tmpl index e6b9061..e21475b 100644 --- a/pkg/sqlc/codegen/golang/templates/go-sql-driver-mysql/copyfromCopy.tmpl +++ b/pkg/sqlc/codegen/golang/templates/go-sql-driver-mysql/copyfromCopy.tmpl @@ -9,11 +9,11 @@ func convertRowsFor{{.MethodName}}(w *io.PipeWriter, {{.Arg.SlicePair}}) { {{- with $arg := .Arg }} {{- range $arg.CopyFromMySQLFields}} {{- if eq .Type "string"}} - e.AppendString({{if eq (len $arg.CopyFromMySQLFields) 1}}row{{else}}row.{{.Name}}{{end}}) + e.AppendString({{if $arg.Struct}}row.{{.Name}}{{else}}row{{end}}) {{- else if or (eq .Type "[]byte") (eq .Type "json.RawMessage")}} - e.AppendBytes({{if eq (len $arg.CopyFromMySQLFields) 1}}row{{else}}row.{{.Name}}{{end}}) + e.AppendBytes({{if $arg.Struct}}row.{{.Name}}{{else}}row{{end}}) {{- else}} - e.AppendValue({{if eq (len $arg.CopyFromMySQLFields) 1}}row{{else}}row.{{.Name}}{{end}}) + e.AppendValue({{if $arg.Struct}}row.{{.Name}}{{else}}row{{end}}) {{- end}} {{- end}} {{- end}} diff --git a/pkg/sqlc/compiler/engine.go b/pkg/sqlc/compiler/engine.go index 154c505..883befb 100644 --- a/pkg/sqlc/compiler/engine.go +++ b/pkg/sqlc/compiler/engine.go @@ -6,13 +6,12 @@ import ( "github.com/tkcrm/pgxgen/pkg/sqlc/analyzer" "github.com/tkcrm/pgxgen/pkg/sqlc/config" + "github.com/tkcrm/pgxgen/pkg/sqlc/dbmanager" "github.com/tkcrm/pgxgen/pkg/sqlc/engine/dolphin" "github.com/tkcrm/pgxgen/pkg/sqlc/engine/postgresql" pganalyze "github.com/tkcrm/pgxgen/pkg/sqlc/engine/postgresql/analyzer" "github.com/tkcrm/pgxgen/pkg/sqlc/engine/sqlite" "github.com/tkcrm/pgxgen/pkg/sqlc/opts" - "github.com/tkcrm/pgxgen/pkg/sqlc/quickdb" - pb "github.com/tkcrm/pgxgen/pkg/sqlc/quickdb/v1" "github.com/tkcrm/pgxgen/pkg/sqlc/sql/catalog" ) @@ -23,7 +22,7 @@ type Compiler struct { parser Parser result *Result analyzer analyzer.Analyzer - client pb.QuickClient + client dbmanager.Client schema []string } @@ -32,10 +31,7 @@ func NewCompiler(conf config.SQL, combo config.CombinedSettings) (*Compiler, err c := &Compiler{conf: conf, combo: combo} if conf.Database != nil && conf.Database.Managed { - client, err := quickdb.NewClientFromConfig(combo.Global.Cloud) - if err != nil { - return nil, fmt.Errorf("client error: %w", err) - } + client := dbmanager.NewClient(combo.Global.Servers) c.client = client } @@ -89,4 +85,7 @@ func (c *Compiler) Close(ctx context.Context) { if c.analyzer != nil { c.analyzer.Close(ctx) } + if c.client != nil { + c.client.Close(ctx) + } } diff --git a/pkg/sqlc/config/config.go b/pkg/sqlc/config/config.go index ac20c92..4631522 100644 --- a/pkg/sqlc/config/config.go +++ b/pkg/sqlc/config/config.go @@ -59,6 +59,7 @@ const ( type Config struct { Version string `json:"version" yaml:"version"` Cloud Cloud `json:"cloud" yaml:"cloud"` + Servers []Server `json:"servers" yaml:"servers"` SQL []SQL `json:"sql" yaml:"sql"` Overrides Overrides `json:"overrides,omitempty" yaml:"overrides"` Plugins []Plugin `json:"plugins" yaml:"plugins"` @@ -66,6 +67,12 @@ type Config struct { Options map[string]yaml.Node `json:"options" yaml:"options"` } +type Server struct { + Name string `json:"name,omitempty" yaml:"name"` + Engine Engine `json:"engine,omitempty" yaml:"engine"` + URI string `json:"uri" yaml:"uri"` +} + type Database struct { URI string `json:"uri" yaml:"uri"` Managed bool `json:"managed" yaml:"managed"` diff --git a/pkg/sqlc/dbmanager/client.go b/pkg/sqlc/dbmanager/client.go new file mode 100644 index 0000000..89dfda7 --- /dev/null +++ b/pkg/sqlc/dbmanager/client.go @@ -0,0 +1,150 @@ +package dbmanager + +import ( + "context" + "fmt" + "hash/fnv" + "io" + "net/url" + "strings" + + "github.com/jackc/pgx/v5" + "golang.org/x/sync/singleflight" + + "github.com/tkcrm/pgxgen/pkg/sqlc/config" + "github.com/tkcrm/pgxgen/pkg/sqlc/pgx/poolcache" + "github.com/tkcrm/pgxgen/pkg/sqlc/shfmt" +) + +type CreateDatabaseRequest struct { + Engine string + Migrations []string + Prefix string +} + +type CreateDatabaseResponse struct { + Uri string +} + +type Client interface { + CreateDatabase(context.Context, *CreateDatabaseRequest) (*CreateDatabaseResponse, error) + Close(context.Context) +} + +var flight singleflight.Group + +type ManagedClient struct { + cache *poolcache.Cache + replacer *shfmt.Replacer + servers []config.Server +} + +func dbid(migrations []string) string { + h := fnv.New64() + for _, query := range migrations { + io.WriteString(h, query) + } + return fmt.Sprintf("%x", h.Sum(nil)) +} + +func (m *ManagedClient) CreateDatabase(ctx context.Context, req *CreateDatabaseRequest) (*CreateDatabaseResponse, error) { + hash := dbid(req.Migrations) + prefix := req.Prefix + if prefix == "" { + prefix = "sqlc_managed" + } + name := fmt.Sprintf("%s_%s", prefix, hash) + + engine := config.Engine(req.Engine) + switch engine { + case config.EngineMySQL: + // pass + case config.EnginePostgreSQL: + // pass + default: + return nil, fmt.Errorf("unsupported engine: %s", engine) + } + + var base string + for _, server := range m.servers { + if server.Engine == engine { + base = server.URI + break + } + } + + if strings.TrimSpace(base) == "" { + return nil, fmt.Errorf("no PostgreSQL database server found") + } + + serverUri := m.replacer.Replace(base) + pool, err := m.cache.Open(ctx, serverUri) + if err != nil { + return nil, err + } + + uri, err := url.Parse(serverUri) + if err != nil { + return nil, err + } + uri.Path = "/" + name + + key := uri.String() + _, err, _ = flight.Do(key, func() (interface{}, error) { + // TODO: Use a parameterized query + row := pool.QueryRow(ctx, + fmt.Sprintf(`SELECT datname FROM pg_database WHERE datname = '%s'`, name)) + + var datname string + if err := row.Scan(&datname); err == nil { + return nil, nil + } + + if _, err := pool.Exec(ctx, fmt.Sprintf(`CREATE DATABASE "%s"`, name)); err != nil { + return nil, err + } + + conn, err := pgx.Connect(ctx, uri.String()) + if err != nil { + pool.Exec(ctx, fmt.Sprintf(`DROP DATABASE "%s" IF EXISTS WITH (FORCE)`, name)) + return nil, fmt.Errorf("connect %s: %s", name, err) + } + defer conn.Close(ctx) + + var migrationErr error + for _, q := range req.Migrations { + if len(strings.TrimSpace(q)) == 0 { + continue + } + if _, err := conn.Exec(ctx, q); err != nil { + migrationErr = fmt.Errorf("%s: %s", q, err) + break + } + } + + if migrationErr != nil { + pool.Exec(ctx, fmt.Sprintf(`DROP DATABASE "%s" IF EXISTS WITH (FORCE)`, name)) + return nil, migrationErr + } + + return nil, nil + }) + + if err != nil { + return nil, err + } + + return &CreateDatabaseResponse{Uri: key}, err +} + +func (m *ManagedClient) Close(ctx context.Context) { + m.cache.Close() +} + +func NewClient(servers []config.Server) *ManagedClient { + return &ManagedClient{ + cache: poolcache.New(), + servers: servers, + replacer: shfmt.NewReplacer(nil), + } +} diff --git a/pkg/sqlc/engine/postgresql/analyzer/analyze.go b/pkg/sqlc/engine/postgresql/analyzer/analyze.go index a0a2ec7..d344e16 100644 --- a/pkg/sqlc/engine/postgresql/analyzer/analyze.go +++ b/pkg/sqlc/engine/postgresql/analyzer/analyze.go @@ -13,8 +13,8 @@ import ( core "github.com/tkcrm/pgxgen/pkg/sqlc/analysis" "github.com/tkcrm/pgxgen/pkg/sqlc/config" + "github.com/tkcrm/pgxgen/pkg/sqlc/dbmanager" "github.com/tkcrm/pgxgen/pkg/sqlc/opts" - pb "github.com/tkcrm/pgxgen/pkg/sqlc/quickdb/v1" "github.com/tkcrm/pgxgen/pkg/sqlc/shfmt" "github.com/tkcrm/pgxgen/pkg/sqlc/sql/ast" "github.com/tkcrm/pgxgen/pkg/sqlc/sql/named" @@ -23,7 +23,7 @@ import ( type Analyzer struct { db config.Database - client pb.QuickClient + client dbmanager.Client pool *pgxpool.Pool dbg opts.Debug replacer *shfmt.Replacer @@ -32,7 +32,7 @@ type Analyzer struct { tables sync.Map } -func New(client pb.QuickClient, db config.Database) *Analyzer { +func New(client dbmanager.Client, db config.Database) *Analyzer { return &Analyzer{ db: db, dbg: opts.DebugFromEnv(), @@ -201,7 +201,7 @@ func (a *Analyzer) Analyze(ctx context.Context, n ast.Node, query string, migrat if a.client == nil { return nil, fmt.Errorf("client is nil") } - edb, err := a.client.CreateEphemeralDatabase(ctx, &pb.CreateEphemeralDatabaseRequest{ + edb, err := a.client.CreateDatabase(ctx, &dbmanager.CreateDatabaseRequest{ Engine: "postgresql", Migrations: migrations, }) diff --git a/pkg/sqlc/engine/postgresql/parse_default.go b/pkg/sqlc/engine/postgresql/parse_default.go index 3f802cc..6fdd106 100644 --- a/pkg/sqlc/engine/postgresql/parse_default.go +++ b/pkg/sqlc/engine/postgresql/parse_default.go @@ -1,5 +1,4 @@ //go:build !windows && cgo -// +build !windows,cgo package postgresql diff --git a/pkg/sqlc/engine/postgresql/parse_wasi.go b/pkg/sqlc/engine/postgresql/parse_wasi.go index 0cd4033..377b812 100644 --- a/pkg/sqlc/engine/postgresql/parse_wasi.go +++ b/pkg/sqlc/engine/postgresql/parse_wasi.go @@ -1,5 +1,4 @@ //go:build windows || !cgo -// +build windows !cgo package postgresql diff --git a/pkg/sqlc/engine/postgresql/parser/parser_default.go b/pkg/sqlc/engine/postgresql/parser/parser_default.go index 06fea36..317c5c0 100644 --- a/pkg/sqlc/engine/postgresql/parser/parser_default.go +++ b/pkg/sqlc/engine/postgresql/parser/parser_default.go @@ -1,5 +1,4 @@ //go:build !windows && cgo -// +build !windows,cgo package parser diff --git a/pkg/sqlc/engine/postgresql/parser/parser_wasi.go b/pkg/sqlc/engine/postgresql/parser/parser_wasi.go index d908b32..e172d36 100644 --- a/pkg/sqlc/engine/postgresql/parser/parser_wasi.go +++ b/pkg/sqlc/engine/postgresql/parser/parser_wasi.go @@ -1,5 +1,4 @@ //go:build windows || !cgo -// +build windows !cgo package parser diff --git a/pkg/sqlc/info/facts.go b/pkg/sqlc/info/facts.go index 29df254..976147b 100644 --- a/pkg/sqlc/info/facts.go +++ b/pkg/sqlc/info/facts.go @@ -2,4 +2,4 @@ package info // When no version is set, return the next bug fix version // after the most recent tag -const Version = "v1.26.0" +const Version = "v1.27.0" diff --git a/pkg/sqlc/pgx/poolcache/poolcache.go b/pkg/sqlc/pgx/poolcache/poolcache.go index 93401ec..3fce3cb 100644 --- a/pkg/sqlc/pgx/poolcache/poolcache.go +++ b/pkg/sqlc/pgx/poolcache/poolcache.go @@ -2,18 +2,32 @@ package poolcache import ( "context" + "fmt" "sync" "github.com/jackc/pgx/v5/pgxpool" ) -var lock sync.RWMutex -var pools = map[string]*pgxpool.Pool{} +type Cache struct { + lock sync.RWMutex + closed bool + pools map[string]*pgxpool.Pool +} + +func New() *Cache { + return &Cache{ + pools: map[string]*pgxpool.Pool{}, + } +} + +func (c *Cache) Open(ctx context.Context, uri string) (*pgxpool.Pool, error) { + if c.closed { + return nil, fmt.Errorf("poolcache is closed") + } -func New(ctx context.Context, uri string) (*pgxpool.Pool, error) { - lock.RLock() - existing, found := pools[uri] - lock.RUnlock() + c.lock.RLock() + existing, found := c.pools[uri] + c.lock.RUnlock() if found { return existing, nil @@ -24,9 +38,24 @@ func New(ctx context.Context, uri string) (*pgxpool.Pool, error) { return nil, err } - lock.Lock() - pools[uri] = pool - lock.Unlock() + c.lock.Lock() + c.pools[uri] = pool + c.lock.Unlock() return pool, nil } + +func (c *Cache) Close() error { + c.lock.Lock() + defer c.lock.Unlock() + + var closeErr error + for _, pool := range c.pools { + pool.Close() + } + + c.closed = true + clear(c.pools) + + return closeErr +} diff --git a/pkg/sqlc/quickdb/v1/quickdb.pb.go b/pkg/sqlc/quickdb/v1/quickdb.pb.go index 39b61a4..690dfc1 100755 --- a/pkg/sqlc/quickdb/v1/quickdb.pb.go +++ b/pkg/sqlc/quickdb/v1/quickdb.pb.go @@ -641,6 +641,100 @@ func (x *VerifyQuerySetsResponse) GetSummary() string { return "" } +type GetQuerySetsRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Tag string `protobuf:"bytes,1,opt,name=tag,proto3" json:"tag,omitempty"` +} + +func (x *GetQuerySetsRequest) Reset() { + *x = GetQuerySetsRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_v1_quickdb_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetQuerySetsRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetQuerySetsRequest) ProtoMessage() {} + +func (x *GetQuerySetsRequest) ProtoReflect() protoreflect.Message { + mi := &file_v1_quickdb_proto_msgTypes[10] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetQuerySetsRequest.ProtoReflect.Descriptor instead. +func (*GetQuerySetsRequest) Descriptor() ([]byte, []int) { + return file_v1_quickdb_proto_rawDescGZIP(), []int{10} +} + +func (x *GetQuerySetsRequest) GetTag() string { + if x != nil { + return x.Tag + } + return "" +} + +type GetQuerySetsResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + QuerySets []*QuerySet `protobuf:"bytes,1,rep,name=query_sets,json=querySets,proto3" json:"query_sets,omitempty"` +} + +func (x *GetQuerySetsResponse) Reset() { + *x = GetQuerySetsResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_v1_quickdb_proto_msgTypes[11] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetQuerySetsResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetQuerySetsResponse) ProtoMessage() {} + +func (x *GetQuerySetsResponse) ProtoReflect() protoreflect.Message { + mi := &file_v1_quickdb_proto_msgTypes[11] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetQuerySetsResponse.ProtoReflect.Descriptor instead. +func (*GetQuerySetsResponse) Descriptor() ([]byte, []int) { + return file_v1_quickdb_proto_rawDescGZIP(), []int{11} +} + +func (x *GetQuerySetsResponse) GetQuerySets() []*QuerySet { + if x != nil { + return x.QuerySets + } + return nil +} + var File_v1_quickdb_proto protoreflect.FileDescriptor var file_v1_quickdb_proto_rawDesc = []byte{ @@ -749,56 +843,72 @@ var file_v1_quickdb_proto_rawDesc = []byte{ 0x65, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x75, 0x6d, - 0x6d, 0x61, 0x72, 0x79, 0x32, 0x9d, 0x04, 0x0a, 0x05, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x12, 0x92, - 0x01, 0x0a, 0x17, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x45, 0x70, 0x68, 0x65, 0x6d, 0x65, 0x72, - 0x61, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x12, 0x3a, 0x2e, 0x72, 0x65, 0x6d, - 0x6f, 0x74, 0x65, 0x2e, 0x73, 0x71, 0x6c, 0x63, 0x2e, 0x64, 0x65, 0x76, 0x2e, 0x71, 0x75, 0x69, - 0x63, 0x6b, 0x64, 0x62, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x45, 0x70, - 0x68, 0x65, 0x6d, 0x65, 0x72, 0x61, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x3b, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, - 0x73, 0x71, 0x6c, 0x63, 0x2e, 0x64, 0x65, 0x76, 0x2e, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x64, 0x62, - 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x45, 0x70, 0x68, 0x65, 0x6d, 0x65, - 0x72, 0x61, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x12, 0x8c, 0x01, 0x0a, 0x15, 0x44, 0x72, 0x6f, 0x70, 0x45, 0x70, 0x68, 0x65, - 0x6d, 0x65, 0x72, 0x61, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x12, 0x38, 0x2e, + 0x6d, 0x61, 0x72, 0x79, 0x22, 0x27, 0x0a, 0x13, 0x47, 0x65, 0x74, 0x51, 0x75, 0x65, 0x72, 0x79, + 0x53, 0x65, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x74, + 0x61, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x74, 0x61, 0x67, 0x22, 0x5b, 0x0a, + 0x14, 0x47, 0x65, 0x74, 0x51, 0x75, 0x65, 0x72, 0x79, 0x53, 0x65, 0x74, 0x73, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x43, 0x0a, 0x0a, 0x71, 0x75, 0x65, 0x72, 0x79, 0x5f, 0x73, + 0x65, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x72, 0x65, 0x6d, 0x6f, + 0x74, 0x65, 0x2e, 0x73, 0x71, 0x6c, 0x63, 0x2e, 0x64, 0x65, 0x76, 0x2e, 0x71, 0x75, 0x69, 0x63, + 0x6b, 0x64, 0x62, 0x2e, 0x76, 0x31, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x53, 0x65, 0x74, 0x52, + 0x09, 0x71, 0x75, 0x65, 0x72, 0x79, 0x53, 0x65, 0x74, 0x73, 0x32, 0x90, 0x05, 0x0a, 0x05, 0x51, + 0x75, 0x69, 0x63, 0x6b, 0x12, 0x92, 0x01, 0x0a, 0x17, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x45, + 0x70, 0x68, 0x65, 0x6d, 0x65, 0x72, 0x61, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, + 0x12, 0x3a, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x73, 0x71, 0x6c, 0x63, 0x2e, 0x64, + 0x65, 0x76, 0x2e, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x64, 0x62, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x72, + 0x65, 0x61, 0x74, 0x65, 0x45, 0x70, 0x68, 0x65, 0x6d, 0x65, 0x72, 0x61, 0x6c, 0x44, 0x61, 0x74, + 0x61, 0x62, 0x61, 0x73, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x3b, 0x2e, 0x72, + 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x73, 0x71, 0x6c, 0x63, 0x2e, 0x64, 0x65, 0x76, 0x2e, 0x71, + 0x75, 0x69, 0x63, 0x6b, 0x64, 0x62, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, + 0x45, 0x70, 0x68, 0x65, 0x6d, 0x65, 0x72, 0x61, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, + 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x8c, 0x01, 0x0a, 0x15, 0x44, 0x72, + 0x6f, 0x70, 0x45, 0x70, 0x68, 0x65, 0x6d, 0x65, 0x72, 0x61, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x62, + 0x61, 0x73, 0x65, 0x12, 0x38, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x73, 0x71, 0x6c, + 0x63, 0x2e, 0x64, 0x65, 0x76, 0x2e, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x64, 0x62, 0x2e, 0x76, 0x31, + 0x2e, 0x44, 0x72, 0x6f, 0x70, 0x45, 0x70, 0x68, 0x65, 0x6d, 0x65, 0x72, 0x61, 0x6c, 0x44, 0x61, + 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x39, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x73, 0x71, 0x6c, 0x63, 0x2e, 0x64, 0x65, 0x76, 0x2e, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x64, 0x62, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x72, 0x6f, 0x70, 0x45, 0x70, 0x68, 0x65, 0x6d, 0x65, 0x72, 0x61, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x39, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, - 0x2e, 0x73, 0x71, 0x6c, 0x63, 0x2e, 0x64, 0x65, 0x76, 0x2e, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x64, - 0x62, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x72, 0x6f, 0x70, 0x45, 0x70, 0x68, 0x65, 0x6d, 0x65, 0x72, - 0x61, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x12, 0x74, 0x0a, 0x0d, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x41, 0x72, 0x63, 0x68, - 0x69, 0x76, 0x65, 0x12, 0x30, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x73, 0x71, 0x6c, - 0x63, 0x2e, 0x64, 0x65, 0x76, 0x2e, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x64, 0x62, 0x2e, 0x76, 0x31, - 0x2e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x41, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x31, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x73, - 0x71, 0x6c, 0x63, 0x2e, 0x64, 0x65, 0x76, 0x2e, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x64, 0x62, 0x2e, - 0x76, 0x31, 0x2e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x41, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x7a, 0x0a, 0x0f, 0x56, 0x65, 0x72, 0x69, - 0x66, 0x79, 0x51, 0x75, 0x65, 0x72, 0x79, 0x53, 0x65, 0x74, 0x73, 0x12, 0x32, 0x2e, 0x72, 0x65, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x74, 0x0a, 0x0d, 0x55, 0x70, 0x6c, 0x6f, + 0x61, 0x64, 0x41, 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x12, 0x30, 0x2e, 0x72, 0x65, 0x6d, 0x6f, + 0x74, 0x65, 0x2e, 0x73, 0x71, 0x6c, 0x63, 0x2e, 0x64, 0x65, 0x76, 0x2e, 0x71, 0x75, 0x69, 0x63, + 0x6b, 0x64, 0x62, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x41, 0x72, 0x63, + 0x68, 0x69, 0x76, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x31, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x73, 0x71, 0x6c, 0x63, 0x2e, 0x64, 0x65, 0x76, 0x2e, 0x71, 0x75, - 0x69, 0x63, 0x6b, 0x64, 0x62, 0x2e, 0x76, 0x31, 0x2e, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x51, - 0x75, 0x65, 0x72, 0x79, 0x53, 0x65, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x33, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x73, 0x71, 0x6c, 0x63, 0x2e, 0x64, 0x65, - 0x76, 0x2e, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x64, 0x62, 0x2e, 0x76, 0x31, 0x2e, 0x56, 0x65, 0x72, - 0x69, 0x66, 0x79, 0x51, 0x75, 0x65, 0x72, 0x79, 0x53, 0x65, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x42, 0xeb, 0x01, 0x0a, 0x1e, 0x63, 0x6f, 0x6d, 0x2e, 0x72, 0x65, 0x6d, + 0x69, 0x63, 0x6b, 0x64, 0x62, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x41, + 0x72, 0x63, 0x68, 0x69, 0x76, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x7a, + 0x0a, 0x0f, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x51, 0x75, 0x65, 0x72, 0x79, 0x53, 0x65, 0x74, + 0x73, 0x12, 0x32, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x73, 0x71, 0x6c, 0x63, 0x2e, + 0x64, 0x65, 0x76, 0x2e, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x64, 0x62, 0x2e, 0x76, 0x31, 0x2e, 0x56, + 0x65, 0x72, 0x69, 0x66, 0x79, 0x51, 0x75, 0x65, 0x72, 0x79, 0x53, 0x65, 0x74, 0x73, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x33, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x73, + 0x71, 0x6c, 0x63, 0x2e, 0x64, 0x65, 0x76, 0x2e, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x64, 0x62, 0x2e, + 0x76, 0x31, 0x2e, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x51, 0x75, 0x65, 0x72, 0x79, 0x53, 0x65, + 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x71, 0x0a, 0x0c, 0x47, 0x65, + 0x74, 0x51, 0x75, 0x65, 0x72, 0x79, 0x53, 0x65, 0x74, 0x73, 0x12, 0x2f, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x73, 0x71, 0x6c, 0x63, 0x2e, 0x64, 0x65, 0x76, 0x2e, 0x71, 0x75, 0x69, - 0x63, 0x6b, 0x64, 0x62, 0x2e, 0x76, 0x31, 0x42, 0x0c, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x64, 0x62, - 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x2e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, - 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x71, 0x6c, 0x63, 0x2d, 0x64, 0x65, 0x76, 0x2f, 0x73, 0x71, 0x6c, - 0x63, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x76, 0x31, 0x3b, 0x71, 0x75, - 0x69, 0x63, 0x6b, 0x64, 0x62, 0x76, 0x31, 0xa2, 0x02, 0x04, 0x52, 0x53, 0x44, 0x51, 0xaa, 0x02, - 0x1a, 0x52, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x53, 0x71, 0x6c, 0x63, 0x2e, 0x44, 0x65, 0x76, - 0x2e, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x64, 0x62, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x1a, 0x52, 0x65, - 0x6d, 0x6f, 0x74, 0x65, 0x5c, 0x53, 0x71, 0x6c, 0x63, 0x5c, 0x44, 0x65, 0x76, 0x5c, 0x51, 0x75, - 0x69, 0x63, 0x6b, 0x64, 0x62, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x26, 0x52, 0x65, 0x6d, 0x6f, 0x74, - 0x65, 0x5c, 0x53, 0x71, 0x6c, 0x63, 0x5c, 0x44, 0x65, 0x76, 0x5c, 0x51, 0x75, 0x69, 0x63, 0x6b, - 0x64, 0x62, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, - 0x61, 0xea, 0x02, 0x1e, 0x52, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x3a, 0x3a, 0x53, 0x71, 0x6c, 0x63, - 0x3a, 0x3a, 0x44, 0x65, 0x76, 0x3a, 0x3a, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x64, 0x62, 0x3a, 0x3a, - 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x63, 0x6b, 0x64, 0x62, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x51, 0x75, 0x65, 0x72, 0x79, + 0x53, 0x65, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x30, 0x2e, 0x72, 0x65, + 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x73, 0x71, 0x6c, 0x63, 0x2e, 0x64, 0x65, 0x76, 0x2e, 0x71, 0x75, + 0x69, 0x63, 0x6b, 0x64, 0x62, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65, 0x74, 0x51, 0x75, 0x65, 0x72, + 0x79, 0x53, 0x65, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0xeb, 0x01, + 0x0a, 0x1e, 0x63, 0x6f, 0x6d, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x73, 0x71, 0x6c, + 0x63, 0x2e, 0x64, 0x65, 0x76, 0x2e, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x64, 0x62, 0x2e, 0x76, 0x31, + 0x42, 0x0c, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x64, 0x62, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, + 0x5a, 0x2e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x71, 0x6c, + 0x63, 0x2d, 0x64, 0x65, 0x76, 0x2f, 0x73, 0x71, 0x6c, 0x63, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, + 0x6e, 0x61, 0x6c, 0x2f, 0x76, 0x31, 0x3b, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x64, 0x62, 0x76, 0x31, + 0xa2, 0x02, 0x04, 0x52, 0x53, 0x44, 0x51, 0xaa, 0x02, 0x1a, 0x52, 0x65, 0x6d, 0x6f, 0x74, 0x65, + 0x2e, 0x53, 0x71, 0x6c, 0x63, 0x2e, 0x44, 0x65, 0x76, 0x2e, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x64, + 0x62, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x1a, 0x52, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x5c, 0x53, 0x71, + 0x6c, 0x63, 0x5c, 0x44, 0x65, 0x76, 0x5c, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x64, 0x62, 0x5c, 0x56, + 0x31, 0xe2, 0x02, 0x26, 0x52, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x5c, 0x53, 0x71, 0x6c, 0x63, 0x5c, + 0x44, 0x65, 0x76, 0x5c, 0x51, 0x75, 0x69, 0x63, 0x6b, 0x64, 0x62, 0x5c, 0x56, 0x31, 0x5c, 0x47, + 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x1e, 0x52, 0x65, 0x6d, + 0x6f, 0x74, 0x65, 0x3a, 0x3a, 0x53, 0x71, 0x6c, 0x63, 0x3a, 0x3a, 0x44, 0x65, 0x76, 0x3a, 0x3a, + 0x51, 0x75, 0x69, 0x63, 0x6b, 0x64, 0x62, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var ( @@ -813,7 +923,7 @@ func file_v1_quickdb_proto_rawDescGZIP() []byte { return file_v1_quickdb_proto_rawDescData } -var file_v1_quickdb_proto_msgTypes = make([]protoimpl.MessageInfo, 12) +var file_v1_quickdb_proto_msgTypes = make([]protoimpl.MessageInfo, 14) var file_v1_quickdb_proto_goTypes = []interface{}{ (*CreateEphemeralDatabaseRequest)(nil), // 0: remote.sqlc.dev.quickdb.v1.CreateEphemeralDatabaseRequest (*CreateEphemeralDatabaseResponse)(nil), // 1: remote.sqlc.dev.quickdb.v1.CreateEphemeralDatabaseResponse @@ -825,8 +935,10 @@ var file_v1_quickdb_proto_goTypes = []interface{}{ (*UploadArchiveResponse)(nil), // 7: remote.sqlc.dev.quickdb.v1.UploadArchiveResponse (*VerifyQuerySetsRequest)(nil), // 8: remote.sqlc.dev.quickdb.v1.VerifyQuerySetsRequest (*VerifyQuerySetsResponse)(nil), // 9: remote.sqlc.dev.quickdb.v1.VerifyQuerySetsResponse - nil, // 10: remote.sqlc.dev.quickdb.v1.UploadArchiveRequest.AnnotationsEntry - nil, // 11: remote.sqlc.dev.quickdb.v1.VerifyQuerySetsRequest.AnnotationsEntry + (*GetQuerySetsRequest)(nil), // 10: remote.sqlc.dev.quickdb.v1.GetQuerySetsRequest + (*GetQuerySetsResponse)(nil), // 11: remote.sqlc.dev.quickdb.v1.GetQuerySetsResponse + nil, // 12: remote.sqlc.dev.quickdb.v1.UploadArchiveRequest.AnnotationsEntry + nil, // 13: remote.sqlc.dev.quickdb.v1.VerifyQuerySetsRequest.AnnotationsEntry } var file_v1_quickdb_proto_depIdxs = []int32{ 4, // 0: remote.sqlc.dev.quickdb.v1.QuerySet.schema:type_name -> remote.sqlc.dev.quickdb.v1.File @@ -834,25 +946,28 @@ var file_v1_quickdb_proto_depIdxs = []int32{ 4, // 2: remote.sqlc.dev.quickdb.v1.QuerySet.codegen_request:type_name -> remote.sqlc.dev.quickdb.v1.File 4, // 3: remote.sqlc.dev.quickdb.v1.UploadArchiveRequest.inputs:type_name -> remote.sqlc.dev.quickdb.v1.File 4, // 4: remote.sqlc.dev.quickdb.v1.UploadArchiveRequest.outputs:type_name -> remote.sqlc.dev.quickdb.v1.File - 10, // 5: remote.sqlc.dev.quickdb.v1.UploadArchiveRequest.annotations:type_name -> remote.sqlc.dev.quickdb.v1.UploadArchiveRequest.AnnotationsEntry + 12, // 5: remote.sqlc.dev.quickdb.v1.UploadArchiveRequest.annotations:type_name -> remote.sqlc.dev.quickdb.v1.UploadArchiveRequest.AnnotationsEntry 5, // 6: remote.sqlc.dev.quickdb.v1.UploadArchiveRequest.query_sets:type_name -> remote.sqlc.dev.quickdb.v1.QuerySet 4, // 7: remote.sqlc.dev.quickdb.v1.UploadArchiveRequest.config:type_name -> remote.sqlc.dev.quickdb.v1.File 5, // 8: remote.sqlc.dev.quickdb.v1.VerifyQuerySetsRequest.query_sets:type_name -> remote.sqlc.dev.quickdb.v1.QuerySet 4, // 9: remote.sqlc.dev.quickdb.v1.VerifyQuerySetsRequest.config:type_name -> remote.sqlc.dev.quickdb.v1.File - 11, // 10: remote.sqlc.dev.quickdb.v1.VerifyQuerySetsRequest.annotations:type_name -> remote.sqlc.dev.quickdb.v1.VerifyQuerySetsRequest.AnnotationsEntry - 0, // 11: remote.sqlc.dev.quickdb.v1.Quick.CreateEphemeralDatabase:input_type -> remote.sqlc.dev.quickdb.v1.CreateEphemeralDatabaseRequest - 2, // 12: remote.sqlc.dev.quickdb.v1.Quick.DropEphemeralDatabase:input_type -> remote.sqlc.dev.quickdb.v1.DropEphemeralDatabaseRequest - 6, // 13: remote.sqlc.dev.quickdb.v1.Quick.UploadArchive:input_type -> remote.sqlc.dev.quickdb.v1.UploadArchiveRequest - 8, // 14: remote.sqlc.dev.quickdb.v1.Quick.VerifyQuerySets:input_type -> remote.sqlc.dev.quickdb.v1.VerifyQuerySetsRequest - 1, // 15: remote.sqlc.dev.quickdb.v1.Quick.CreateEphemeralDatabase:output_type -> remote.sqlc.dev.quickdb.v1.CreateEphemeralDatabaseResponse - 3, // 16: remote.sqlc.dev.quickdb.v1.Quick.DropEphemeralDatabase:output_type -> remote.sqlc.dev.quickdb.v1.DropEphemeralDatabaseResponse - 7, // 17: remote.sqlc.dev.quickdb.v1.Quick.UploadArchive:output_type -> remote.sqlc.dev.quickdb.v1.UploadArchiveResponse - 9, // 18: remote.sqlc.dev.quickdb.v1.Quick.VerifyQuerySets:output_type -> remote.sqlc.dev.quickdb.v1.VerifyQuerySetsResponse - 15, // [15:19] is the sub-list for method output_type - 11, // [11:15] is the sub-list for method input_type - 11, // [11:11] is the sub-list for extension type_name - 11, // [11:11] is the sub-list for extension extendee - 0, // [0:11] is the sub-list for field type_name + 13, // 10: remote.sqlc.dev.quickdb.v1.VerifyQuerySetsRequest.annotations:type_name -> remote.sqlc.dev.quickdb.v1.VerifyQuerySetsRequest.AnnotationsEntry + 5, // 11: remote.sqlc.dev.quickdb.v1.GetQuerySetsResponse.query_sets:type_name -> remote.sqlc.dev.quickdb.v1.QuerySet + 0, // 12: remote.sqlc.dev.quickdb.v1.Quick.CreateEphemeralDatabase:input_type -> remote.sqlc.dev.quickdb.v1.CreateEphemeralDatabaseRequest + 2, // 13: remote.sqlc.dev.quickdb.v1.Quick.DropEphemeralDatabase:input_type -> remote.sqlc.dev.quickdb.v1.DropEphemeralDatabaseRequest + 6, // 14: remote.sqlc.dev.quickdb.v1.Quick.UploadArchive:input_type -> remote.sqlc.dev.quickdb.v1.UploadArchiveRequest + 8, // 15: remote.sqlc.dev.quickdb.v1.Quick.VerifyQuerySets:input_type -> remote.sqlc.dev.quickdb.v1.VerifyQuerySetsRequest + 10, // 16: remote.sqlc.dev.quickdb.v1.Quick.GetQuerySets:input_type -> remote.sqlc.dev.quickdb.v1.GetQuerySetsRequest + 1, // 17: remote.sqlc.dev.quickdb.v1.Quick.CreateEphemeralDatabase:output_type -> remote.sqlc.dev.quickdb.v1.CreateEphemeralDatabaseResponse + 3, // 18: remote.sqlc.dev.quickdb.v1.Quick.DropEphemeralDatabase:output_type -> remote.sqlc.dev.quickdb.v1.DropEphemeralDatabaseResponse + 7, // 19: remote.sqlc.dev.quickdb.v1.Quick.UploadArchive:output_type -> remote.sqlc.dev.quickdb.v1.UploadArchiveResponse + 9, // 20: remote.sqlc.dev.quickdb.v1.Quick.VerifyQuerySets:output_type -> remote.sqlc.dev.quickdb.v1.VerifyQuerySetsResponse + 11, // 21: remote.sqlc.dev.quickdb.v1.Quick.GetQuerySets:output_type -> remote.sqlc.dev.quickdb.v1.GetQuerySetsResponse + 17, // [17:22] is the sub-list for method output_type + 12, // [12:17] is the sub-list for method input_type + 12, // [12:12] is the sub-list for extension type_name + 12, // [12:12] is the sub-list for extension extendee + 0, // [0:12] is the sub-list for field type_name } func init() { file_v1_quickdb_proto_init() } @@ -981,6 +1096,30 @@ func file_v1_quickdb_proto_init() { return nil } } + file_v1_quickdb_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetQuerySetsRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_v1_quickdb_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetQuerySetsResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -988,7 +1127,7 @@ func file_v1_quickdb_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_v1_quickdb_proto_rawDesc, NumEnums: 0, - NumMessages: 12, + NumMessages: 14, NumExtensions: 0, NumServices: 1, }, diff --git a/pkg/sqlc/quickdb/v1/quickdb_grpc.pb.go b/pkg/sqlc/quickdb/v1/quickdb_grpc.pb.go index 97b25ab..f8f4a13 100644 --- a/pkg/sqlc/quickdb/v1/quickdb_grpc.pb.go +++ b/pkg/sqlc/quickdb/v1/quickdb_grpc.pb.go @@ -23,6 +23,7 @@ const ( Quick_DropEphemeralDatabase_FullMethodName = "/remote.sqlc.dev.quickdb.v1.Quick/DropEphemeralDatabase" Quick_UploadArchive_FullMethodName = "/remote.sqlc.dev.quickdb.v1.Quick/UploadArchive" Quick_VerifyQuerySets_FullMethodName = "/remote.sqlc.dev.quickdb.v1.Quick/VerifyQuerySets" + Quick_GetQuerySets_FullMethodName = "/remote.sqlc.dev.quickdb.v1.Quick/GetQuerySets" ) // QuickClient is the client API for Quick service. @@ -33,6 +34,7 @@ type QuickClient interface { DropEphemeralDatabase(ctx context.Context, in *DropEphemeralDatabaseRequest, opts ...grpc.CallOption) (*DropEphemeralDatabaseResponse, error) UploadArchive(ctx context.Context, in *UploadArchiveRequest, opts ...grpc.CallOption) (*UploadArchiveResponse, error) VerifyQuerySets(ctx context.Context, in *VerifyQuerySetsRequest, opts ...grpc.CallOption) (*VerifyQuerySetsResponse, error) + GetQuerySets(ctx context.Context, in *GetQuerySetsRequest, opts ...grpc.CallOption) (*GetQuerySetsResponse, error) } type quickClient struct { @@ -79,6 +81,15 @@ func (c *quickClient) VerifyQuerySets(ctx context.Context, in *VerifyQuerySetsRe return out, nil } +func (c *quickClient) GetQuerySets(ctx context.Context, in *GetQuerySetsRequest, opts ...grpc.CallOption) (*GetQuerySetsResponse, error) { + out := new(GetQuerySetsResponse) + err := c.cc.Invoke(ctx, Quick_GetQuerySets_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // QuickServer is the server API for Quick service. // All implementations must embed UnimplementedQuickServer // for forward compatibility @@ -87,6 +98,7 @@ type QuickServer interface { DropEphemeralDatabase(context.Context, *DropEphemeralDatabaseRequest) (*DropEphemeralDatabaseResponse, error) UploadArchive(context.Context, *UploadArchiveRequest) (*UploadArchiveResponse, error) VerifyQuerySets(context.Context, *VerifyQuerySetsRequest) (*VerifyQuerySetsResponse, error) + GetQuerySets(context.Context, *GetQuerySetsRequest) (*GetQuerySetsResponse, error) mustEmbedUnimplementedQuickServer() } @@ -106,6 +118,9 @@ func (UnimplementedQuickServer) UploadArchive(context.Context, *UploadArchiveReq func (UnimplementedQuickServer) VerifyQuerySets(context.Context, *VerifyQuerySetsRequest) (*VerifyQuerySetsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method VerifyQuerySets not implemented") } +func (UnimplementedQuickServer) GetQuerySets(context.Context, *GetQuerySetsRequest) (*GetQuerySetsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetQuerySets not implemented") +} func (UnimplementedQuickServer) mustEmbedUnimplementedQuickServer() {} // UnsafeQuickServer may be embedded to opt out of forward compatibility for this service. @@ -191,6 +206,24 @@ func _Quick_VerifyQuerySets_Handler(srv interface{}, ctx context.Context, dec fu return interceptor(ctx, in, info, handler) } +func _Quick_GetQuerySets_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetQuerySetsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QuickServer).GetQuerySets(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Quick_GetQuerySets_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QuickServer).GetQuerySets(ctx, req.(*GetQuerySetsRequest)) + } + return interceptor(ctx, in, info, handler) +} + // Quick_ServiceDesc is the grpc.ServiceDesc for Quick service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -214,6 +247,10 @@ var Quick_ServiceDesc = grpc.ServiceDesc{ MethodName: "VerifyQuerySets", Handler: _Quick_VerifyQuerySets_Handler, }, + { + MethodName: "GetQuerySets", + Handler: _Quick_GetQuerySets_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "v1/quickdb.proto", diff --git a/pkg/sqlc/sqltest/hosted/client.go b/pkg/sqlc/sqltest/hosted/client.go deleted file mode 100644 index 6023491..0000000 --- a/pkg/sqlc/sqltest/hosted/client.go +++ /dev/null @@ -1,27 +0,0 @@ -package hosted - -import ( - "fmt" - "os" - "sync" - - "github.com/tkcrm/pgxgen/pkg/sqlc/quickdb" - pb "github.com/tkcrm/pgxgen/pkg/sqlc/quickdb/v1" -) - -var client pb.QuickClient -var once sync.Once - -func initClient() error { - projectID := os.Getenv("CI_SQLC_PROJECT_ID") - authToken := os.Getenv("CI_SQLC_AUTH_TOKEN") - if projectID == "" || authToken == "" { - return fmt.Errorf("missing project id or auth token") - } - c, err := quickdb.NewClient(projectID, authToken) - if err != nil { - return err - } - client = c - return nil -} diff --git a/pkg/sqlc/sqltest/hosted/mysql.go b/pkg/sqlc/sqltest/hosted/mysql.go deleted file mode 100644 index 5adb35b..0000000 --- a/pkg/sqlc/sqltest/hosted/mysql.go +++ /dev/null @@ -1,64 +0,0 @@ -package hosted - -import ( - "context" - "os" - "testing" - - "github.com/tkcrm/pgxgen/pkg/sqlc/quickdb" - pb "github.com/tkcrm/pgxgen/pkg/sqlc/quickdb/v1" - "github.com/tkcrm/pgxgen/pkg/sqlc/sql/sqlpath" -) - -func MySQL(t *testing.T, migrations []string) string { - ctx := context.Background() - t.Helper() - - once.Do(func() { - if err := initClient(); err != nil { - t.Log(err) - } - }) - - if client == nil { - t.Skip("client init failed") - } - - var seed []string - files, err := sqlpath.Glob(migrations) - if err != nil { - t.Fatal(err) - } - for _, f := range files { - blob, err := os.ReadFile(f) - if err != nil { - t.Fatal(err) - } - seed = append(seed, string(blob)) - } - - resp, err := client.CreateEphemeralDatabase(ctx, &pb.CreateEphemeralDatabaseRequest{ - Engine: "mysql", - Region: quickdb.GetClosestRegion(), - Migrations: seed, - }) - if err != nil { - t.Fatalf("region %s: %s", quickdb.GetClosestRegion(), err) - } - - t.Cleanup(func() { - _, err = client.DropEphemeralDatabase(ctx, &pb.DropEphemeralDatabaseRequest{ - DatabaseId: resp.DatabaseId, - }) - if err != nil { - t.Fatal(err) - } - }) - - uri, err := quickdb.MySQLReformatURI(resp.Uri) - if err != nil { - t.Fatalf("uri error: %s", err) - } - - return uri -} diff --git a/pkg/sqlc/sqltest/hosted/postgres.go b/pkg/sqlc/sqltest/hosted/postgres.go deleted file mode 100644 index a3db478..0000000 --- a/pkg/sqlc/sqltest/hosted/postgres.go +++ /dev/null @@ -1,59 +0,0 @@ -package hosted - -import ( - "context" - "os" - "testing" - - "github.com/tkcrm/pgxgen/pkg/sqlc/quickdb" - pb "github.com/tkcrm/pgxgen/pkg/sqlc/quickdb/v1" - "github.com/tkcrm/pgxgen/pkg/sqlc/sql/sqlpath" -) - -func PostgreSQL(t *testing.T, migrations []string) string { - ctx := context.Background() - t.Helper() - - once.Do(func() { - if err := initClient(); err != nil { - t.Log(err) - } - }) - - if client == nil { - t.Skip("client init failed") - } - - var seed []string - files, err := sqlpath.Glob(migrations) - if err != nil { - t.Fatal(err) - } - for _, f := range files { - blob, err := os.ReadFile(f) - if err != nil { - t.Fatal(err) - } - seed = append(seed, string(blob)) - } - - resp, err := client.CreateEphemeralDatabase(ctx, &pb.CreateEphemeralDatabaseRequest{ - Engine: "postgresql", - Region: quickdb.GetClosestRegion(), - Migrations: seed, - }) - if err != nil { - t.Fatalf("region %s: %s", quickdb.GetClosestRegion(), err) - } - - t.Cleanup(func() { - _, err = client.DropEphemeralDatabase(ctx, &pb.DropEphemeralDatabaseRequest{ - DatabaseId: resp.DatabaseId, - }) - if err != nil { - t.Fatal(err) - } - }) - - return resp.Uri -} diff --git a/pkg/sqlc/sqltest/local/mysql.go b/pkg/sqlc/sqltest/local/mysql.go index 9c429ba..2f8d0e4 100644 --- a/pkg/sqlc/sqltest/local/mysql.go +++ b/pkg/sqlc/sqltest/local/mysql.go @@ -18,6 +18,10 @@ import ( var mysqlSync sync.Once var mysqlPool *sql.DB +func MySQLServer() string { + return os.Getenv("MYSQL_SERVER_URI") +} + func MySQL(t *testing.T, migrations []string) string { ctx := context.Background() t.Helper() diff --git a/pkg/sqlc/sqltest/local/postgres.go b/pkg/sqlc/sqltest/local/postgres.go index 8869b06..25515fa 100644 --- a/pkg/sqlc/sqltest/local/postgres.go +++ b/pkg/sqlc/sqltest/local/postgres.go @@ -18,6 +18,7 @@ import ( ) var flight singleflight.Group +var cache = poolcache.New() func PostgreSQL(t *testing.T, migrations []string) string { return postgreSQL(t, migrations, true) @@ -27,6 +28,10 @@ func ReadOnlyPostgreSQL(t *testing.T, migrations []string) string { return postgreSQL(t, migrations, false) } +func PostgreSQLServer() string { + return os.Getenv("POSTGRESQL_SERVER_URI") +} + func postgreSQL(t *testing.T, migrations []string, rw bool) string { ctx := context.Background() t.Helper() @@ -36,7 +41,7 @@ func postgreSQL(t *testing.T, migrations []string, rw bool) string { t.Skip("POSTGRESQL_SERVER_URI is empty") } - postgresPool, err := poolcache.New(ctx, dburi) + postgresPool, err := cache.Open(ctx, dburi) if err != nil { t.Fatalf("PostgreSQL pool creation failed: %s", err) }