mysql

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: May 24, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FieldTypeBoolean = "sq.BooleanField"
	FieldTypeJSON    = "sq.JSONField"
	FieldTypeNumber  = "sq.NumberField"
	FieldTypeString  = "sq.StringField"
	FieldTypeTime    = "sq.TimeField"
	FieldTypeEnum    = "sq.EnumField"
	FieldTypeBinary  = "sq.BinaryField"

	FieldConstructorBoolean = "sq.NewBooleanField"
	FieldConstructorJSON    = "sq.NewJSONField"
	FieldConstructorNumber  = "sq.NewNumberField"
	FieldConstructorString  = "sq.NewStringField"
	FieldConstructorTime    = "sq.NewTimeField"
	FieldConstructorEnum    = "sq.NewEnumField"
	FieldConstructorBinary  = "sq.NewBinaryField"
)

Field Types

Variables

This section is empty.

Functions

func BuildTables

func BuildTables(config Config, writer io.Writer) (int, error)

Types

type Config

type Config struct {
	// (required) DB URL
	DB *sql.DB
	// Package name of the file to be generated
	Package string
	// Slice of database schemas that you want to generate tables for
	Schemas []string
	// Slice of case-insensitive table names or functions to exclude from generation
	Exclude []string
	// Used to log any skipped/unsupported column types
	Logger sqgen.Logger
}

type Table

type Table struct {
	Schema      string
	Name        string
	StructName  string
	RawType     string
	Constructor string
	Fields      []TableField
}

func (Table) Populate

func (table Table) Populate(config *Config, isDuplicate bool) Table

type TableField

type TableField struct {
	Name        string
	RawType     string
	RawTypeEx   string
	Type        string
	Constructor string
}

TableField represents a field in a database table

In the MySQL information_schema.columns table, the data_type column (mapped into TableField.RawType) has the general type of the column (i.e. char, integer, etc.), but it does not have information on the exact size of the column The information_schema.column_type column (mapped into TableField.RawTypeEx) contains the full data type for the column, including size

We need to have this extra field to distinguish between boolean columns and number columns, since MySQL stores boolean values as tinyint(1), and we can only get the (1) part from information_schema.column_type

func (TableField) Populate

func (field TableField) Populate() TableField

type TablesTemplateData

type TablesTemplateData struct {
	PackageName string
	Imports     []string
	Tables      []Table
}

Jump to

Keyboard shortcuts

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