sql

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(dsn string) dbal.Grammar

New Create a new mysql grammar inteface

Types

type Quoter

type Quoter struct {
	DB         *sqlx.DB
	DBPrimary  *sqlx.DB
	DBReadOnly *sqlx.DB
	Prefix     string
}

Quoter the database quoting query text SQL type

func (*Quoter) Bind added in v0.5.1

func (quoter *Quoter) Bind(db *sqlx.DB, prefix string, dbRead ...*sqlx.DB) dbal.Quoter

Bind make a new Quoter inteface

func (*Quoter) Columnize added in v0.5.1

func (quoter *Quoter) Columnize(columns []interface{}) string

Columnize Convert an array of column names into a delimited string.

func (*Quoter) ID

func (quoter *Quoter) ID(value string) string

ID quoting query Identifier (`id`)

func (*Quoter) IsExpression added in v0.5.1

func (quoter *Quoter) IsExpression(value interface{}) bool

IsExpression Determine if the given value is a raw expression.

func (*Quoter) Parameter added in v0.5.1

func (quoter *Quoter) Parameter(value interface{}, num int) string

Parameter Get the appropriate query parameter place-holder for a value.

func (*Quoter) Parameterize added in v0.5.1

func (quoter *Quoter) Parameterize(values []interface{}, offset int) string

Parameterize Create query parameter place-holders for an array.

func (*Quoter) Read added in v0.5.1

func (quoter *Quoter) Read() dbal.Quoter

Read pick the readonly connection

func (*Quoter) VAL

func (quoter *Quoter) VAL(value interface{}) string

VAL quoting query value ( 'value' )

func (*Quoter) Wrap added in v0.5.1

func (quoter *Quoter) Wrap(value interface{}) string

Wrap a value in keyword identifiers.

func (*Quoter) WrapAliasedValue added in v0.5.1

func (quoter *Quoter) WrapAliasedValue(value string) string

WrapAliasedValue Wrap a value that has an alias.

func (*Quoter) WrapTable added in v0.5.1

func (quoter *Quoter) WrapTable(value interface{}) string

WrapTable Wrap a table in keyword identifiers.

func (*Quoter) WrapUnion added in v0.5.1

func (quoter *Quoter) WrapUnion(sql string) string

WrapUnion a union subquery in parentheses.

func (*Quoter) Write added in v0.5.1

func (quoter *Quoter) Write() dbal.Quoter

Write pick the primary connection

type SQL

type SQL struct {
	Driver       string
	Mode         string
	Types        map[string]string
	FlipTypes    map[string]string
	IndexTypes   map[string]string
	DatabaseName string
	SchemaName   string
	DB           *sqlx.DB
	Config       *dbal.Config
	Read         *sqlx.DB
	ReadConfig   *dbal.Config
	Option       *dbal.Option
	dbal.Grammar
	dbal.Quoter
}

SQL the SQL Grammar

func NewSQL

func NewSQL(quoter dbal.Quoter) SQL

NewSQL create a new SQL instance

func (SQL) AlterTable added in v0.0.3

func (grammarSQL SQL) AlterTable(table *dbal.Table) error

AlterTable alter a table on the schema

func (SQL) CompileAggregate added in v0.5.1

func (grammarSQL SQL) CompileAggregate(query *dbal.Query, aggregate dbal.Aggregate) string

CompileAggregate Compile an aggregated select clause.

func (SQL) CompileColumns added in v0.5.1

func (grammarSQL SQL) CompileColumns(query *dbal.Query, columns []interface{}, bindingOffset *int) string

CompileColumns Compile the "select *" portion of the query.

func (SQL) CompileDelete added in v0.5.1

func (grammarSQL SQL) CompileDelete(query *dbal.Query) (string, []interface{})

CompileDelete Compile a delete statement into SQL.

func (SQL) CompileExists added in v0.5.1

func (grammarSQL SQL) CompileExists(query *dbal.Query) string

CompileExists Compile an exists statement into SQL.

func (SQL) CompileFrom added in v0.5.1

func (grammarSQL SQL) CompileFrom(query *dbal.Query, from dbal.From, bindingOffset *int) string

CompileFrom Compile the "from" portion of the query.

func (SQL) CompileGroups added in v0.5.1

func (grammarSQL SQL) CompileGroups(query *dbal.Query, groups []interface{}, bindingOffset *int) string

CompileGroups Compile the "group by" portions of the query.

func (SQL) CompileHaving added in v0.5.1

func (grammarSQL SQL) CompileHaving(query *dbal.Query, having dbal.Having, bindingOffset *int) string

CompileHaving Compile a single having clause.

func (SQL) CompileHavings added in v0.5.1

func (grammarSQL SQL) CompileHavings(query *dbal.Query, havings []dbal.Having, bindingOffset *int) string

CompileHavings Compile the "having" portions of the query.

func (SQL) CompileInsert added in v0.5.1

func (grammarSQL SQL) CompileInsert(query *dbal.Query, columns []interface{}, values [][]interface{}) (string, []interface{})

CompileInsert Compile an insert statement into SQL.

func (SQL) CompileInsertGetID added in v0.5.1

func (grammarSQL SQL) CompileInsertGetID(query *dbal.Query, columns []interface{}, values [][]interface{}, sequence string) (string, []interface{})

CompileInsertGetID Compile an insert and get ID statement into SQL.

func (SQL) CompileInsertOrIgnore added in v0.5.1

func (grammarSQL SQL) CompileInsertOrIgnore(query *dbal.Query, columns []interface{}, values [][]interface{}) (string, []interface{})

CompileInsertOrIgnore Compile an insert ignore statement into SQL.

func (SQL) CompileInsertUsing added in v0.5.1

func (grammarSQL SQL) CompileInsertUsing(query *dbal.Query, columns []interface{}, sql string) string

CompileInsertUsing Compile an insert statement using a subquery into SQL.

func (SQL) CompileJoins added in v0.5.1

func (grammarSQL SQL) CompileJoins(query *dbal.Query, joins []dbal.Join, offset *int) string

CompileJoins Compile the "join" portions of the query.

func (SQL) CompileLimit added in v0.5.1

func (grammarSQL SQL) CompileLimit(query *dbal.Query, limit int, bindingOffset *int) string

CompileLimit Compile the "limit" portions of the query.

func (SQL) CompileLock added in v0.5.1

func (grammarSQL SQL) CompileLock(query *dbal.Query, lock interface{}) string

CompileLock the lock into SQL.

func (SQL) CompileOffset added in v0.5.1

func (grammarSQL SQL) CompileOffset(query *dbal.Query, offset int) string

CompileOffset Compile the "offset" portions of the query.

func (SQL) CompileOrders added in v0.5.1

func (grammarSQL SQL) CompileOrders(query *dbal.Query, orders []dbal.Order, bindingOffset *int) string

CompileOrders Compile the "order by" portions of the query.

func (SQL) CompileSelect added in v0.5.1

func (grammarSQL SQL) CompileSelect(query *dbal.Query) string

CompileSelect Compile a select query into SQL.

func (SQL) CompileSelectOffset added in v0.5.1

func (grammarSQL SQL) CompileSelectOffset(query *dbal.Query, offset *int) string

CompileSelectOffset Compile a select query into SQL.

func (SQL) CompileSub added in v0.5.1

func (grammarSQL SQL) CompileSub(sub interface{}, offset *int) string

CompileSub Parse the subquery into SQL and bindings.

func (SQL) CompileTruncate added in v0.5.1

func (grammarSQL SQL) CompileTruncate(query *dbal.Query) ([]string, [][]interface{})

CompileTruncate Compile a truncate table statement into SQL.

func (SQL) CompileUnion added in v0.5.1

func (grammarSQL SQL) CompileUnion(query *dbal.Query, union dbal.Union, offset *int) string

CompileUnion Compile a single union statement.

func (SQL) CompileUnionAggregate added in v0.5.1

func (grammarSQL SQL) CompileUnionAggregate(query *dbal.Query) string

CompileUnionAggregate Compile a union aggregate query into SQL.

func (SQL) CompileUnions added in v0.5.1

func (grammarSQL SQL) CompileUnions(query *dbal.Query, unions []dbal.Union, offset *int) string

CompileUnions Compile the "union" queries attached to the main query.

func (SQL) CompileUpdate added in v0.5.1

func (grammarSQL SQL) CompileUpdate(query *dbal.Query, values map[string]interface{}) (string, []interface{})

CompileUpdate Compile an update statement into SQL.

func (SQL) CompileUpdateColumns added in v0.5.1

func (grammarSQL SQL) CompileUpdateColumns(query *dbal.Query, values map[string]interface{}, offset *int) (string, []interface{})

CompileUpdateColumns Compile the columns for an update statement.

func (SQL) CompileUpsert added in v0.5.1

func (grammarSQL SQL) CompileUpsert(query *dbal.Query, columns []interface{}, values [][]interface{}, uniqueBy []interface{}, updateValues interface{}) (string, []interface{})

CompileUpsert Compile an "upsert" statement into SQL.

func (SQL) CompileWheres added in v0.5.1

func (grammarSQL SQL) CompileWheres(query *dbal.Query, wheres []dbal.Where, bindingOffset *int) string

CompileWheres Compile an update statement into SQL.

func (SQL) CreateTable added in v0.0.3

func (grammarSQL SQL) CreateTable(table *dbal.Table) error

CreateTable create a new table on the schema

func (SQL) DropTable added in v0.0.3

func (grammarSQL SQL) DropTable(name string) error

DropTable a table from the schema.

func (SQL) DropTableIfExists added in v0.0.3

func (grammarSQL SQL) DropTableIfExists(name string) error

DropTableIfExists if the table exists, drop it from the schema.

func (SQL) ExecSQL

func (grammarSQL SQL) ExecSQL(table *dbal.Table, sql string) error

ExecSQL execute sql then update table structure

func (SQL) GetColumnListing

func (grammarSQL SQL) GetColumnListing(dbName string, tableName string) ([]*dbal.Column, error)

GetColumnListing get a table columns structure

func (SQL) GetDatabase added in v0.0.3

func (grammarSQL SQL) GetDatabase() string

GetDatabase get the database name of the current connection

func (SQL) GetDefaultValue added in v0.5.1

func (grammarSQL SQL) GetDefaultValue(column *dbal.Column) string

GetDefaultValue get the default value

func (SQL) GetIndexListing

func (grammarSQL SQL) GetIndexListing(dbName string, tableName string) ([]*dbal.Index, error)

GetIndexListing get a table indexes structure

func (SQL) GetOperators added in v0.5.1

func (grammarSQL SQL) GetOperators() []string

GetOperators get the operators

func (SQL) GetSchema added in v0.0.3

func (grammarSQL SQL) GetSchema() string

GetSchema get the schema name of the current connection

func (SQL) GetTable added in v0.0.3

func (grammarSQL SQL) GetTable(name string) (*dbal.Table, error)

GetTable get a table on the schema

func (SQL) GetTables added in v0.0.3

func (grammarSQL SQL) GetTables() ([]string, error)

GetTables Get all of the table names for the database.

func (SQL) GetTypeFromComment added in v0.0.3

func (grammarSQL SQL) GetTypeFromComment(comment *string) string

GetTypeFromComment Get the type name from comment

func (SQL) GetVersion added in v0.0.3

func (grammarSQL SQL) GetVersion() (*dbal.Version, error)

GetVersion get the version of the connection database

func (SQL) HavingBasic added in v0.5.1

func (grammarSQL SQL) HavingBasic(query *dbal.Query, having dbal.Having, bindingOffset *int) string

HavingBasic Compile a basic having clause.

func (SQL) HavingBetween added in v0.5.1

func (grammarSQL SQL) HavingBetween(query *dbal.Query, having dbal.Having, bindingOffset *int) string

HavingBetween Compile a "between" having clause.

func (SQL) NewWith added in v0.0.3

func (grammarSQL SQL) NewWith(db *sqlx.DB, config *dbal.Config, option *dbal.Option) (dbal.Grammar, error)

NewWith Create a new grammar interface, using the given *sqlx.DB, *dbal.Config and *dbal.Option.

func (SQL) NewWithRead added in v0.5.1

func (grammarSQL SQL) NewWithRead(write *sqlx.DB, writeConfig *dbal.Config, read *sqlx.DB, readConfig *dbal.Config, option *dbal.Option) (dbal.Grammar, error)

NewWithRead Create a new grammar interface, using the given *sqlx.DB, *dbal.Config and *dbal.Option.

func (SQL) OnConnected added in v0.0.3

func (grammarSQL SQL) OnConnected() error

OnConnected the event will be triggered when db server was connected

func (SQL) ProcessInsertGetID added in v0.5.1

func (grammarSQL SQL) ProcessInsertGetID(sql string, bindings []interface{}, sequence string) (int64, error)

ProcessInsertGetID Execute an insert and get ID statement and return the id

func (SQL) Raw added in v0.5.1

func (grammarSQL SQL) Raw(value string) dbal.Expression

Raw make a new expression

func (SQL) RemoveLeadingBoolean added in v0.5.1

func (grammarSQL SQL) RemoveLeadingBoolean(value string) string

RemoveLeadingBoolean Remove the leading boolean from a statement.

func (SQL) RenameTable added in v0.0.3

func (grammarSQL SQL) RenameTable(old string, new string) error

RenameTable rename a table on the schema.

func (SQL) SQLAddColumn added in v0.0.3

func (grammarSQL SQL) SQLAddColumn(column *dbal.Column) string

SQLAddColumn return the add column sql for table create

func (SQL) SQLAddIndex added in v0.0.3

func (grammarSQL SQL) SQLAddIndex(index *dbal.Index) string

SQLAddIndex return the add index sql for table create

func (SQL) SQLAddPrimary added in v0.0.3

func (grammarSQL SQL) SQLAddPrimary(primary *dbal.Primary) string

SQLAddPrimary return the add primary key sql for table create

func (SQL) TableExists added in v0.0.3

func (grammarSQL SQL) TableExists(name string) (bool, error)

TableExists check if the table exists

func (SQL) WhereBasic added in v0.5.1

func (grammarSQL SQL) WhereBasic(query *dbal.Query, where dbal.Where, bindingOffset *int) string

WhereBasic Compile a date based where clause.

func (SQL) WhereBetween added in v0.5.1

func (grammarSQL SQL) WhereBetween(query *dbal.Query, where dbal.Where, bindingOffset *int) string

WhereBetween Compile a "between" where clause.

func (SQL) WhereColumn added in v0.5.1

func (grammarSQL SQL) WhereColumn(query *dbal.Query, where dbal.Where, bindingOffset *int) string

WhereColumn Compile a where clause comparing two columns.

func (SQL) WhereDate added in v0.5.1

func (grammarSQL SQL) WhereDate(query *dbal.Query, where dbal.Where, bindingOffset *int) string

WhereDate Compile a "where date" clause.

func (SQL) WhereDateBased added in v0.5.1

func (grammarSQL SQL) WhereDateBased(typ string, query *dbal.Query, where dbal.Where, bindingOffset *int) string

WhereDateBased Compile a date based where clause.

func (SQL) WhereDay added in v0.5.1

func (grammarSQL SQL) WhereDay(query *dbal.Query, where dbal.Where, bindingOffset *int) string

WhereDay Compile a "where day" clause.

func (SQL) WhereExists added in v0.5.1

func (grammarSQL SQL) WhereExists(query *dbal.Query, where dbal.Where, bindingOffset *int) string

WhereExists Compile a where (not) exists clause.

func (SQL) WhereIn added in v0.5.1

func (grammarSQL SQL) WhereIn(query *dbal.Query, where dbal.Where, bindingOffset *int) string

WhereIn Compile a "where in" clause.

func (SQL) WhereMonth added in v0.5.1

func (grammarSQL SQL) WhereMonth(query *dbal.Query, where dbal.Where, bindingOffset *int) string

WhereMonth Compile a "where month" clause.

func (SQL) WhereNested added in v0.5.1

func (grammarSQL SQL) WhereNested(query *dbal.Query, where dbal.Where, bindingOffset *int) string

WhereNested Compile a nested where clause.

func (SQL) WhereNotnull added in v0.5.1

func (grammarSQL SQL) WhereNotnull(query *dbal.Query, where dbal.Where, bindingOffset *int) string

WhereNotnull Compile a "where not null" clause.

func (SQL) WhereNull added in v0.5.1

func (grammarSQL SQL) WhereNull(query *dbal.Query, where dbal.Where, bindingOffset *int) string

WhereNull Compile a "where null" clause.

func (SQL) WhereRaw added in v0.5.1

func (grammarSQL SQL) WhereRaw(query *dbal.Query, where dbal.Where, bindingOffset *int) string

WhereRaw Compile a raw where clause.

func (SQL) WhereSub added in v0.5.1

func (grammarSQL SQL) WhereSub(query *dbal.Query, where dbal.Where, bindingOffset *int) string

WhereSub Compile a where condition with a sub-select.

func (SQL) WhereTime added in v0.5.1

func (grammarSQL SQL) WhereTime(query *dbal.Query, where dbal.Where, bindingOffset *int) string

WhereTime Compile a "where time" clause.

func (SQL) WhereYear added in v0.5.1

func (grammarSQL SQL) WhereYear(query *dbal.Query, where dbal.Where, bindingOffset *int) string

WhereYear Compile a "where year" clause.

func (SQL) Wrap added in v0.5.1

func (grammarSQL SQL) Wrap(value interface{}) string

Wrap a value in keyword identifiers.

func (SQL) WrapTable added in v0.5.1

func (grammarSQL SQL) WrapTable(value interface{}) string

WrapTable Wrap a table in keyword identifiers.

Jump to

Keyboard shortcuts

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