dbgen

package module
v0.0.0-...-bb41262 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2021 License: MIT Imports: 9 Imported by: 0

README

dbgen

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

func (*Buffer) Convert

func (b *Buffer) Convert() ([]byte, error)

type BufferMap

type BufferMap map[string]*Buffer

type Column

type Column struct {
	TableCatalog           string
	TableSchema            string
	TableName              string
	ColumnName             string
	OrdinalPosition        int64
	ColumnDefault          sql.NullString
	IsNullAble             string
	DataType               string
	CharacterMaximumLength []uint8
	CharacterOctetLength   []uint8
	NumericPrecision       []uint8
	NumericScale           []uint8
	DatetimePrecision      []uint8
	CharacterSetName       sql.NullString
	CollationName          sql.NullString
	ColumnType             string
	ColumnKey              string
	Extra                  string
	Privileges             string
	ColumnComment          string
}

type ColumnSchema

type ColumnSchema struct {
	Column
	GoFieldName  string
	GoFieldType  string
	GoTags       string
	IsNullAble   bool
	IsPrimaryKey bool
}

type ExtraField

type ExtraField struct {
	Line          string
	ImportPackage string
}

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

func New

func New(db *sql.DB, options ...Options) *Generator

func (*Generator) Generate

func (g *Generator) Generate() (BufferMap, error)

type Options

type Options struct {
	GoPackage      string // main by default
	GeneratorName  string // dbgen by default
	DisableNull    bool
	Tables         []string                 // all tables if it's nil or empty
	OutputPathFunc func(table Table) string // os.Stdout if it's nil or returns empty string

	FieldTypeFunc           func(column ColumnSchema) (fieldType string, importPackage string, err error) // general field type if returns empty field type
	FieldNameFunc           func(column ColumnSchema) string
	TagsFunc                func(column ColumnSchema) Tags
	IgnoreColumnFunc        func(column ColumnSchema) bool
	StructureNameFunc       func(table Table) string
	TemplatePreparationFunc func(table Table) (interface{}, []string)
	Template                *template.Template
	EnableGoImports         bool
	ExtraFieldFunc          func(table Table) []*ExtraField
}

func DefaultOptions

func DefaultOptions() Options

type Table

type Table struct {
	Name            string
	GoStructureName string
	Columns         []*ColumnSchema
	ExtraFields     []*ExtraField
}

type Tag

type Tag struct {
	// contains filtered or unexported fields
}

func NewTag

func NewTag(key, value string) *Tag

func (Tag) String

func (t Tag) String() string

type Tags

type Tags []*Tag

func NewTags

func NewTags(tags ...*Tag) Tags

func (Tags) String

func (ts Tags) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL