Skip to content

Commit

Permalink
test: add test cases and fix testing pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
si3nloong committed Nov 2, 2023
1 parent a4c3a9a commit f1eff64
Show file tree
Hide file tree
Showing 50 changed files with 1,317 additions and 33 deletions.
3 changes: 3 additions & 0 deletions examples/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion examples/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.21
toolchain go1.21.3

require (
cloud.google.com/go v0.110.10
github.com/go-sql-driver/mysql v1.7.0
github.com/google/uuid v1.4.0
github.com/jaswdr/faker v1.16.0
Expand All @@ -21,7 +22,7 @@ require (
github.com/valyala/bytebufferpool v1.0.0 // indirect
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/tools v0.13.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Expand Down
8 changes: 6 additions & 2 deletions examples/go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
cloud.google.com/go v0.110.10 h1:LXy9GEO+timppncPIAZoOj3l58LIU9k+kn48AN7IO3Y=
cloud.google.com/go v0.110.10/go.mod h1:v1OoFqYxiBkUrruItNM3eT4lLByNjxmJSV/xDKJNnic=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc=
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/jaswdr/faker v1.16.0 h1:5ZjusQbqIZwJnUymPirNKJI1yFCuozdSR9oeYPgD5Uk=
Expand All @@ -24,8 +28,8 @@ golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ=
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
Expand Down
3 changes: 3 additions & 0 deletions examples/testcase/schema/a/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions examples/testcase/schema/a/generated.go.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Code generated by sqlgen, version 1.0.0. DO NOT EDIT.

package a
118 changes: 118 additions & 0 deletions examples/testcase/schema/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

118 changes: 118 additions & 0 deletions examples/testcase/schema/generated.go.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Code generated by sqlgen, version 1.0.0. DO NOT EDIT.

package schema

import (
"database/sql"
"database/sql/driver"
"time"

"github.com/si3nloong/sqlgen/sequel/types"
)

func (Model) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS model ();"
}
func (Model) AlterTableStmt() string {
return "ALTER TABLE model ;"
}
func (Model) TableName() string {
return "model"
}
func (Model) Columns() []string {
return []string{}
}
func (v Model) Values() []any {
return []any{}
}
func (v *Model) Addrs() []any {
return []any{}
}

func (A) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS a (id VARCHAR(255) NOT NULL,created_at DATETIME NOT NULL);"
}
func (A) AlterTableStmt() string {
return "ALTER TABLE a MODIFY id VARCHAR(255) NOT NULL,MODIFY created_at DATETIME NOT NULL AFTER id;"
}
func (A) TableName() string {
return "a"
}
func (A) Columns() []string {
return []string{"id", "created_at"}
}
func (v A) Values() []any {
return []any{string(v.ID), time.Time(v.CreatedAt)}
}
func (v *A) Addrs() []any {
return []any{types.String(&v.ID), (*time.Time)(&v.CreatedAt)}
}

func (B) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS b (id VARCHAR(255) NOT NULL,created_at DATETIME NOT NULL);"
}
func (B) AlterTableStmt() string {
return "ALTER TABLE b MODIFY id VARCHAR(255) NOT NULL,MODIFY created_at DATETIME NOT NULL AFTER id;"
}
func (B) TableName() string {
return "b"
}
func (B) Columns() []string {
return []string{"id", "created_at"}
}
func (v B) Values() []any {
return []any{string(v.ID), time.Time(v.CreatedAt)}
}
func (v *B) Addrs() []any {
return []any{types.String(&v.ID), (*time.Time)(&v.CreatedAt)}
}

func (C) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS c (id BIGINT NOT NULL,PRIMARY KEY (id));"
}
func (C) AlterTableStmt() string {
return "ALTER TABLE c MODIFY id BIGINT NOT NULL;"
}
func (C) TableName() string {
return "c"
}
func (C) Columns() []string {
return []string{"id"}
}
func (v C) IsAutoIncr() bool {
return false
}
func (v C) PK() (columnName string, pos int, value driver.Value) {
return "id", 0, int64(v.ID)
}
func (v C) Values() []any {
return []any{int64(v.ID)}
}
func (v *C) Addrs() []any {
return []any{types.Integer(&v.ID)}
}

func (D) CreateTableStmt() string {
return "CREATE TABLE IF NOT EXISTS d (id VARCHAR(255) NOT NULL,PRIMARY KEY (id));"
}
func (D) AlterTableStmt() string {
return "ALTER TABLE d MODIFY id VARCHAR(255) NOT NULL;"
}
func (D) TableName() string {
return "d"
}
func (D) Columns() []string {
return []string{"id"}
}
func (v D) IsAutoIncr() bool {
return false
}
func (v D) PK() (columnName string, pos int, value driver.Value) {
return "id", 0, (driver.Valuer)(v.ID)
}
func (v D) Values() []any {
return []any{(driver.Valuer)(v.ID)}
}
func (v *D) Addrs() []any {
return []any{(sql.Scanner)(&v.ID)}
}
29 changes: 29 additions & 0 deletions examples/testcase/schema/model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package schema

import (
"database/sql"
t "time"

s "github.com/si3nloong/sqlgen/sequel"
)

type A struct {
s.Name `sql:"Apple"`
ID string
CreatedAt t.Time
}

type B struct {
// go:staticcheck
// n, p schema.Name `sql:"Boy"`
ID string
CreatedAt t.Time
}

type C struct {
ID int64 `sql:",pk"`
}

type D struct {
ID sql.NullString `sql:",pk"`
}
1 change: 1 addition & 0 deletions examples/testcase/schema/model_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package schema_test
74 changes: 74 additions & 0 deletions examples/testcase/struct-field/alias/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f1eff64

Please sign in to comment.