dialects

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2020 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatColumnTime

func FormatColumnTime(dialect Dialect, defaultTimeZone *time.Location, col *schemas.Column, t time.Time) (v interface{})

func FormatTime

func FormatTime(dialect Dialect, sqlTypeName string, t time.Time) (v interface{})

FormatTime format time as column type

func FullTableName

func FullTableName(dialect Dialect, mapper names.Mapper, bean interface{}, includeSchema ...bool) string

FullTableName returns table name with quote and schema according parameter

func RegisterDialect

func RegisterDialect(dbName schemas.DBType, dialectFunc func() Dialect)

RegisterDialect register database dialect

func RegisterDriver

func RegisterDriver(driverName string, driver Driver)

func RegisteredDriverSize

func RegisteredDriverSize() int

func TableNameNoSchema

func TableNameNoSchema(dialect Dialect, mapper names.Mapper, tableName interface{}) string

TableNameNoSchema returns table name with given tableName

func TableNameWithSchema

func TableNameWithSchema(dialect Dialect, tableName string) string

TableNameWithSchema will add schema prefix on table name if possible

Types

type Base

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

Base represents a basic dialect and all real dialects could embed this struct

func (*Base) AddColumnSQL

func (db *Base) AddColumnSQL(tableName string, col *schemas.Column) string

func (*Base) CreateIndexSQL

func (db *Base) CreateIndexSQL(tableName string, index *schemas.Index) string

func (*Base) DB

func (b *Base) DB() *core.DB

func (*Base) DBType

func (b *Base) DBType() schemas.DBType

func (*Base) DefaultSchema

func (b *Base) DefaultSchema() string

func (*Base) DropIndexSQL

func (db *Base) DropIndexSQL(tableName string, index *schemas.Index) string

func (*Base) DropTableSQL

func (db *Base) DropTableSQL(tableName string) (string, bool)

func (*Base) ForUpdateSQL

func (b *Base) ForUpdateSQL(query string) string

func (*Base) FormatBytes

func (b *Base) FormatBytes(bs []byte) string

func (*Base) HasRecords

func (db *Base) HasRecords(ctx context.Context, query string, args ...interface{}) (bool, error)

func (*Base) Init

func (b *Base) Init(db *core.DB, dialect Dialect, uri *URI) error

func (*Base) IsColumnExist

func (db *Base) IsColumnExist(ctx context.Context, tableName, colName string) (bool, error)

func (*Base) ModifyColumnSQL

func (db *Base) ModifyColumnSQL(tableName string, col *schemas.Column) string

func (*Base) Quoter

func (b *Base) Quoter() schemas.Quoter

func (*Base) SetParams

func (b *Base) SetParams(params map[string]string)

func (*Base) String

func (b *Base) String(col *schemas.Column) string

String generate column description string according dialect

func (*Base) StringNoPk

func (b *Base) StringNoPk(col *schemas.Column) string

StringNoPk generate column description string according dialect without primary keys

func (*Base) URI

func (b *Base) URI() *URI

type Dialect

type Dialect interface {
	Init(*core.DB, *URI) error
	URI() *URI
	DB() *core.DB
	SQLType(*schemas.Column) string
	FormatBytes(b []byte) string
	DefaultSchema() string

	IsReserved(string) bool
	Quoter() schemas.Quoter
	SetQuotePolicy(quotePolicy QuotePolicy)

	AutoIncrStr() string

	GetIndexes(ctx context.Context, tableName string) (map[string]*schemas.Index, error)
	IndexCheckSQL(tableName, idxName string) (string, []interface{})
	CreateIndexSQL(tableName string, index *schemas.Index) string
	DropIndexSQL(tableName string, index *schemas.Index) string

	GetTables(ctx context.Context) ([]*schemas.Table, error)
	IsTableExist(ctx context.Context, tableName string) (bool, error)
	CreateTableSQL(table *schemas.Table, tableName string) ([]string, bool)
	DropTableSQL(tableName string) (string, bool)

	GetColumns(ctx context.Context, tableName string) ([]string, map[string]*schemas.Column, error)
	IsColumnExist(ctx context.Context, tableName string, colName string) (bool, error)
	AddColumnSQL(tableName string, col *schemas.Column) string
	ModifyColumnSQL(tableName string, col *schemas.Column) string

	ForUpdateSQL(query string) string

	Filters() []Filter
	SetParams(params map[string]string)
}

Dialect represents a kind of database

func OpenDialect

func OpenDialect(driverName, connstr string) (Dialect, error)

OpenDialect opens a dialect via driver name and connection string

func QueryDialect

func QueryDialect(dbName schemas.DBType) Dialect

QueryDialect query if registered database dialect

type Driver

type Driver interface {
	Parse(string, string) (*URI, error)
}

func QueryDriver

func QueryDriver(driverName string) Driver

type Filter

type Filter interface {
	Do(sql string) string
}

Filter is an interface to filter SQL

type QuotePolicy

type QuotePolicy int

QuotePolicy describes quote handle policy

const (
	QuotePolicyAlways QuotePolicy = iota
	QuotePolicyNone
	QuotePolicyReserved
)

All QuotePolicies

type SeqFilter

type SeqFilter struct {
	Prefix string
	Start  int
}

SeqFilter filter SQL replace ?, ? ... to $1, $2 ...

func (*SeqFilter) Do

func (s *SeqFilter) Do(sql string) string

type URI

type URI struct {
	DBType  schemas.DBType
	Proto   string
	Host    string
	Port    string
	DBName  string
	User    string
	Passwd  string
	Charset string
	Laddr   string
	Raddr   string
	Timeout time.Duration
	Schema  string
}

URI represents an uri to visit database

func (URI) SetSchema

func (uri URI) SetSchema(schema string)

SetSchema set schema

Jump to

Keyboard shortcuts

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