dialect

package
v0.21.1 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2019 License: BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SqliteIndex = iota
	MysqlIndex
	PostgresIndex
	PgxIndex
)

Variables

View Source
var AllDialects = []Dialect{Sqlite, Mysql, Postgres, Pgx}

AllDialects lists all currently-supported dialects.

Functions

This section is empty.

Types

type Dialect

type Dialect interface {
	// Index returns a consistent ID for this dialect, regardless of other settings.
	Index() int
	// String returns the name of this dialect.
	String() string
	// Alias is an alternative name for this dialect.
	Alias() string
	// Quoter is the tool used for quoting identifiers.
	Quoter() Quoter
	// WithQuoter returns a modified Dialect with a given quoter.
	WithQuoter(q Quoter) Dialect

	FieldAsColumn(field *schema.Field) string
	TruncateDDL(tableName string, force bool) []string
	CreateTableSettings() string
	InsertHasReturningPhrase() bool
	ShowTables() string

	ReplacePlaceholders(sql string, args []interface{}) string
	Placeholders(n int) string
	HasNumberedPlaceholders() bool
}

Dialect is an abstraction of a type of database.

var Mysql Dialect = mysql(mySqlQuoter)
var Pgx Dialect = pgx{}
var Postgres Dialect = postgres(ansiQuoter)
var Sqlite Dialect = sqlite(ansiQuoter)

func PickDialect

func PickDialect(name string) Dialect

PickDialect finds a dialect that matches by name, ignoring letter case. It returns nil if not found.

type Quoter

type Quoter interface {
	Quote(identifier string) string
	QuoteN(identifiers []string) []string
	QuoteW(w StringWriter, identifier string)
}

Quoter wraps identifiers in quote marks. Compound identifers (i.e. those with an alias prefix) are handled according to SQL grammar.

var (
	// AnsiQuoter wraps identifiers in double quotes.
	AnsiQuoter Quoter = ansiQuoter

	// MySqlQuoter wraps identifiers in back-ticks.
	MySqlQuoter Quoter = mySqlQuoter

	// NoQuoter leaves identifiers unquoted.
	NoQuoter Quoter = noQuoter

	// DefaultQuoter is used by default. Change this to affect the default setting for every
	// SQL construction function.
	DefaultQuoter = AnsiQuoter
)

func NewQuoter

func NewQuoter(mark string) Quoter

NewQuoter gets a quoter using arbitrary quote marks.

type StringWriter

type StringWriter interface {
	io.Writer
	WriteString(s string) (n int, err error)
	String() string
}

StringWriter is an interface that wraps the WriteString method. Note that bytes.Buffer happens to implement this interface.

func Adapt

func Adapt(w io.Writer) StringWriter

Adapt wraps an io.Writer as a StringWriter.

Jump to

Keyboard shortcuts

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