Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var UseStructTag = `col`
UseStructTag specifies the struct tag key for the column name. Default is `col`.
var UseTokenType = QuestionMarkTokenType
UseTokenType specifies the token type to use for values. Default is the question mark (`?`).
Functions ¶
Types ¶
type Insert ¶
type Insert struct {
Table string
Data interface{}
}
Insert models data used to produce a valid SQL INSERT statement with bind args. Table is the table name. Data is either a struct with column-name tagged fields and the data to be inserted or a slice struct (struct ptr works too). Private recordType and recordValue fields are used with reflection to get struct tags for Insert.Columns, Insert.Params, and Insert.SQL and to retrieve values for Insert.Args.
func (*Insert) Args ¶
func (ins *Insert) Args() []interface{}
Args returns the arguments to be bound in Insert() or the variadic Exec/ExecContext functions in database/sql.
func (*Insert) Columns ¶
Columns returns the comma-separated list of column names-as-tokens for the SQL INSERT statement. Multi Row Insert: Insert.Data is a slice; first item in slice is
func (*Insert) Insert ¶
func (ins *Insert) Insert(with InsertWith) (*sql.Stmt, error)
Insert prepares and executes a SQL INSERT statement on a *sql.DB, *sql.Tx, or other Inserter-compatible interface to Prepare and Exec.
func (*Insert) InsertContext ¶
InsertContext prepares and executes a SQL INSERT statement on a *sql.DB, *sql.Tx, *sql.Conn, or other Inserter-compatible interface to PrepareContext and ExecContext.
type InsertWith ¶
type InsertWith interface {
Prepare(query string) (*sql.Stmt, error)
PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
Exec(query string, args ...interface{}) (sql.Result, error)
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
}
InsertWith models functionality needed to execute a SQL INSERT statement with database/sql via sql.DB or sql.Tx. Note: sql.Conn is also supported, however, for PrepareContext and ExecContext only.
type Inserter ¶
type Inserter interface {
Tokenize(tokenType TokenType) string
Columns() string
Params() string
SQL() string
Args() []interface{}
Insert(with InsertWith) (*sql.Stmt, error)
InsertContext(ctx context.Context, with InsertWith) (*sql.Stmt, error)
}
Inserter models functionality to produce a valid SQL INSERT statement with bind args.
type TokenType ¶
type TokenType int
TokenType represents a type of token in a SQL INSERT statement, whether column or value expression.
const ( // ColumnNameTokenType uses the column name from the struct tag specified by UseStructTag. // INSERT INTO tbl (foo, bar, ... baz) ColumnNameTokenType TokenType = 0 // QuestionMarkTokenType uses question marks as value-tokens. // VALUES (?, ?, ... ?) -- MySQL, SingleStore QuestionMarkTokenType TokenType = 1 // AtColumnNameTokenType uses @ followed by the column name from the struct tag specified by UseStructTag. // VALUES (@foo, @bar, ... @baz) -- MySQL, SingleStore AtColumnNameTokenType TokenType = 2 // OrdinalNumberTokenType uses % plus the value of an ordered sequence of integers starting at 1. // %1, %2, ... %n -- Postgres OrdinalNumberTokenType TokenType = 3 // ColonTokenType uses : followed by the column name from the struct tag specified by UseStructTag. // :foo, :bar, ... :baz -- Oracle ColonTokenType TokenType = 4 )