-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: interface and actual package name
- Loading branch information
Showing
9 changed files
with
250 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
copy: | ||
cp -rf ./sequel/sequel.go ./codegen/sequel.go.tpl | ||
build: | ||
go build -o sqlgen -ldflags="-s -w" ./main.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package sequel | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"database/sql/driver" | ||
"fmt" | ||
"io" | ||
) | ||
|
||
// For rename table name | ||
type Name struct{} | ||
|
||
type Scanner[T any] interface { | ||
*T | ||
Addrs() []any | ||
} | ||
|
||
type TableColumnValuer[T any] interface { | ||
Tabler | ||
Columner | ||
Valuer | ||
} | ||
|
||
type KeyValuer[T any] interface { | ||
Keyer | ||
Tabler | ||
Columner | ||
Valuer | ||
} | ||
|
||
type KeyValueScanner[T any] interface { | ||
KeyValuer[T] | ||
Scanner[T] | ||
} | ||
|
||
type Keyer interface { | ||
PK() (columnName string, pos int, value driver.Value) | ||
} | ||
|
||
type AutoIncrKeyer interface { | ||
Keyer | ||
IsAutoIncr() | ||
} | ||
|
||
type Tabler interface { | ||
TableName() string | ||
} | ||
|
||
type Columner interface { | ||
Columns() []string | ||
} | ||
|
||
type Valuer interface { | ||
Values() []any | ||
} | ||
|
||
type DB interface { | ||
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error) | ||
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error) | ||
QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row | ||
} | ||
|
||
type Dialect interface { | ||
Var(n int) string | ||
Wrap(v string) string | ||
Driver() string | ||
} | ||
|
||
type Migrator interface { | ||
Tabler | ||
CreateTableStmt() string | ||
AlterTableStmt() string | ||
} | ||
|
||
type SingleInserter interface { | ||
InsertOneStmt() string | ||
} | ||
|
||
type KeyFinder interface { | ||
Keyer | ||
FindByPKStmt() string | ||
} | ||
|
||
type Inserter interface { | ||
Columner | ||
InsertVarQuery() string | ||
} | ||
|
||
type StmtWriter interface { | ||
io.StringWriter | ||
io.ByteWriter | ||
} | ||
|
||
type StmtBuilder interface { | ||
StmtWriter | ||
Var(query string, v any) | ||
Vars(query string, v []any) | ||
} | ||
|
||
type Stmt interface { | ||
StmtBuilder | ||
fmt.Stringer | ||
Args() []any | ||
Reset() | ||
} | ||
|
||
type ( | ||
WhereClause func(StmtBuilder) | ||
SetClause func(StmtBuilder) | ||
OrderByClause func(StmtWriter) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Code generated by sqlgen, version v1.0.0-alpha.2. DO NOT EDIT. | ||
|
||
package version | ||
|
||
import ( | ||
"database/sql" | ||
"database/sql/driver" | ||
|
||
uuid "github.com/gofrs/uuid/v5" | ||
"github.com/si3nloong/sqlgen/sequel" | ||
) | ||
|
||
func (v Version) CreateTableStmt() string { | ||
return "CREATE TABLE IF NOT EXISTS " + v.TableName() + " (`id` VARCHAR(36) NOT NULL,PRIMARY KEY (`id`));" | ||
} | ||
func (Version) AlterTableStmt() string { | ||
return "ALTER TABLE `version` MODIFY `id` VARCHAR(36) NOT NULL;" | ||
} | ||
func (Version) TableName() string { | ||
return "`version`" | ||
} | ||
func (v Version) InsertOneStmt() string { | ||
return "INSERT INTO `version` (`id`) VALUES (?);" | ||
} | ||
func (Version) InsertVarQuery() string { | ||
return "(?)" | ||
} | ||
func (Version) Columns() []string { | ||
return []string{"`id`"} | ||
} | ||
func (v Version) PK() (columnName string, pos int, value driver.Value) { | ||
return "`id`", 0, (driver.Valuer)(v.ID) | ||
} | ||
func (v Version) FindByPKStmt() string { | ||
return "SELECT `id` FROM `version` WHERE `id` = ? LIMIT 1;" | ||
} | ||
func (v Version) Values() []any { | ||
return []any{(driver.Valuer)(v.ID)} | ||
} | ||
func (v *Version) Addrs() []any { | ||
return []any{(sql.Scanner)(&v.ID)} | ||
} | ||
func (v Version) GetID() sequel.ColumnValuer[uuid.UUID] { | ||
return sequel.Column[uuid.UUID]("`id`", v.ID, func(vi uuid.UUID) driver.Value { return (driver.Valuer)(vi) }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package version | ||
|
||
import "github.com/gofrs/uuid/v5" | ||
|
||
type Version struct { | ||
ID uuid.UUID `sql:",pk"` | ||
} |