go-admin: github.com/GoAdminGroup/go-admin/modules/db Index | Files | Directories

package db

import "github.com/GoAdminGroup/go-admin/modules/db"

Index

Package Files

base.go connection.go converter.go mssql.go mysql.go performer.go postgresql.go sqlite.go statement.go types.go

Constants

const (
    // DriverMysql is a const value of mysql driver.
    DriverMysql = "mysql"
    // DriverSqlite is a const value of sqlite driver.
    DriverSqlite = "sqlite"
    // DriverPostgresql is a const value of postgresql driver.
    DriverPostgresql = "postgresql"
    // DriverMssql is a const value of mssql driver.
    DriverMssql = "mssql"
)

Variables

var (
    // StringTypeList is a DatabaseType list of string.
    StringTypeList = []DatabaseType{Date, Time, Year, Datetime, Timestamptz, Timestamp,
        Varchar, Char, Mediumtext, Longtext, Tinytext,
        Text, JSON, Blob, Tinyblob, Mediumblob, Longblob,
        Interval, Point,
        Line, Lseg, Box, Path, Polygon, Circle, Cidr, Inet, Macaddr, Character, Varyingcharacter,
        Nchar, Nativecharacter, Nvarchar, Clob, Binary, Varbinary, Enum, Set, Geometry, Multilinestring,
        Multipolygon, Linestring, Multipoint, Geometrycollection, Name, UUID, Timestamptz,
        Name, UUID, Inet}

    // BoolTypeList is a DatabaseType list of bool.
    BoolTypeList = []DatabaseType{Bool, Boolean}

    // IntTypeList is a DatabaseType list of integer.
    IntTypeList = []DatabaseType{Int4,
        Int,
        Tinyint,
        Mediumint,
        Smallint,
        Numeric, Smallserial, Serial, Bigserial, Money,
        Integer,
        Bigint}

    // FloatTypeList is a DatabaseType list of float.
    FloatTypeList = []DatabaseType{Float, Double, Real, Doubleprecision}

    // UintTypeList is a DatabaseType list of uint.
    UintTypeList = []DatabaseType{Decimal, Bit}
)
var SQLPool = sync.Pool{
    New: func() interface{} {
        return &SQL{
            SQLComponent: dialect.SQLComponent{
                Fields:     make([]string, 0),
                TableName:  "",
                Args:       make([]interface{}, 0),
                Wheres:     make([]dialect.Where, 0),
                Leftjoins:  make([]dialect.Join, 0),
                UpdateRaws: make([]dialect.RawUpdate, 0),
                WhereRaws:  "",
                Order:      "",
                Group:      "",
                Limit:      "",
            },
            diver:   nil,
            dialect: nil,
        }
    },
}

SQLPool is a object pool of SQL.

func CommonBeginTxWithLevel Uses

func CommonBeginTxWithLevel(db *sql.DB, level sql.IsolationLevel) *sql.Tx

CommonBeginTxWithLevel starts a transaction with given transaction isolation level and db connection.

func CommonExec Uses

func CommonExec(db *sql.DB, query string, args ...interface{}) (sql.Result, error)

CommonExec is a common method of exec.

func CommonExecWithTx Uses

func CommonExecWithTx(tx *sql.Tx, query string, args ...interface{}) (sql.Result, error)

CommonExecWithTx is a common method of exec.

func CommonQuery Uses

func CommonQuery(db *sql.DB, query string, args ...interface{}) ([]map[string]interface{}, error)

CommonQuery is a common method of query.

func CommonQueryWithTx Uses

func CommonQueryWithTx(tx *sql.Tx, query string, args ...interface{}) ([]map[string]interface{}, error)

CommonQueryWithTx is a common method of query.

func Contains Uses

func Contains(v DatabaseType, a []DatabaseType) bool

Contains check the given DatabaseType is in the list or not.

func RecycleSQL Uses

func RecycleSQL(sql *SQL)

RecycleSQL clear the SQL and put into the pool.

func SetColVarType Uses

func SetColVarType(colVar *[]interface{}, i int, typeName string)

SetColVarType set the column type.

func SetResultValue Uses

func SetResultValue(result *map[string]interface{}, index string, colVar interface{}, typeName string)

SetResultValue set the result value.

type Base Uses

type Base struct {
    DbList map[string]*sql.DB
    Once   sync.Once
}

Base is a common Connection.

func (*Base) Close Uses

func (db *Base) Close() []error

Close implements the method Connection.Close.

func (*Base) GetDB Uses

func (db *Base) GetDB(key string) *sql.DB

GetDB implements the method Connection.GetDB.

type Connection Uses

type Connection interface {
    // Query is the query method of sql.
    Query(query string, args ...interface{}) ([]map[string]interface{}, error)

    // Exec is the exec method of sql.
    Exec(query string, args ...interface{}) (sql.Result, error)

    // QueryWithConnection is the query method with given connection of sql.
    QueryWithConnection(conn, query string, args ...interface{}) ([]map[string]interface{}, error)

    // ExecWithConnection is the exec method with given connection of sql.
    ExecWithConnection(conn, query string, args ...interface{}) (sql.Result, error)

    QueryWithTx(tx *sql.Tx, query string, args ...interface{}) ([]map[string]interface{}, error)

    ExecWithTx(tx *sql.Tx, query string, args ...interface{}) (sql.Result, error)

    BeginTxWithReadUncommitted() *sql.Tx
    BeginTxWithReadCommitted() *sql.Tx
    BeginTxWithRepeatableRead() *sql.Tx
    BeginTx() *sql.Tx
    BeginTxWithLevel(level sql.IsolationLevel) *sql.Tx

    BeginTxWithReadUncommittedAndConnection(conn string) *sql.Tx
    BeginTxWithReadCommittedAndConnection(conn string) *sql.Tx
    BeginTxWithRepeatableReadAndConnection(conn string) *sql.Tx
    BeginTxAndConnection(conn string) *sql.Tx
    BeginTxWithLevelAndConnection(conn string, level sql.IsolationLevel) *sql.Tx

    // InitDB initialize the database connections.
    InitDB(cfg map[string]config.Database) Connection

    // GetName get the connection name.
    Name() string

    Close() []error

    // GetDelimiter get the default delimiter.
    GetDelimiter() string

    GetDB(key string) *sql.DB
}

Connection is a connection handler of database.

func GetConnection Uses

func GetConnection(srvs service.List) Connection

func GetConnectionByDriver Uses

func GetConnectionByDriver(driver string) Connection

GetConnectionByDriver return the Connection by given driver name.

func GetConnectionFromService Uses

func GetConnectionFromService(srv interface{}) Connection

type DatabaseType Uses

type DatabaseType string

DatabaseType is the database field type.

const (
    Int       DatabaseType = "INT"
    Tinyint   DatabaseType = "TINYINT"
    Mediumint DatabaseType = "MEDIUMINT"
    Smallint  DatabaseType = "SMALLINT"
    Bigint    DatabaseType = "BIGINT"
    Bit       DatabaseType = "BIT"
    Int4      DatabaseType = "INT4"

    Integer     DatabaseType = "INTEGER"
    Numeric     DatabaseType = "NUMERIC"
    Smallserial DatabaseType = "SMALLSERIAL"
    Serial      DatabaseType = "SERIAL"
    Bigserial   DatabaseType = "BIGSERIAL"
    Money       DatabaseType = "MONEY"

    Real    DatabaseType = "REAL"
    Float   DatabaseType = "FLOAT"
    Double  DatabaseType = "DOUBLE"
    Decimal DatabaseType = "DECIMAL"

    Doubleprecision DatabaseType = "DOUBLEPRECISION"

    Date      DatabaseType = "DATE"
    Time      DatabaseType = "TIME"
    Year      DatabaseType = "YEAR"
    Datetime  DatabaseType = "DATETIME"
    Timestamp DatabaseType = "TIMESTAMP"

    Text       DatabaseType = "TEXT"
    Longtext   DatabaseType = "LONGTEXT"
    Mediumtext DatabaseType = "MEDIUMTEXT"
    Tinytext   DatabaseType = "TINYTEXT"

    Varchar DatabaseType = "VARCHAR"
    Char    DatabaseType = "CHAR"
    JSON    DatabaseType = "JSON"

    Blob       DatabaseType = "BLOB"
    Tinyblob   DatabaseType = "TINYBLOB"
    Mediumblob DatabaseType = "MEDIUMBLOB"
    Longblob   DatabaseType = "LONGBLOB"

    Interval DatabaseType = "INTERVAL"
    Boolean  DatabaseType = "BOOLEAN"
    Bool     DatabaseType = "Bool"

    Point   DatabaseType = "POINT"
    Line    DatabaseType = "LINE"
    Lseg    DatabaseType = "LSEG"
    Box     DatabaseType = "BOX"
    Path    DatabaseType = "PATH"
    Polygon DatabaseType = "POLYGON"
    Circle  DatabaseType = "CIRCLE"

    Cidr    DatabaseType = "CIDR"
    Inet    DatabaseType = "INET"
    Macaddr DatabaseType = "MACADDR"

    Character        DatabaseType = "CHARACTER"
    Varyingcharacter DatabaseType = "VARYINGCHARACTER"
    Nchar            DatabaseType = "NCHAR"
    Nativecharacter  DatabaseType = "NATIVECHARACTER"
    Nvarchar         DatabaseType = "NVARCHAR"
    Clob             DatabaseType = "CLOB"

    Binary    DatabaseType = "BINARY"
    Varbinary DatabaseType = "VARBINARY"
    Enum      DatabaseType = "ENUM"
    Set       DatabaseType = "SET"

    Geometry DatabaseType = "GEOMETRY"

    Multilinestring    DatabaseType = "MULTILINESTRING"
    Multipolygon       DatabaseType = "MULTIPOLYGON"
    Linestring         DatabaseType = "LINESTRING"
    Multipoint         DatabaseType = "MULTIPOINT"
    Geometrycollection DatabaseType = "GEOMETRYCOLLECTION"

    Name DatabaseType = "NAME"
    UUID DatabaseType = "UUID"

    Timestamptz DatabaseType = "TIMESTAMPTZ"
)

func DT Uses

func DT(s string) DatabaseType

DT turn the string value into DatabaseType.

func GetDTAndCheck Uses

func GetDTAndCheck(s string) DatabaseType

GetDTAndCheck check the DatabaseType.

type H Uses

type H map[string]interface{}

H is a shorthand of map.

type Mssql Uses

type Mssql struct {
    Base
}

Mssql is a Connection of mssql.

func GetMssqlDB Uses

func GetMssqlDB() *Mssql

GetMssqlDB return the global mssql connection.

func (*Mssql) BeginTx Uses

func (db *Mssql) BeginTx() *sql.Tx

BeginTx starts a transaction with level LevelDefault.

func (*Mssql) BeginTxAndConnection Uses

func (db *Mssql) BeginTxAndConnection(conn string) *sql.Tx

BeginTxAndConnection starts a transaction with level LevelDefault and connection.

func (*Mssql) BeginTxWithLevel Uses

func (db *Mssql) BeginTxWithLevel(level sql.IsolationLevel) *sql.Tx

BeginTxWithLevel starts a transaction with given transaction isolation level.

func (*Mssql) BeginTxWithLevelAndConnection Uses

func (db *Mssql) BeginTxWithLevelAndConnection(conn string, level sql.IsolationLevel) *sql.Tx

BeginTxWithLevelAndConnection starts a transaction with given transaction isolation level and connection.

func (*Mssql) BeginTxWithReadCommitted Uses

func (db *Mssql) BeginTxWithReadCommitted() *sql.Tx

BeginTxWithReadCommitted starts a transaction with level LevelReadCommitted.

func (*Mssql) BeginTxWithReadCommittedAndConnection Uses

func (db *Mssql) BeginTxWithReadCommittedAndConnection(conn string) *sql.Tx

BeginTxWithReadCommittedAndConnection starts a transaction with level LevelReadCommitted and connection.

func (*Mssql) BeginTxWithReadUncommitted Uses

func (db *Mssql) BeginTxWithReadUncommitted() *sql.Tx

BeginTxWithReadUncommitted starts a transaction with level LevelReadUncommitted.

func (*Mssql) BeginTxWithReadUncommittedAndConnection Uses

func (db *Mssql) BeginTxWithReadUncommittedAndConnection(conn string) *sql.Tx

BeginTxWithReadUncommittedAndConnection starts a transaction with level LevelReadUncommitted and connection.

func (*Mssql) BeginTxWithRepeatableRead Uses

func (db *Mssql) BeginTxWithRepeatableRead() *sql.Tx

BeginTxWithRepeatableRead starts a transaction with level LevelRepeatableRead.

func (*Mssql) BeginTxWithRepeatableReadAndConnection Uses

func (db *Mssql) BeginTxWithRepeatableReadAndConnection(conn string) *sql.Tx

BeginTxWithRepeatableReadAndConnection starts a transaction with level LevelRepeatableRead and connection.

func (*Mssql) Exec Uses

func (db *Mssql) Exec(query string, args ...interface{}) (sql.Result, error)

Exec implements the method Connection.Exec.

func (*Mssql) ExecWithConnection Uses

func (db *Mssql) ExecWithConnection(con string, query string, args ...interface{}) (sql.Result, error)

ExecWithConnection implements the method Connection.ExecWithConnection.

func (*Mssql) ExecWithTx Uses

func (db *Mssql) ExecWithTx(tx *sql.Tx, query string, args ...interface{}) (sql.Result, error)

ExecWithTx is exec method within the transaction.

func (*Mssql) GetDelimiter Uses

func (db *Mssql) GetDelimiter() string

GetDelimiter implements the method Connection.GetDelimiter.

func (*Mssql) InitDB Uses

func (db *Mssql) InitDB(cfglist map[string]config.Database) Connection

InitDB implements the method Connection.InitDB.

func (*Mssql) Name Uses

func (db *Mssql) Name() string

Name implements the method Connection.Name.

func (*Mssql) Query Uses

func (db *Mssql) Query(query string, args ...interface{}) ([]map[string]interface{}, error)

Query implements the method Connection.Query.

func (*Mssql) QueryWithConnection Uses

func (db *Mssql) QueryWithConnection(con string, query string, args ...interface{}) ([]map[string]interface{}, error)

QueryWithConnection implements the method Connection.QueryWithConnection.

func (*Mssql) QueryWithTx Uses

func (db *Mssql) QueryWithTx(tx *sql.Tx, query string, args ...interface{}) ([]map[string]interface{}, error)

QueryWithTx is query method within the transaction.

type Mysql Uses

type Mysql struct {
    Base
}

Mysql is a Connection of mysql.

func GetMysqlDB Uses

func GetMysqlDB() *Mysql

GetMysqlDB return the global mysql connection.

func (*Mysql) BeginTx Uses

func (db *Mysql) BeginTx() *sql.Tx

BeginTx starts a transaction with level LevelDefault.

func (*Mysql) BeginTxAndConnection Uses

func (db *Mysql) BeginTxAndConnection(conn string) *sql.Tx

BeginTxAndConnection starts a transaction with level LevelDefault and connection.

func (*Mysql) BeginTxWithLevel Uses

func (db *Mysql) BeginTxWithLevel(level sql.IsolationLevel) *sql.Tx

BeginTxWithLevel starts a transaction with given transaction isolation level.

func (*Mysql) BeginTxWithLevelAndConnection Uses

func (db *Mysql) BeginTxWithLevelAndConnection(conn string, level sql.IsolationLevel) *sql.Tx

BeginTxWithLevelAndConnection starts a transaction with given transaction isolation level and connection.

func (*Mysql) BeginTxWithReadCommitted Uses

func (db *Mysql) BeginTxWithReadCommitted() *sql.Tx

BeginTxWithReadCommitted starts a transaction with level LevelReadCommitted.

func (*Mysql) BeginTxWithReadCommittedAndConnection Uses

func (db *Mysql) BeginTxWithReadCommittedAndConnection(conn string) *sql.Tx

BeginTxWithReadCommittedAndConnection starts a transaction with level LevelReadCommitted and connection.

func (*Mysql) BeginTxWithReadUncommitted Uses

func (db *Mysql) BeginTxWithReadUncommitted() *sql.Tx

BeginTxWithReadUncommitted starts a transaction with level LevelReadUncommitted.

func (*Mysql) BeginTxWithReadUncommittedAndConnection Uses

func (db *Mysql) BeginTxWithReadUncommittedAndConnection(conn string) *sql.Tx

BeginTxWithReadUncommittedAndConnection starts a transaction with level LevelReadUncommitted and connection.

func (*Mysql) BeginTxWithRepeatableRead Uses

func (db *Mysql) BeginTxWithRepeatableRead() *sql.Tx

BeginTxWithRepeatableRead starts a transaction with level LevelRepeatableRead.

func (*Mysql) BeginTxWithRepeatableReadAndConnection Uses

func (db *Mysql) BeginTxWithRepeatableReadAndConnection(conn string) *sql.Tx

BeginTxWithRepeatableReadAndConnection starts a transaction with level LevelRepeatableRead and connection.

func (*Mysql) Exec Uses

func (db *Mysql) Exec(query string, args ...interface{}) (sql.Result, error)

Exec implements the method Connection.Exec.

func (*Mysql) ExecWithConnection Uses

func (db *Mysql) ExecWithConnection(con string, query string, args ...interface{}) (sql.Result, error)

ExecWithConnection implements the method Connection.ExecWithConnection.

func (*Mysql) ExecWithTx Uses

func (db *Mysql) ExecWithTx(tx *sql.Tx, query string, args ...interface{}) (sql.Result, error)

ExecWithTx is exec method within the transaction.

func (*Mysql) GetDelimiter Uses

func (db *Mysql) GetDelimiter() string

GetDelimiter implements the method Connection.GetDelimiter.

func (*Mysql) InitDB Uses

func (db *Mysql) InitDB(cfgs map[string]config.Database) Connection

InitDB implements the method Connection.InitDB.

func (*Mysql) Name Uses

func (db *Mysql) Name() string

Name implements the method Connection.Name.

func (*Mysql) Query Uses

func (db *Mysql) Query(query string, args ...interface{}) ([]map[string]interface{}, error)

Query implements the method Connection.Query.

func (*Mysql) QueryWithConnection Uses

func (db *Mysql) QueryWithConnection(con string, query string, args ...interface{}) ([]map[string]interface{}, error)

QueryWithConnection implements the method Connection.QueryWithConnection.

func (*Mysql) QueryWithTx Uses

func (db *Mysql) QueryWithTx(tx *sql.Tx, query string, args ...interface{}) ([]map[string]interface{}, error)

QueryWithTx is query method within the transaction.

type Postgresql Uses

type Postgresql struct {
    Base
}

Postgresql is a Connection of postgresql.

func GetPostgresqlDB Uses

func GetPostgresqlDB() *Postgresql

GetPostgresqlDB return the global postgresql connection.

func (*Postgresql) BeginTx Uses

func (db *Postgresql) BeginTx() *sql.Tx

BeginTx starts a transaction with level LevelDefault.

func (*Postgresql) BeginTxAndConnection Uses

func (db *Postgresql) BeginTxAndConnection(conn string) *sql.Tx

BeginTxAndConnection starts a transaction with level LevelDefault and connection.

func (*Postgresql) BeginTxWithLevel Uses

func (db *Postgresql) BeginTxWithLevel(level sql.IsolationLevel) *sql.Tx

BeginTxWithLevel starts a transaction with given transaction isolation level.

func (*Postgresql) BeginTxWithLevelAndConnection Uses

func (db *Postgresql) BeginTxWithLevelAndConnection(conn string, level sql.IsolationLevel) *sql.Tx

BeginTxWithLevelAndConnection starts a transaction with given transaction isolation level and connection.

func (*Postgresql) BeginTxWithReadCommitted Uses

func (db *Postgresql) BeginTxWithReadCommitted() *sql.Tx

BeginTxWithReadCommitted starts a transaction with level LevelReadCommitted.

func (*Postgresql) BeginTxWithReadCommittedAndConnection Uses

func (db *Postgresql) BeginTxWithReadCommittedAndConnection(conn string) *sql.Tx

BeginTxWithReadCommittedAndConnection starts a transaction with level LevelReadCommitted and connection.

func (*Postgresql) BeginTxWithReadUncommitted Uses

func (db *Postgresql) BeginTxWithReadUncommitted() *sql.Tx

BeginTxWithReadUncommitted starts a transaction with level LevelReadUncommitted.

func (*Postgresql) BeginTxWithReadUncommittedAndConnection Uses

func (db *Postgresql) BeginTxWithReadUncommittedAndConnection(conn string) *sql.Tx

BeginTxWithReadUncommittedAndConnection starts a transaction with level LevelReadUncommitted and connection.

func (*Postgresql) BeginTxWithRepeatableRead Uses

func (db *Postgresql) BeginTxWithRepeatableRead() *sql.Tx

BeginTxWithRepeatableRead starts a transaction with level LevelRepeatableRead.

func (*Postgresql) BeginTxWithRepeatableReadAndConnection Uses

func (db *Postgresql) BeginTxWithRepeatableReadAndConnection(conn string) *sql.Tx

BeginTxWithRepeatableReadAndConnection starts a transaction with level LevelRepeatableRead and connection.

func (*Postgresql) Exec Uses

func (db *Postgresql) Exec(query string, args ...interface{}) (sql.Result, error)

Exec implements the method Connection.Exec.

func (*Postgresql) ExecWithConnection Uses

func (db *Postgresql) ExecWithConnection(con string, query string, args ...interface{}) (sql.Result, error)

ExecWithConnection implements the method Connection.ExecWithConnection.

func (*Postgresql) ExecWithTx Uses

func (db *Postgresql) ExecWithTx(tx *sql.Tx, query string, args ...interface{}) (sql.Result, error)

ExecWithTx is exec method within the transaction.

func (*Postgresql) GetDelimiter Uses

func (db *Postgresql) GetDelimiter() string

GetDelimiter implements the method Connection.GetDelimiter.

func (*Postgresql) InitDB Uses

func (db *Postgresql) InitDB(cfgList map[string]config.Database) Connection

InitDB implements the method Connection.InitDB.

func (*Postgresql) Name Uses

func (db *Postgresql) Name() string

Name implements the method Connection.Name.

func (*Postgresql) Query Uses

func (db *Postgresql) Query(query string, args ...interface{}) ([]map[string]interface{}, error)

Query implements the method Connection.Query.

func (*Postgresql) QueryWithConnection Uses

func (db *Postgresql) QueryWithConnection(con string, query string, args ...interface{}) ([]map[string]interface{}, error)

QueryWithConnection implements the method Connection.QueryWithConnection.

func (*Postgresql) QueryWithTx Uses

func (db *Postgresql) QueryWithTx(tx *sql.Tx, query string, args ...interface{}) ([]map[string]interface{}, error)

QueryWithTx is query method within the transaction.

type SQL Uses

type SQL struct {
    dialect.SQLComponent
    // contains filtered or unexported fields
}

SQL wraps the Connection and driver dialect methods.

func Table Uses

func Table(table string) *SQL

TableName return a SQL with given table and default connection.

func WithDriver Uses

func WithDriver(conn Connection) *SQL

WithDriver return a SQL with given driver.

func WithDriverAndConnection Uses

func WithDriverAndConnection(connName string, conn Connection) *SQL

WithDriverAndConnection return a SQL with given driver and connection name.

func (*SQL) All Uses

func (sql *SQL) All() ([]map[string]interface{}, error)

All query all the result and return.

func (*SQL) Avg Uses

func (sql *SQL) Avg(field string) (interface{}, error)

Avg find the average value of given field.

func (*SQL) Count Uses

func (sql *SQL) Count() (int64, error)

Count query the count of query results.

func (*SQL) Delete Uses

func (sql *SQL) Delete() error

Delete exec the delete method.

func (*SQL) Exec Uses

func (sql *SQL) Exec() (int64, error)

Exec exec the exec method.

func (*SQL) Find Uses

func (sql *SQL) Find(arg interface{}) (map[string]interface{}, error)

Find query the sql result with given id assuming that primary key name is "id".

func (*SQL) First Uses

func (sql *SQL) First() (map[string]interface{}, error)

First query the result and return the first row.

func (*SQL) GroupBy Uses

func (sql *SQL) GroupBy(fields ...string) *SQL

func (*SQL) Insert Uses

func (sql *SQL) Insert(values dialect.H) (int64, error)

Insert exec the insert method of given key/value pairs.

func (*SQL) LeftJoin Uses

func (sql *SQL) LeftJoin(table string, fieldA string, operation string, fieldB string) *SQL

LeftJoin add a left join info.

func (*SQL) Max Uses

func (sql *SQL) Max(field string) (interface{}, error)

Max find the maximal value of given field.

func (*SQL) Min Uses

func (sql *SQL) Min(field string) (interface{}, error)

Min find the minimal value of given field.

func (*SQL) OrderBy Uses

func (sql *SQL) OrderBy(fields ...string) *SQL

OrderBy set order fields.

func (*SQL) Select Uses

func (sql *SQL) Select(fields ...string) *SQL

Select set select fields.

func (*SQL) ShowColumns Uses

func (sql *SQL) ShowColumns() ([]map[string]interface{}, error)

ShowColumns show columns info.

func (*SQL) ShowTables Uses

func (sql *SQL) ShowTables() ([]map[string]interface{}, error)

ShowTables show table info.

func (*SQL) Skip Uses

func (sql *SQL) Skip(offset int) *SQL

Skip set offset value.

func (*SQL) Sum Uses

func (sql *SQL) Sum(field string) (float64, error)

Sum sum the value of given field.

func (*SQL) Table Uses

func (sql *SQL) Table(table string) *SQL

TableName set table of SQL.

func (*SQL) Take Uses

func (sql *SQL) Take(take int) *SQL

Take set limit value.

func (*SQL) Update Uses

func (sql *SQL) Update(values dialect.H) (int64, error)

Update exec the update method of given key/value pairs.

func (*SQL) UpdateRaw Uses

func (sql *SQL) UpdateRaw(raw string, args ...interface{}) *SQL

UpdateRaw set UpdateRaw.

func (*SQL) Where Uses

func (sql *SQL) Where(field string, operation string, arg interface{}) *SQL

Where add the where operation and argument value.

func (*SQL) WhereIn Uses

func (sql *SQL) WhereIn(field string, arg []interface{}) *SQL

WhereIn add the where operation of "in" and argument values.

func (*SQL) WhereNotIn Uses

func (sql *SQL) WhereNotIn(field string, arg []interface{}) *SQL

WhereNotIn add the where operation of "not in" and argument values.

func (*SQL) WhereRaw Uses

func (sql *SQL) WhereRaw(raw string, args ...interface{}) *SQL

WhereRaw set WhereRaws and arguments.

func (*SQL) WithConnection Uses

func (sql *SQL) WithConnection(conn string) *SQL

WithConnection set the connection name of SQL.

func (*SQL) WithDriver Uses

func (sql *SQL) WithDriver(conn Connection) *SQL

WithDriver return a SQL with given driver.

func (*SQL) WithTransaction Uses

func (sql *SQL) WithTransaction(fn TxFn) (res map[string]interface{}, err error)

WithTransaction call the callback function within the transaction and catch the error.

func (*SQL) WithTransactionByLevel Uses

func (sql *SQL) WithTransactionByLevel(level dbsql.IsolationLevel, fn TxFn) (res map[string]interface{}, err error)

WithTransactionByLevel call the callback function within the transaction of given transaction level and catch the error.

func (*SQL) WithTx Uses

func (sql *SQL) WithTx(tx *dbsql.Tx) *SQL

WithTx set the database transaction object of SQL.

type SQLTx Uses

type SQLTx struct {
    Tx *sql.Tx
}

SQLTx is an in-progress database transaction.

type Sqlite Uses

type Sqlite struct {
    Base
}

Sqlite is a Connection of sqlite.

func GetSqliteDB Uses

func GetSqliteDB() *Sqlite

GetSqliteDB return the global sqlite connection.

func (*Sqlite) BeginTx Uses

func (db *Sqlite) BeginTx() *sql.Tx

BeginTx starts a transaction with level LevelDefault.

func (*Sqlite) BeginTxAndConnection Uses

func (db *Sqlite) BeginTxAndConnection(conn string) *sql.Tx

BeginTxAndConnection starts a transaction with level LevelDefault and connection.

func (*Sqlite) BeginTxWithLevel Uses

func (db *Sqlite) BeginTxWithLevel(level sql.IsolationLevel) *sql.Tx

BeginTxWithLevel starts a transaction with given transaction isolation level.

func (*Sqlite) BeginTxWithLevelAndConnection Uses

func (db *Sqlite) BeginTxWithLevelAndConnection(conn string, level sql.IsolationLevel) *sql.Tx

BeginTxWithLevelAndConnection starts a transaction with given transaction isolation level and connection.

func (*Sqlite) BeginTxWithReadCommitted Uses

func (db *Sqlite) BeginTxWithReadCommitted() *sql.Tx

BeginTxWithReadCommitted starts a transaction with level LevelReadCommitted.

func (*Sqlite) BeginTxWithReadCommittedAndConnection Uses

func (db *Sqlite) BeginTxWithReadCommittedAndConnection(conn string) *sql.Tx

BeginTxWithReadCommittedAndConnection starts a transaction with level LevelReadCommitted and connection.

func (*Sqlite) BeginTxWithReadUncommitted Uses

func (db *Sqlite) BeginTxWithReadUncommitted() *sql.Tx

BeginTxWithReadUncommitted starts a transaction with level LevelReadUncommitted.

func (*Sqlite) BeginTxWithReadUncommittedAndConnection Uses

func (db *Sqlite) BeginTxWithReadUncommittedAndConnection(conn string) *sql.Tx

BeginTxWithReadUncommittedAndConnection starts a transaction with level LevelReadUncommitted and connection.

func (*Sqlite) BeginTxWithRepeatableRead Uses

func (db *Sqlite) BeginTxWithRepeatableRead() *sql.Tx

BeginTxWithRepeatableRead starts a transaction with level LevelRepeatableRead.

func (*Sqlite) BeginTxWithRepeatableReadAndConnection Uses

func (db *Sqlite) BeginTxWithRepeatableReadAndConnection(conn string) *sql.Tx

BeginTxWithRepeatableReadAndConnection starts a transaction with level LevelRepeatableRead and connection.

func (*Sqlite) Exec Uses

func (db *Sqlite) Exec(query string, args ...interface{}) (sql.Result, error)

Exec implements the method Connection.Exec.

func (*Sqlite) ExecWithConnection Uses

func (db *Sqlite) ExecWithConnection(con string, query string, args ...interface{}) (sql.Result, error)

ExecWithConnection implements the method Connection.ExecWithConnection.

func (*Sqlite) ExecWithTx Uses

func (db *Sqlite) ExecWithTx(tx *sql.Tx, query string, args ...interface{}) (sql.Result, error)

ExecWithTx is exec method within the transaction.

func (*Sqlite) GetDelimiter Uses

func (db *Sqlite) GetDelimiter() string

GetDelimiter implements the method Connection.GetDelimiter.

func (*Sqlite) InitDB Uses

func (db *Sqlite) InitDB(cfgList map[string]config.Database) Connection

InitDB implements the method Connection.InitDB.

func (*Sqlite) Name Uses

func (db *Sqlite) Name() string

Name implements the method Connection.Name.

func (*Sqlite) Query Uses

func (db *Sqlite) Query(query string, args ...interface{}) ([]map[string]interface{}, error)

Query implements the method Connection.Query.

func (*Sqlite) QueryWithConnection Uses

func (db *Sqlite) QueryWithConnection(con string, query string, args ...interface{}) ([]map[string]interface{}, error)

QueryWithConnection implements the method Connection.QueryWithConnection.

func (*Sqlite) QueryWithTx Uses

func (db *Sqlite) QueryWithTx(tx *sql.Tx, query string, args ...interface{}) ([]map[string]interface{}, error)

QueryWithTx is query method within the transaction.

type TxFn Uses

type TxFn func(tx *dbsql.Tx) (error, map[string]interface{})

TxFn is the transaction callback function.

type Value Uses

type Value string

Value is a string.

func GetValueFromDatabaseType Uses

func GetValueFromDatabaseType(typ DatabaseType, value interface{}) Value

GetValueFromDatabaseType return Value of given DatabaseType and interface.

func (Value) String Uses

func (v Value) String() string

String return the string value.

func (Value) ToInt64 Uses

func (v Value) ToInt64() int64

ToInt64 turn the string to a int64.

Directories

PathSynopsis
dialect
drivers/mssql
drivers/mysql
drivers/postgres
drivers/sqlite

Package db imports 13 packages (graph) and is imported by 27 packages. Updated 2020-01-16. Refresh now. Tools for package owners.