Documentation ¶
Overview ¶
go:generate go-bindata -o bindata.go template mapconfig
Index ¶
- Variables
- func CreateInsertParams(st *Struct) string
- func CreateInsertSQL(st *Struct) string
- func CreateInsertScan(st *Struct) string
- func CreateSelectByPkFuncParams(st *Struct) string
- func CreateSelectByPkSQL(st *Struct) string
- func CreateSelectByPkSQLParams(st *Struct) string
- func CreateSelectByPkScan(st *Struct) string
- func OpenDB(connStr string) (*sql.DB, error)
- func PgConvertType(col *PgColumn, typeCfg *PgTypeMapConfig) string
- func PgExecuteCustomTemplate(st *StructTemplate, customTmpl string) ([]byte, error)
- type AutoKeyMap
- type PgColumn
- type PgTable
- type PgTypeMapConfig
- type Queryer
- type Struct
- type StructField
- type StructTemplate
- type TypeMap
Constants ¶
This section is empty.
Variables ¶
var AutoGenKeyCfg = &AutoKeyMap{ Types: []string{"smallserial", "serial", "bigserial", "autogenuuid"}, }
AutoGenKeyCfg ...
Functions ¶
func CreateSelectByPkFuncParams ¶
CreateSelectByPkFuncParams ...
func CreateSelectByPkSQLParams ¶
CreateSelectByPkSQLParams ...
func PgConvertType ¶
func PgConvertType(col *PgColumn, typeCfg *PgTypeMapConfig) string
PgConvertType converts type
func PgExecuteCustomTemplate ¶
func PgExecuteCustomTemplate(st *StructTemplate, customTmpl string) ([]byte, error)
PgExecuteCustomTemplate execute custom template
Types ¶
type AutoKeyMap ¶
type AutoKeyMap struct {
Types []string `toml:"db_types"`
}
AutoKeyMap auto generating key config
type PgColumn ¶
type PgColumn struct { FieldOrdinal int Name string DataType string DDLType string NotNull bool DefaultValue sql.NullString IsPrimaryKey bool }
PgColumn postgres columns
type PgTable ¶
type PgTable struct { Schema string Name string DataType string AutoGenPk bool PrimaryKeys []*PgColumn Columns []*PgColumn }
PgTable postgres table
type PgTypeMapConfig ¶
PgTypeMapConfig go/db type map struct toml config
var DefaultTypeMapCfg PgTypeMapConfig = PgTypeMapConfig{ "string": TypeMap{ DBTypes: []string{"character", "character varying", "text", "money"}, NotNullGoType: "string", NullableGoType: "sql.NullString", }, "time": TypeMap{ DBTypes: []string{"time with time zone", "time without time zone", "timestamp without time zone", "timestamp with time zone", "date"}, NotNullGoType: "time.Time", NullableGoType: "sql.NullTime", }, "bool": TypeMap{ DBTypes: []string{"boolean"}, NotNullGoType: "bool", NullableGoType: "sql.NullBool", }, "smallint": TypeMap{ DBTypes: []string{"smallint"}, NotNullGoType: "int16", NullableGoType: "sql.NullInt64", }, "integer": TypeMap{ DBTypes: []string{"integer"}, NotNullGoType: "int", NullableGoType: "sql.NullInt64", }, "bigint": TypeMap{ DBTypes: []string{"bigint"}, NotNullGoType: "int64", NullableGoType: "sql.NullInt64", }, "smallserial": TypeMap{ DBTypes: []string{"smallserial"}, NotNullGoType: "uint16", NullableGoType: "sql.NullInt64", }, "serial": TypeMap{ DBTypes: []string{"serial"}, NotNullGoType: "uint32", NullableGoType: "sql.NullInt64", }, "real": TypeMap{ DBTypes: []string{"real"}, NotNullGoType: "float32", NullableGoType: "sql.NullFloat64", }, "numeric": TypeMap{ DBTypes: []string{"numeric", "double precision"}, NotNullGoType: "float64", NullableGoType: "sql.NullFloat64", }, "bytea": TypeMap{ DBTypes: []string{"bytea"}, NotNullGoType: "[]byte", NullableGoType: "[]byte", }, "json": TypeMap{ DBTypes: []string{"json", "jsonb"}, NotNullGoType: "[]byte", NullableGoType: "[]byte", }, "xml": TypeMap{ DBTypes: []string{"xml"}, NotNullGoType: "[]byte", NullableGoType: "[]byte", }, "interval": TypeMap{ DBTypes: []string{"interval"}, NotNullGoType: "time.Duration", NullableGoType: "*time.Duration", }, "default": TypeMap{ DBTypes: []string{"*"}, NotNullGoType: "interface{}", NullableGoType: "interface{}", }, }
DefaultTypeMapCfg is the default type map configuration
func PgLoadTypeMapFromFile ¶
func PgLoadTypeMapFromFile(filePath string) (*PgTypeMapConfig, error)
PgLoadTypeMapFromFile load type map from toml file
type Queryer ¶
type Queryer interface { Exec(string, ...interface{}) (sql.Result, error) Query(string, ...interface{}) (*sql.Rows, error) QueryRow(string, ...interface{}) *sql.Row ExecContext(context.Context, string, ...interface{}) (sql.Result, error) QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error) QueryRowContext(context.Context, string, ...interface{}) *sql.Row }
Queryer database/sql compatible query interface
type Struct ¶
type Struct struct { Name string Table *PgTable Comment string Fields []*StructField }
Struct go struct
func PgTableToStruct ¶
func PgTableToStruct(t *PgTable, typeCfg *PgTypeMapConfig, keyConfig *AutoKeyMap) (*Struct, error)
PgTableToStruct converts table def to go struct
type StructField ¶
StructField go struct field
func PgColToField ¶
func PgColToField(col *PgColumn, typeCfg *PgTypeMapConfig) (*StructField, error)
PgColToField converts pg column to go struct field
type StructTemplate ¶
type StructTemplate struct {
Struct *Struct
}
StructTemplate go struct passed to template