Documentation
¶
Index ¶
- Constants
- Variables
- func MapToSlice(query string, mp interface{}) (string, []interface{}, error)
- func NonFatalError(err error) bool
- func SelectFloat(queryRunner SqlQueryRunner, query string, args ...interface{}) (float64, error)
- func SelectInt(queryRunner SqlQueryRunner, query string, args ...interface{}) (int64, error)
- func SelectNullFloat(queryRunner SqlQueryRunner, query string, args ...interface{}) (sql.NullFloat64, error)
- func SelectNullInt(queryRunner SqlQueryRunner, query string, args ...interface{}) (sql.NullInt64, error)
- func SelectNullStr(queryRunner SqlQueryRunner, query string, args ...interface{}) (sql.NullString, error)
- func SelectOne(dbUtils *DbUtils, queryRunner SqlQueryRunner, holder interface{}, query string, ...) error
- func SelectStr(queryRunner SqlQueryRunner, query string, args ...interface{}) (string, error)
- func StructToSlice(query string, st interface{}) (string, []interface{}, error)
- type ColumnMap
- type CustomScanner
- type DbUtils
- func (dbUtils *DbUtils) AddTable(i interface{}) *TableMap
- func (dbUtils *DbUtils) AddTableWithName(i interface{}, name string) *TableMap
- func (dbUtils *DbUtils) AddTableWithNameAndSchema(i interface{}, schema string, name string) *TableMap
- func (dbUtils *DbUtils) Begin() (*Transaction, error)
- func (dbUtils *DbUtils) CreateTables() error
- func (dbUtils *DbUtils) CreateTablesIfNotExists() error
- func (dbUtils *DbUtils) Delete(list ...interface{}) (int64, error)
- func (dbUtils *DbUtils) DropTables() error
- func (dbUtils *DbUtils) DropTablesIfExists() error
- func (dbUtils *DbUtils) Exec(query string, args ...interface{}) (sql.Result, error)
- func (dbUtils *DbUtils) Get(i interface{}, keys ...interface{}) (interface{}, error)
- func (dbUtils *DbUtils) Insert(list ...interface{}) error
- func (dbUtils *DbUtils) Prepare(query string) (*sql.Stmt, error)
- func (dbUtils *DbUtils) Query(q string, args ...interface{}) (*sql.Rows, error)
- func (dbUtils *DbUtils) QueryRow(query string, args ...interface{}) *sql.Row
- func (dbUtils *DbUtils) Select(i interface{}, query string, args ...interface{}) ([]interface{}, error)
- func (dbUtils *DbUtils) SelectFloat(query string, args ...interface{}) (float64, error)
- func (dbUtils *DbUtils) SelectInt(query string, args ...interface{}) (int64, error)
- func (dbUtils *DbUtils) SelectNullFloat(query string, args ...interface{}) (sql.NullFloat64, error)
- func (dbUtils *DbUtils) SelectNullInt(query string, args ...interface{}) (sql.NullInt64, error)
- func (dbUtils *DbUtils) SelectNullStr(query string, args ...interface{}) (sql.NullString, error)
- func (dbUtils *DbUtils) SelectOne(holder interface{}, query string, args ...interface{}) error
- func (dbUtils *DbUtils) SelectStr(query string, args ...interface{}) (string, error)
- func (dbUtils *DbUtils) TableFor(t reflect.Type, checkPK bool) (*TableMap, error)
- func (dbUtils *DbUtils) Update(list ...interface{}) (int64, error)
- func (dbUtils *DbUtils) WithContext(ctx context.Context) SqlQueryRunner
- type Dialect
- type IndexMap
- type IntegerAutoIncrInserter
- type MySQLDialect
- func (d MySQLDialect) AutoIncrBindValue() string
- func (d MySQLDialect) AutoIncrInsertSuffix(col *ColumnMap) string
- func (d MySQLDialect) AutoIncrStr() string
- func (d MySQLDialect) BindVar(i int) string
- func (d MySQLDialect) CreateIndexSuffix() string
- func (d MySQLDialect) CreateTableSuffix() string
- func (d MySQLDialect) DropIndexSuffix() string
- func (d MySQLDialect) IfSchemaNotExists(command, schema string) string
- func (d MySQLDialect) IfTableExists(command, schema, table string) string
- func (d MySQLDialect) IfTableNotExists(command, schema, table string) string
- func (d MySQLDialect) InsertAutoIncr(queryRunner SqlQueryRunner, insertSql string, params ...interface{}) (int64, error)
- func (d MySQLDialect) QuerySuffix() string
- func (d MySQLDialect) QuoteField(f string) string
- func (d MySQLDialect) QuotedTableForQuery(schema string, table string) string
- func (d MySQLDialect) SleepClause(s time.Duration) string
- func (d MySQLDialect) ToSqlType(val reflect.Type, maxsize int, isAutoIncr bool) string
- func (d MySQLDialect) TruncateClause() string
- type NoFieldInTypeError
- type NullTime
- type OracleDialect
- func (d OracleDialect) AutoIncrBindValue() string
- func (d OracleDialect) AutoIncrInsertSuffix(col *ColumnMap) string
- func (d OracleDialect) AutoIncrStr() string
- func (d OracleDialect) BindVar(i int) string
- func (d OracleDialect) CreateIndexSuffix() string
- func (d OracleDialect) CreateTableSuffix() string
- func (d OracleDialect) DropIndexSuffix() string
- func (d OracleDialect) IfSchemaNotExists(command, schema string) string
- func (d OracleDialect) IfTableExists(command, schema, table string) string
- func (d OracleDialect) IfTableNotExists(command, schema, table string) string
- func (d OracleDialect) InsertQueryToTarget(exec SqlQueryRunner, insertSql, idSql string, target interface{}, ...) error
- func (d OracleDialect) QuerySuffix() string
- func (d OracleDialect) QuoteField(f string) string
- func (d OracleDialect) QuotedTableForQuery(schema string, table string) string
- func (d OracleDialect) ToSqlType(val reflect.Type, maxsize int, isAutoIncr bool) string
- func (d OracleDialect) TruncateClause() string
- type PostgresDialect
- func (d PostgresDialect) AutoIncrBindValue() string
- func (d PostgresDialect) AutoIncrInsertSuffix(col *ColumnMap) string
- func (d PostgresDialect) AutoIncrStr() string
- func (d PostgresDialect) BindVar(i int) string
- func (d PostgresDialect) CreateIndexSuffix() string
- func (d PostgresDialect) CreateTableSuffix() string
- func (d PostgresDialect) DropIndexSuffix() string
- func (d PostgresDialect) IfSchemaNotExists(command, schema string) string
- func (d PostgresDialect) IfTableExists(command, schema, table string) string
- func (d PostgresDialect) IfTableNotExists(command, schema, table string) string
- func (d PostgresDialect) InsertAutoIncrToTarget(exec SqlQueryRunner, insertSql string, target interface{}, ...) error
- func (d PostgresDialect) QuerySuffix() string
- func (d PostgresDialect) QuoteField(f string) string
- func (d PostgresDialect) QuotedTableForQuery(schema string, table string) string
- func (d PostgresDialect) SleepClause(s time.Duration) string
- func (d PostgresDialect) ToSqlType(val reflect.Type, maxsize int, isAutoIncr bool) string
- func (d PostgresDialect) TruncateClause() string
- type RowsMap
- type SqlQueryRunner
- type SqlServerDialect
- func (d SqlServerDialect) AutoIncrBindValue() string
- func (d SqlServerDialect) AutoIncrInsertSuffix(col *ColumnMap) string
- func (d SqlServerDialect) AutoIncrStr() string
- func (d SqlServerDialect) BindVar(i int) string
- func (d SqlServerDialect) CreateIndexSuffix() string
- func (d SqlServerDialect) CreateTableSuffix() string
- func (d SqlServerDialect) DropIndexSuffix() string
- func (d SqlServerDialect) IfSchemaNotExists(command, schema string) string
- func (d SqlServerDialect) IfTableExists(command, schema, table string) string
- func (d SqlServerDialect) IfTableNotExists(command, schema, table string) string
- func (d SqlServerDialect) InsertAutoIncr(exec SqlQueryRunner, insertSql string, params ...interface{}) (int64, error)
- func (d SqlServerDialect) QuerySuffix() string
- func (d SqlServerDialect) QuoteField(f string) string
- func (d SqlServerDialect) QuotedTableForQuery(schema string, table string) string
- func (d SqlServerDialect) ToSqlType(val reflect.Type, maxsize int, isAutoIncr bool) string
- func (d SqlServerDialect) TruncateClause() string
- type SqlTyper
- type SqliteDialect
- func (d SqliteDialect) AutoIncrBindValue() string
- func (d SqliteDialect) AutoIncrInsertSuffix(col *ColumnMap) string
- func (d SqliteDialect) AutoIncrStr() string
- func (d SqliteDialect) BindVar(i int) string
- func (d SqliteDialect) CreateIndexSuffix() string
- func (d SqliteDialect) CreateTableSuffix() string
- func (d SqliteDialect) DropIndexSuffix() string
- func (d SqliteDialect) IfSchemaNotExists(command, schema string) string
- func (d SqliteDialect) IfTableExists(command, schema, table string) string
- func (d SqliteDialect) IfTableNotExists(command, schema, table string) string
- func (d SqliteDialect) InsertAutoIncr(exec SqlQueryRunner, insertSql string, params ...interface{}) (int64, error)
- func (d SqliteDialect) QuerySuffix() string
- func (d SqliteDialect) QuoteField(f string) string
- func (d SqliteDialect) QuotedTableForQuery(schema string, table string) string
- func (d SqliteDialect) ToSqlType(val reflect.Type, maxsize int, isAutoIncr bool) string
- func (d SqliteDialect) TruncateClause() string
- type TableMap
- func (t *TableMap) AddIndex(name string, idxtype string, columns []string) *IndexMap
- func (t *TableMap) ColMap(field string) *ColumnMap
- func (t *TableMap) CreateTableSql(ifNotExists bool) string
- func (t *TableMap) IdxMap(field string) *IndexMap
- func (t *TableMap) SetKeys(isAutoIncr bool, fieldNames ...string) *TableMap
- func (t *TableMap) SetUniqueTogether(fieldNames ...string) *TableMap
- type TargetQueryInserter
- type TargetedAutoIncrInserter
- type Transaction
- func (t *Transaction) Commit() error
- func (t *Transaction) Delete(list ...interface{}) (int64, error)
- func (t *Transaction) Exec(query string, args ...interface{}) (sql.Result, error)
- func (t *Transaction) Get(i interface{}, keys ...interface{}) (interface{}, error)
- func (t *Transaction) Insert(list ...interface{}) error
- func (t *Transaction) Query(q string, args ...interface{}) (*sql.Rows, error)
- func (t *Transaction) QueryRow(query string, args ...interface{}) *sql.Row
- func (t *Transaction) Rollback() error
- func (t *Transaction) RollbackToSavepoint(savepoint string) error
- func (t *Transaction) Savepoint(name string) error
- func (t *Transaction) Select(i interface{}, query string, args ...interface{}) ([]interface{}, error)
- func (t *Transaction) SelectFloat(query string, args ...interface{}) (float64, error)
- func (t *Transaction) SelectInt(query string, args ...interface{}) (int64, error)
- func (t *Transaction) SelectNullFloat(query string, args ...interface{}) (sql.NullFloat64, error)
- func (t *Transaction) SelectNullInt(query string, args ...interface{}) (sql.NullInt64, error)
- func (t *Transaction) SelectNullStr(query string, args ...interface{}) (sql.NullString, error)
- func (t *Transaction) SelectOne(holder interface{}, query string, args ...interface{}) error
- func (t *Transaction) SelectStr(query string, args ...interface{}) (string, error)
- func (t *Transaction) Update(list ...interface{}) (int64, error)
- func (t *Transaction) WithContext(ctx context.Context) SqlQueryRunner
- type TypeConverter
Constants ¶
const ( MYSQL = "mysql" ORACLE = "oracle" POSTGRESQL = "postgresql" DB2 = "db2" SQLITE = "sqlite3" )
Variables ¶
var (
DefaultCacheSize = 200
)
var (
ErrNullPointer = errors.New("t should be a pointer")
)
Functions ¶
func MapToSlice ¶
func NonFatalError ¶
returns true if the error is non-fatal (ie, we shouldn't immediately return)
func SelectFloat ¶
func SelectFloat(queryRunner SqlQueryRunner, query string, args ...interface{}) (float64, error)
func SelectInt ¶
func SelectInt(queryRunner SqlQueryRunner, query string, args ...interface{}) (int64, error)
func SelectNullFloat ¶
func SelectNullFloat(queryRunner SqlQueryRunner, query string, args ...interface{}) (sql.NullFloat64, error)
func SelectNullInt ¶
func SelectNullInt(queryRunner SqlQueryRunner, query string, args ...interface{}) (sql.NullInt64, error)
func SelectNullStr ¶
func SelectNullStr(queryRunner SqlQueryRunner, query string, args ...interface{}) (sql.NullString, error)
func SelectOne ¶
func SelectOne(dbUtils *DbUtils, queryRunner SqlQueryRunner, holder interface{}, query string, args ...interface{}) error
func SelectStr ¶
func SelectStr(queryRunner SqlQueryRunner, query string, args ...interface{}) (string, error)
func StructToSlice ¶
Types ¶
type ColumnMap ¶
type ColumnMap struct {
// Column name in db table
ColumnName string
// If true, this column is skipped in generated SQL statements
Transient bool
// If true, " unique" is added to create table statements.
// Not used elsewhere
Unique bool
// Query used for getting generated id after insert
GeneratedIdQuery string
// Passed to Dialect.ToSqlType() to assist in informing the
// correct column type to map to in CreateTables()
MaxSize int
DefaultValue string
// contains filtered or unexported fields
}
func (*ColumnMap) SetMaxSize ¶
SetMaxSize specifies the max length of values of this column. This is passed to the dialect.ToSqlType() function, which can use the value to alter the generated type for "create table" statements
func (*ColumnMap) SetNotNull ¶
SetNotNull adds "not null" to the create table statements for this column, if nn is true.
func (*ColumnMap) SetTransient ¶
SetTransient allows you to mark the column as transient. If true this column will be skipped when SQL statements are generated
type CustomScanner ¶
type CustomScanner struct {
// After a row is scanned, Holder will contain the value from the database column.
// Initialize the CustomScanner with the concrete Go type you wish the database
// driver to scan the raw column into.
Holder interface{}
// Target typically holds a pointer to the target struct field to bind the Holder
// value to.
Target interface{}
// Binder is a custom function that converts the holder value to the target type
// and sets target accordingly. This function should return error if a problem
// occurs converting the holder to the target.
Binder func(holder interface{}, target interface{}) error
}
func (CustomScanner) Bind ¶
func (me CustomScanner) Bind() error
type DbUtils ¶
type DbUtils struct {
Db *sql.DB
Dialect Dialect
TypeConverter TypeConverter
// contains filtered or unexported fields
}
func (*DbUtils) AddTableWithName ¶
func (*DbUtils) AddTableWithNameAndSchema ¶
func (*DbUtils) Begin ¶
func (dbUtils *DbUtils) Begin() (*Transaction, error)
func (*DbUtils) CreateTables ¶
func (*DbUtils) CreateTablesIfNotExists ¶
func (*DbUtils) DropTables ¶
func (*DbUtils) DropTablesIfExists ¶
DropTablesIfExists is the same as DropTables, but uses the "if exists" clause to avoid errors for tables that do not exist.
func (*DbUtils) SelectFloat ¶
SelectFloat is a convenience wrapper around the gorp.SelectFloat function
func (*DbUtils) SelectNullFloat ¶
func (dbUtils *DbUtils) SelectNullFloat(query string, args ...interface{}) (sql.NullFloat64, error)
SelectNullFloat is a convenience wrapper around the gorp.SelectNullFloat function
func (*DbUtils) SelectNullInt ¶
SelectNullInt is a convenience wrapper around the gorp.SelectNullInt function
func (*DbUtils) SelectNullStr ¶
func (dbUtils *DbUtils) SelectNullStr(query string, args ...interface{}) (sql.NullString, error)
SelectNullStr is a convenience wrapper around the gorp.SelectNullStr function
func (*DbUtils) WithContext ¶
func (dbUtils *DbUtils) WithContext(ctx context.Context) SqlQueryRunner
type Dialect ¶
type Dialect interface {
// adds a suffix to any query, usually ";"
QuerySuffix() string
// ToSqlType returns the SQL column type to use when creating a
// table of the given Go Type. maxsize can be used to switch based on
// size. For example, in MySQL []byte could map to BLOB, MEDIUMBLOB,
// or LONGBLOB depending on the maxsize
ToSqlType(val reflect.Type, maxsize int, isAutoIncr bool) string
// string to append to primary key column definitions
AutoIncrStr() string
// string to bind autoincrement columns to. Empty string will
// remove reference to those columns in the INSERT statement.
AutoIncrBindValue() string
AutoIncrInsertSuffix(col *ColumnMap) string
// string to append to "create table" statement for vendor specific
// table attributes
CreateTableSuffix() string
// string to append to "create index" statement
CreateIndexSuffix() string
// string to append to "drop index" statement
DropIndexSuffix() string
// string to truncate tables
TruncateClause() string
// bind variable string to use when forming SQL statements
// in many dbs it is "?", but Postgres appears to use $1
//
// i is a zero based index of the bind variable in this statement
//
BindVar(i int) string
// Handles quoting of a field name to ensure that it doesn't raise any
// SQL parsing exceptions by using a reserved word as a field name.
QuoteField(field string) string
// Handles building up of a schema.database string that is compatible with
// the given dialect
//
// schema - The schema that <table> lives in
// table - The table name
QuotedTableForQuery(schema string, table string) string
// Existence clause for table creation / deletion
IfSchemaNotExists(command, schema string) string
IfTableExists(command, schema, table string) string
IfTableNotExists(command, schema, table string) string
}
type IndexMap ¶
type IndexMap struct {
// Index name in db table
IndexName string
// If true, " unique" is added to create index statements.
// Not used elsewhere
Unique bool
// Index type supported by Dialect
// Postgres: B-tree, Hash, GiST and GIN.
// Mysql: Btree, Hash.
// Sqlite: nil.
IndexType string
// contains filtered or unexported fields
}
func (*IndexMap) SetIndexType ¶
SetIndexType specifies the index type supported by chousen SQL Dialect
type IntegerAutoIncrInserter ¶
type IntegerAutoIncrInserter interface {
InsertAutoIncr(exec SqlQueryRunner, insertSql string, params ...interface{}) (int64, error)
}
type MySQLDialect ¶
type MySQLDialect struct {
// Engine is the storage engine to use "InnoDB" vs "MyISAM" for example
Engine string
// Encoding is the character encoding to use for created tables
Encoding string
}
func (MySQLDialect) AutoIncrBindValue ¶
func (d MySQLDialect) AutoIncrBindValue() string
func (MySQLDialect) AutoIncrInsertSuffix ¶
func (d MySQLDialect) AutoIncrInsertSuffix(col *ColumnMap) string
func (MySQLDialect) CreateIndexSuffix ¶
func (d MySQLDialect) CreateIndexSuffix() string
func (MySQLDialect) CreateTableSuffix ¶
func (d MySQLDialect) CreateTableSuffix() string
Returns engine=%s charset=%s based on values stored on struct
func (MySQLDialect) DropIndexSuffix ¶
func (d MySQLDialect) DropIndexSuffix() string
func (MySQLDialect) IfSchemaNotExists ¶
func (d MySQLDialect) IfSchemaNotExists(command, schema string) string
func (MySQLDialect) IfTableExists ¶
func (d MySQLDialect) IfTableExists(command, schema, table string) string
func (MySQLDialect) IfTableNotExists ¶
func (d MySQLDialect) IfTableNotExists(command, schema, table string) string
func (MySQLDialect) InsertAutoIncr ¶
func (d MySQLDialect) InsertAutoIncr(queryRunner SqlQueryRunner, insertSql string, params ...interface{}) (int64, error)
func (MySQLDialect) QuerySuffix ¶
func (d MySQLDialect) QuerySuffix() string
func (MySQLDialect) QuoteField ¶
func (d MySQLDialect) QuoteField(f string) string
func (MySQLDialect) QuotedTableForQuery ¶
func (d MySQLDialect) QuotedTableForQuery(schema string, table string) string
func (MySQLDialect) SleepClause ¶
func (d MySQLDialect) SleepClause(s time.Duration) string
func (MySQLDialect) TruncateClause ¶
func (d MySQLDialect) TruncateClause() string
type NoFieldInTypeError ¶
func (*NoFieldInTypeError) Error ¶
func (err *NoFieldInTypeError) Error() string
type OracleDialect ¶
type OracleDialect struct{}
func (OracleDialect) AutoIncrBindValue ¶
func (d OracleDialect) AutoIncrBindValue() string
func (OracleDialect) AutoIncrInsertSuffix ¶
func (d OracleDialect) AutoIncrInsertSuffix(col *ColumnMap) string
func (OracleDialect) CreateIndexSuffix ¶
func (d OracleDialect) CreateIndexSuffix() string
func (OracleDialect) CreateTableSuffix ¶
func (d OracleDialect) CreateTableSuffix() string
Returns suffix
func (OracleDialect) DropIndexSuffix ¶
func (d OracleDialect) DropIndexSuffix() string
func (OracleDialect) IfSchemaNotExists ¶
func (d OracleDialect) IfSchemaNotExists(command, schema string) string
func (OracleDialect) IfTableExists ¶
func (d OracleDialect) IfTableExists(command, schema, table string) string
func (OracleDialect) IfTableNotExists ¶
func (d OracleDialect) IfTableNotExists(command, schema, table string) string
func (OracleDialect) InsertQueryToTarget ¶
func (d OracleDialect) InsertQueryToTarget(exec SqlQueryRunner, insertSql, idSql string, target interface{}, params ...interface{}) error
After executing the insert uses the ColMap IdQuery to get the generated id
func (OracleDialect) QuerySuffix ¶
func (d OracleDialect) QuerySuffix() string
func (OracleDialect) QuoteField ¶
func (d OracleDialect) QuoteField(f string) string
func (OracleDialect) QuotedTableForQuery ¶
func (d OracleDialect) QuotedTableForQuery(schema string, table string) string
func (OracleDialect) TruncateClause ¶
func (d OracleDialect) TruncateClause() string
type PostgresDialect ¶
type PostgresDialect struct {
LowercaseFields bool
// contains filtered or unexported fields
}
func (PostgresDialect) AutoIncrBindValue ¶
func (d PostgresDialect) AutoIncrBindValue() string
func (PostgresDialect) AutoIncrInsertSuffix ¶
func (d PostgresDialect) AutoIncrInsertSuffix(col *ColumnMap) string
func (PostgresDialect) AutoIncrStr ¶
func (d PostgresDialect) AutoIncrStr() string
Returns empty string
func (PostgresDialect) CreateIndexSuffix ¶
func (d PostgresDialect) CreateIndexSuffix() string
func (PostgresDialect) CreateTableSuffix ¶
func (d PostgresDialect) CreateTableSuffix() string
Returns suffix
func (PostgresDialect) DropIndexSuffix ¶
func (d PostgresDialect) DropIndexSuffix() string
func (PostgresDialect) IfSchemaNotExists ¶
func (d PostgresDialect) IfSchemaNotExists(command, schema string) string
func (PostgresDialect) IfTableExists ¶
func (d PostgresDialect) IfTableExists(command, schema, table string) string
func (PostgresDialect) IfTableNotExists ¶
func (d PostgresDialect) IfTableNotExists(command, schema, table string) string
func (PostgresDialect) InsertAutoIncrToTarget ¶
func (d PostgresDialect) InsertAutoIncrToTarget(exec SqlQueryRunner, insertSql string, target interface{}, params ...interface{}) error
func (PostgresDialect) QuerySuffix ¶
func (d PostgresDialect) QuerySuffix() string
func (PostgresDialect) QuoteField ¶
func (d PostgresDialect) QuoteField(f string) string
func (PostgresDialect) QuotedTableForQuery ¶
func (d PostgresDialect) QuotedTableForQuery(schema string, table string) string
func (PostgresDialect) SleepClause ¶
func (d PostgresDialect) SleepClause(s time.Duration) string
func (PostgresDialect) TruncateClause ¶
func (d PostgresDialect) TruncateClause() string
type SqlQueryRunner ¶
type SqlQueryRunner interface {
WithContext(ctx context.Context) SqlQueryRunner
Get(i interface{}, keys ...interface{}) (interface{}, error)
Insert(list ...interface{}) error
Update(list ...interface{}) (int64, error)
Delete(list ...interface{}) (int64, error)
Exec(query string, args ...interface{}) (sql.Result, error)
Select(i interface{}, query string, args ...interface{}) ([]interface{}, error)
SelectInt(query string, args ...interface{}) (int64, error)
SelectNullInt(query string, args ...interface{}) (sql.NullInt64, error)
SelectFloat(query string, args ...interface{}) (float64, error)
SelectNullFloat(query string, args ...interface{}) (sql.NullFloat64, error)
SelectStr(query string, args ...interface{}) (string, error)
SelectNullStr(query string, args ...interface{}) (sql.NullString, error)
SelectOne(holder interface{}, query string, args ...interface{}) error
Query(query string, args ...interface{}) (*sql.Rows, error)
QueryRow(query string, args ...interface{}) *sql.Row
}
type SqlServerDialect ¶
type SqlServerDialect struct {
// If set to "2005" legacy datatypes will be used
Version string
}
func (SqlServerDialect) AutoIncrBindValue ¶
func (d SqlServerDialect) AutoIncrBindValue() string
Empty string removes autoincrement columns from the INSERT statements.
func (SqlServerDialect) AutoIncrInsertSuffix ¶
func (d SqlServerDialect) AutoIncrInsertSuffix(col *ColumnMap) string
func (SqlServerDialect) AutoIncrStr ¶
func (d SqlServerDialect) AutoIncrStr() string
Returns auto_increment
func (SqlServerDialect) CreateIndexSuffix ¶
func (d SqlServerDialect) CreateIndexSuffix() string
func (SqlServerDialect) CreateTableSuffix ¶
func (d SqlServerDialect) CreateTableSuffix() string
func (SqlServerDialect) DropIndexSuffix ¶
func (d SqlServerDialect) DropIndexSuffix() string
func (SqlServerDialect) IfSchemaNotExists ¶
func (d SqlServerDialect) IfSchemaNotExists(command, schema string) string
func (SqlServerDialect) IfTableExists ¶
func (d SqlServerDialect) IfTableExists(command, schema, table string) string
func (SqlServerDialect) IfTableNotExists ¶
func (d SqlServerDialect) IfTableNotExists(command, schema, table string) string
func (SqlServerDialect) InsertAutoIncr ¶
func (d SqlServerDialect) InsertAutoIncr(exec SqlQueryRunner, insertSql string, params ...interface{}) (int64, error)
func (SqlServerDialect) QuerySuffix ¶
func (d SqlServerDialect) QuerySuffix() string
func (SqlServerDialect) QuoteField ¶
func (d SqlServerDialect) QuoteField(f string) string
func (SqlServerDialect) QuotedTableForQuery ¶
func (d SqlServerDialect) QuotedTableForQuery(schema string, table string) string
func (SqlServerDialect) TruncateClause ¶
func (d SqlServerDialect) TruncateClause() string
type SqliteDialect ¶
type SqliteDialect struct {
// contains filtered or unexported fields
}
func (SqliteDialect) AutoIncrBindValue ¶
func (d SqliteDialect) AutoIncrBindValue() string
func (SqliteDialect) AutoIncrInsertSuffix ¶
func (d SqliteDialect) AutoIncrInsertSuffix(col *ColumnMap) string
func (SqliteDialect) AutoIncrStr ¶
func (d SqliteDialect) AutoIncrStr() string
Returns autoincrement
func (SqliteDialect) CreateIndexSuffix ¶
func (d SqliteDialect) CreateIndexSuffix() string
func (SqliteDialect) CreateTableSuffix ¶
func (d SqliteDialect) CreateTableSuffix() string
Returns suffix
func (SqliteDialect) DropIndexSuffix ¶
func (d SqliteDialect) DropIndexSuffix() string
func (SqliteDialect) IfSchemaNotExists ¶
func (d SqliteDialect) IfSchemaNotExists(command, schema string) string
func (SqliteDialect) IfTableExists ¶
func (d SqliteDialect) IfTableExists(command, schema, table string) string
func (SqliteDialect) IfTableNotExists ¶
func (d SqliteDialect) IfTableNotExists(command, schema, table string) string
func (SqliteDialect) InsertAutoIncr ¶
func (d SqliteDialect) InsertAutoIncr(exec SqlQueryRunner, insertSql string, params ...interface{}) (int64, error)
func (SqliteDialect) QuerySuffix ¶
func (d SqliteDialect) QuerySuffix() string
func (SqliteDialect) QuoteField ¶
func (d SqliteDialect) QuoteField(f string) string
func (SqliteDialect) QuotedTableForQuery ¶
func (d SqliteDialect) QuotedTableForQuery(schema string, table string) string
sqlite does not have schemas like PostgreSQL does, so just escape it like normal
func (SqliteDialect) TruncateClause ¶
func (d SqliteDialect) TruncateClause() string
With sqlite, there technically isn't a TRUNCATE statement, but a DELETE FROM uses a truncate optimization: http://www.sqlite.org/lang_delete.html
type TableMap ¶
type TableMap struct {
TableName string
SchemaName string
Columns []*ColumnMap
// contains filtered or unexported fields
}
func (*TableMap) CreateTableSql ¶
func (*TableMap) SetUniqueTogether ¶
type TargetQueryInserter ¶
type TargetQueryInserter interface {
// TargetQueryInserter runs an insert operation and assigns the
// automatically generated primary key retrived by the query
// extracted from the GeneratedIdQuery field of the id column.
InsertQueryToTarget(exec SqlQueryRunner, insertSql, idSql string, target interface{}, params ...interface{}) error
}
TargetQueryInserter is implemented by dialects that can perform assignment of integer primary key type by executing a query like "select sequence.currval from dual".
type TargetedAutoIncrInserter ¶
type TargetedAutoIncrInserter interface {
// InsertAutoIncrToTarget runs an insert operation and assigns the
// automatically generated primary key directly to the passed in
// target. The target should be a pointer to the primary key
// field of the value being inserted.
InsertAutoIncrToTarget(exec SqlQueryRunner, insertSql string, target interface{}, params ...interface{}) error
}
TargetedAutoIncrInserter is implemented by dialects that can perform automatic assignment of any primary key type (i.e. strings for uuids, integers for serials, etc).
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
func (*Transaction) Commit ¶
func (t *Transaction) Commit() error
func (*Transaction) Delete ¶
func (t *Transaction) Delete(list ...interface{}) (int64, error)
Delete has the same behavior as DbMap.Delete(), but runs in a transaction.
func (*Transaction) Exec ¶
func (t *Transaction) Exec(query string, args ...interface{}) (sql.Result, error)
Exec has the same behavior as DbMap.Exec(), but runs in a transaction.
func (*Transaction) Get ¶
func (t *Transaction) Get(i interface{}, keys ...interface{}) (interface{}, error)
Get has the same behavior as DbMap.Get(), but runs in a transaction.
func (*Transaction) Insert ¶
func (t *Transaction) Insert(list ...interface{}) error
Insert has the same behavior as DbMap.Insert(), but runs in a transaction.
func (*Transaction) Query ¶
func (t *Transaction) Query(q string, args ...interface{}) (*sql.Rows, error)
func (*Transaction) QueryRow ¶
func (t *Transaction) QueryRow(query string, args ...interface{}) *sql.Row
func (*Transaction) Rollback ¶
func (t *Transaction) Rollback() error
Rollback rolls back the underlying database transaction.
func (*Transaction) RollbackToSavepoint ¶
func (t *Transaction) RollbackToSavepoint(savepoint string) error
RollbackToSavepoint rolls back to the savepoint with the given name. The name is interpolated directly into the SQL SAVEPOINT statement, so you must sanitize it if it is derived from user input.
func (*Transaction) Savepoint ¶
func (t *Transaction) Savepoint(name string) error
func (*Transaction) Select ¶
func (t *Transaction) Select(i interface{}, query string, args ...interface{}) ([]interface{}, error)
Select has the same behavior as DbMap.Select(), but runs in a transaction.
func (*Transaction) SelectFloat ¶
func (t *Transaction) SelectFloat(query string, args ...interface{}) (float64, error)
SelectFloat is a convenience wrapper around the gorp.SelectFloat function.
func (*Transaction) SelectInt ¶
func (t *Transaction) SelectInt(query string, args ...interface{}) (int64, error)
SelectInt is a convenience wrapper around the gorp.SelectInt function.
func (*Transaction) SelectNullFloat ¶
func (t *Transaction) SelectNullFloat(query string, args ...interface{}) (sql.NullFloat64, error)
SelectNullFloat is a convenience wrapper around the gorp.SelectNullFloat function.
func (*Transaction) SelectNullInt ¶
func (t *Transaction) SelectNullInt(query string, args ...interface{}) (sql.NullInt64, error)
SelectNullInt is a convenience wrapper around the gorp.SelectNullInt function.
func (*Transaction) SelectNullStr ¶
func (t *Transaction) SelectNullStr(query string, args ...interface{}) (sql.NullString, error)
SelectNullStr is a convenience wrapper around the gorp.SelectNullStr function.
func (*Transaction) SelectOne ¶
func (t *Transaction) SelectOne(holder interface{}, query string, args ...interface{}) error
SelectOne is a convenience wrapper around the gorp.SelectOne function.
func (*Transaction) SelectStr ¶
func (t *Transaction) SelectStr(query string, args ...interface{}) (string, error)
SelectStr is a convenience wrapper around the gorp.SelectStr function.
func (*Transaction) Update ¶
func (t *Transaction) Update(list ...interface{}) (int64, error)
Update had the same behavior as DbMap.Update(), but runs in a transaction.
func (*Transaction) WithContext ¶
func (t *Transaction) WithContext(ctx context.Context) SqlQueryRunner
type TypeConverter ¶
type TypeConverter interface {
// ToDb converts val to another type. Called before INSERT/UPDATE operations
ToDb(val interface{}) (interface{}, error)
// FromDb returns a CustomScanner appropriate for this type. This will be used
// to hold values returned from SELECT queries.
//
// In particular the CustomScanner returned should implement a Binder
// function appropriate for the Go type you wish to convert the db value to
//
// If bool==false, then no custom scanner will be used for this field.
FromDb(target interface{}) (CustomScanner, bool)
}