dialect

package
v0.41.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2019 License: BSD-2-Clause Imports: 8 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() quote.Quoter
	// WithQuoter returns a modified Dialect with a given quoter.
	WithQuoter(q quote.Quoter) Dialect

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

	// ReplacePlaceholders alters a query string by replacing the '?' placeholders with the appropriate
	// placeholders needed by this dialect. For MySQL and SQlite3, the string is returned unchanged.
	ReplacePlaceholders(sql string, args []interface{}) string
	// Placeholders returns a comma-separated list of n placeholders.
	Placeholders(n int) string
	// HasNumberedPlaceholders returns true for dialects such as PostgreSQL that use numbered placeholders.
	HasNumberedPlaceholders() bool
	// HasLastInsertId returns true for dialects such as MySQL that return a last-insert ID after each INSERT.
	HasLastInsertId() bool
}

Dialect is an abstraction of a type of database.

var Mysql Dialect = mysql{/* contains filtered or unexported fields */}
var Pgx Dialect = pgx{}
var Postgres Dialect = postgres{/* contains filtered or unexported fields */}
var Sqlite Dialect = sqlite{/* contains filtered or unexported fields */}

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 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