dbvendor

package
v2.3.7 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Update used for update_at column
	Update = "on update CURRENT_TIMESTAMP"
)

Variables

View Source
var (
	// Question is a PlaceholderFormat instance that leaves placeholders as
	// question marks.
	Question = questionFormat{}

	// Dollar is a PlaceholderFormat instance that replaces placeholders with
	// dollar-prefixed positional placeholders (e.g. $1, $2, $3).
	Dollar = dollarFormat{}

	// Colon is a PlaceholderFormat instance that replaces placeholders with
	// colon-prefixed positional placeholders (e.g. :1, :2, :3).
	Colon = colonFormat{}

	// AtP is a PlaceholderFormat instance that replaces placeholders with
	// "@p"-prefixed positional placeholders (e.g. @p1, @p2, @p3).
	AtP = atpFormat{}
)
View Source
var Registry = &registry{
	vendors: map[string]IVendor{},
}

Functions

func Placeholders

func Placeholders(count int) string

Placeholders returns a string with count ? placeholders joined with commas.

func Scan

func Scan(rows *sql.Rows, result *[]map[string]interface{})

func String

func String(tmplname, tmpl string, data interface{}, pf PlaceholderFormat) (string, error)

func StringBlock

func StringBlock(tmplname, tmpl string, block string, data interface{}, pf PlaceholderFormat) (string, error)

Types

type Column

type Column struct {
	TablePrefix   string
	Table         string
	Name          string
	OldName       string
	Type          string
	Default       *string
	Pk            bool
	Nullable      bool
	Unsigned      bool
	Autoincrement bool
	Extra         string
	Comment       string
	// 关联表名
	Foreign string
}

Column define a column

type DMLSchema

type DMLSchema struct {
	Schema        string
	TablePrefix   string
	TableName     string
	InsertColumns []Column
	UpdateColumns []Column
	Pk            []Column
}

type IVendor

type IVendor interface {
	CreateTable(ctx context.Context, db *gorm.DB, t Table) error
	DropTable(ctx context.Context, db *gorm.DB, t Table) error
	ChangeColumn(ctx context.Context, db *gorm.DB, col Column) error
	AddColumn(ctx context.Context, db *gorm.DB, col Column) error
	DropColumn(ctx context.Context, db *gorm.DB, col Column) error
	ToColumnType(goType string, autoincrementing bool) string

	Insert(ctx context.Context, db *gorm.DB, dml DMLSchema, args ...interface{}) (int64, error)
	Update(ctx context.Context, db *gorm.DB, dml DMLSchema, args ...interface{}) error
	Delete(ctx context.Context, db *gorm.DB, dml DMLSchema, args ...interface{}) error
	SelectById(ctx context.Context, db *gorm.DB, dml DMLSchema, args ...interface{}) (map[string]interface{}, error)
	GetInsertStatement(dml DMLSchema) (statement string, err error)
	GetInsertReturningPkStatement(dml DMLSchema) (statement string, err error)
	GetBatchInsertStatement(dml DMLSchema, rows []interface{}) (statement string, err error)
	GetUpdateStatement(dml DMLSchema) (statement string, err error)
}

type Index added in v2.2.8

type Index struct {
	Name        string
	Columns     []string
	Cardinality []uint64
	NoneUnique  uint64
}

type PlaceholderFormat

type PlaceholderFormat interface {
	ReplacePlaceholders(sql string) (string, error)
}

PlaceholderFormat is the interface that wraps the ReplacePlaceholders method.

ReplacePlaceholders takes a SQL statement and replaces each question mark placeholder with a (possibly different) SQL placeholder.

type Table

type Table struct {
	TablePrefix string
	Name        string
	Columns     []Column
	BizColumns  []Column
	Pk          []string
	Joins       []string
	Indexes     []*Index
	// 父表
	Inherited string
}

Table defines a table

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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