Documentation ¶
Index ¶
- func TimeFormat(t *time.Time) string
- type Column
- type CommonSQLGenerator
- type DB
- func (d *DB) Begin() (*Tx, error)
- func (d *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
- func (d *DB) Close() error
- func (e DB) Exec(query string, args ...interface{}) (rs sql.Result, err error)
- func (e DB) ExecContext(ctx context.Context, query string, args ...interface{}) (rs sql.Result, err error)
- func (e DB) Get(dest interface{}, query string, args ...interface{}) (err error)
- func (e DB) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error)
- func (e DB) Insert(value interface{}) (sql.Result, error)
- func (e DB) InsertContext(ctx context.Context, value interface{}) (rs sql.Result, err error)
- func (e DB) MustExec(query string, args ...interface{}) (rs sql.Result)
- func (e DB) MustGet(dest interface{}, query string, args ...interface{}) bool
- func (e DB) MustInsert(value interface{}) sql.Result
- func (e DB) MustNamedExec(query string, arg map[string]interface{}) sql.Result
- func (e DB) MustNamedGet(dest interface{}, query string, arg map[string]interface{}) bool
- func (e DB) MustNamedQuery(dest interface{}, query string, arg map[string]interface{})
- func (e DB) MustQuery(dest interface{}, query string, args ...interface{})
- func (e DB) MustUpdate(value interface{}, columns ...string) (rs sql.Result)
- func (e DB) NamedExec(query string, arg map[string]interface{}) (sql.Result, error)
- func (e DB) NamedExecContext(ctx context.Context, query string, arg map[string]interface{}) (sql.Result, error)
- func (e DB) NamedGet(dest interface{}, query string, arg map[string]interface{}) (err error)
- func (e DB) NamedGetContext(ctx context.Context, dest interface{}, query string, ...) (err error)
- func (e DB) NamedQuery(dest interface{}, query string, arg map[string]interface{}) (err error)
- func (e DB) NamedQueryContext(ctx context.Context, dest interface{}, query string, ...) (err error)
- func (d *DB) Options() *Options
- func (e DB) Prepare(query string) (*Stmt, error)
- func (e DB) PrepareContext(ctx context.Context, query string) (*Stmt, error)
- func (e DB) Query(dest interface{}, query string, args ...interface{}) (err error)
- func (e DB) QueryContext(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error)
- func (d *DB) RawDB() *sql.DB
- func (d *DB) Transaction(fn func(*Tx) error) error
- func (e DB) Update(value interface{}, columns ...string) (sql.Result, error)
- func (e DB) UpdateContext(ctx context.Context, value interface{}, columns ...string) (rs sql.Result, err error)
- type Executor
- type Logger
- type Options
- type SQLGenerator
- type Stmt
- func (s *Stmt) Close() error
- func (s *Stmt) Exec() (sql.Result, error)
- func (s *Stmt) ExecContext(ctx context.Context, args ...interface{}) (sql.Result, error)
- func (s *Stmt) Get(dest interface{}, args ...interface{}) error
- func (s *Stmt) GetContext(ctx context.Context, dest interface{}, args ...interface{}) error
- func (s *Stmt) Query(dest interface{}, args ...interface{}) error
- func (s *Stmt) QueryContext(ctx context.Context, dest interface{}, args ...interface{}) error
- type Table
- type Tx
- func (t *Tx) Commit() error
- func (e Tx) Exec(query string, args ...interface{}) (rs sql.Result, err error)
- func (e Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (rs sql.Result, err error)
- func (e Tx) Get(dest interface{}, query string, args ...interface{}) (err error)
- func (e Tx) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error)
- func (e Tx) Insert(value interface{}) (sql.Result, error)
- func (e Tx) InsertContext(ctx context.Context, value interface{}) (rs sql.Result, err error)
- func (e Tx) MustExec(query string, args ...interface{}) (rs sql.Result)
- func (e Tx) MustGet(dest interface{}, query string, args ...interface{}) bool
- func (e Tx) MustInsert(value interface{}) sql.Result
- func (e Tx) MustNamedExec(query string, arg map[string]interface{}) sql.Result
- func (e Tx) MustNamedGet(dest interface{}, query string, arg map[string]interface{}) bool
- func (e Tx) MustNamedQuery(dest interface{}, query string, arg map[string]interface{})
- func (e Tx) MustQuery(dest interface{}, query string, args ...interface{})
- func (e Tx) MustUpdate(value interface{}, columns ...string) (rs sql.Result)
- func (e Tx) NamedExec(query string, arg map[string]interface{}) (sql.Result, error)
- func (e Tx) NamedExecContext(ctx context.Context, query string, arg map[string]interface{}) (sql.Result, error)
- func (e Tx) NamedGet(dest interface{}, query string, arg map[string]interface{}) (err error)
- func (e Tx) NamedGetContext(ctx context.Context, dest interface{}, query string, ...) (err error)
- func (e Tx) NamedQuery(dest interface{}, query string, arg map[string]interface{}) (err error)
- func (e Tx) NamedQueryContext(ctx context.Context, dest interface{}, query string, ...) (err error)
- func (e Tx) Prepare(query string) (*Stmt, error)
- func (e Tx) PrepareContext(ctx context.Context, query string) (*Stmt, error)
- func (e Tx) Query(dest interface{}, query string, args ...interface{}) (err error)
- func (e Tx) QueryContext(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error)
- func (t *Tx) Rollback() error
- func (e Tx) Update(value interface{}, columns ...string) (sql.Result, error)
- func (e Tx) UpdateContext(ctx context.Context, value interface{}, columns ...string) (rs sql.Result, err error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TimeFormat ¶
Types ¶
type CommonSQLGenerator ¶
type CommonSQLGenerator struct { }
func NewCommonSQLGenerator ¶
func NewCommonSQLGenerator() *CommonSQLGenerator
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
func Open ¶
Open a database
Example ¶
db, err = Open("mysql", "root:basebitxdp@tcp(172.18.0.210:32600)/enigma2_accountx?parseTime=True&loc=Local") if err != nil { panic(err) }
Output:
func (*DB) Close ¶
Close the database and prevents newDBX queries from starting. Close then waits for all queries that have started processing on the server to finish.
It is rare to Close a DB, as the DB handle is meant to be long-lived and shared between many goroutines.
func (DB) Exec ¶
Exec executes a query without returning any rows. The args are for any placeholder parameters in the query.
func (DB) ExecContext ¶
func (e DB) ExecContext(ctx context.Context, query string, args ...interface{}) (rs sql.Result, err error)
ExecContext executes a query without returning any rows. The args are for any placeholder parameters in the query.
func (DB) Get ¶
Get execute the query and scan the first row to dest, dest must be a pointer. if dest is a type supported by the database (string , int, []byte, time.Time, etc.) and there is only one column, the row will be assigned to dest. if dest is a struct, it will be mapped to the dbx tag field in the struct according to the name of each column. An sql.ErrNoRows is returned if the result set is empty.
func (DB) GetContext ¶
func (e DB) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error)
GetContext execute the query and scan the first row to dest, dest must be a pointer. if dest is a type supported by the database (string , int, []byte, time.Time, etc.) and there is only one column, the row will be assigned to dest. if dest is a struct, it will be mapped to the dbx tag field in the struct according to the name of each column. An sql.ErrNoRows is returned if the result set is empty.
func (DB) InsertContext ¶
InsertContext insert a struct to database
func (DB) MustGet ¶
MustGet is the same as Get, if there is a error in query, it will panics, but sql.ErrNoRows will return false
func (DB) MustInsert ¶
MustInsert is the same as Insert but panics if cannot insert.
func (DB) MustNamedExec ¶
MustNamedExec is the same as NamedExec but panics if cannot insert.
func (DB) MustNamedGet ¶
MustNamedGet is the same as NamedGet, if there is a error in query, it will panics, but sql.ErrNoRows will return false
func (DB) MustNamedQuery ¶
MustNamedQuery like NamedQuery but panics if cannot query.
func (DB) MustQuery ¶
func (e DB) MustQuery(dest interface{}, query string, args ...interface{})
MustQuery is the same as Query but panics if cannot query.
func (DB) MustUpdate ¶
MustUpdate is the same as Update, but panics if cannot update.
func (DB) NamedExec ¶
NamedExec executes a Named query without returning any rows. The arg are for any placeholder parameters in the query.
func (DB) NamedExecContext ¶
func (e DB) NamedExecContext(ctx context.Context, query string, arg map[string]interface{}) (sql.Result, error)
NamedExecContext executes a Named query without returning any rows. The arg are for any placeholder parameters in the query.
func (DB) NamedGet ¶
NamedGet execute the Named query and scan the first row to dest, dest must be a pointer. if dest is a type supported by the database (string , int, []byte, time.Time, etc.) and there is only one column, the row will be assigned to dest. if dest is a struct, it will be mapped to the dbx tag field in the struct according to the name of each column. A sql.ErrNoRows is returned if the result set is empty.
func (DB) NamedGetContext ¶
func (e DB) NamedGetContext(ctx context.Context, dest interface{}, query string, arg map[string]interface{}) (err error)
NamedGetContext execute the Named query and scan the first row to dest, dest must be a pointer. if dest is a type supported by the database (string , int, []byte, time.Time, etc.) and there is only one column, the row will be assigned to dest. if dest is a struct, it will be mapped to the dbx tag field in the struct according to the name of each column. A sql.ErrNoRows is returned if the result set is empty.
func (DB) NamedQuery ¶
NamedQuery execute the query and scan the rows to dest, dest must be a slice of pointer. if dest is a type supported by the database ([]string , []int, []byte, []time.Time, etc.) and there is only one column, the rows will be assigned to dest. if dest is a struct, it will be mapped to the dbx tag field in the struct according to the name of each column.
func (DB) NamedQueryContext ¶
func (e DB) NamedQueryContext(ctx context.Context, dest interface{}, query string, arg map[string]interface{}) (err error)
NamedQueryContext execute the query and scan the rows to dest, dest must be a slice of pointer. if dest is a type supported by the database ([]string , []int, []byte, []time.Time, etc.) and there is only one column, the rows will be assigned to dest. if dest is a struct, it will be mapped to the dbx tag field in the struct according to the name of each column.
func (DB) PrepareContext ¶
PrepareContext creates a prepared statement
func (DB) Query ¶
Query execute the query and scan the rows to dest, dest must be a slice of pointer. if dest is a type supported by the database ([]string , []int, []byte, []time.Time, etc.) and there is only one column, the rows will be assigned to dest. if dest is a struct, it will be mapped to the dbx tag field in the struct according to the name of each column.
func (DB) QueryContext ¶
func (e DB) QueryContext(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error)
QueryContext execute the query and scan the rows to dest, dest must be a slice of pointer. if dest is a type supported by the database ([]string , []int, []byte, []time.Time, etc.) and there is only one column, the rows will be assigned to dest. if dest is a struct, it will be mapped to the dbx tag field in the struct according to the name of each column.
func (*DB) Transaction ¶
Transaction begin a transaction and commit automatically,automatically roll back when there is an error.
type Executor ¶
type Executor interface { // NamedExecContext executes a Named query without returning any rows. // The arg are for any placeholder parameters in the query. NamedExecContext(ctx context.Context, query string, arg map[string]interface{}) (sql.Result, error) // NamedExec executes a Named query without returning any rows. // The arg are for any placeholder parameters in the query. NamedExec(query string, arg map[string]interface{}) (sql.Result, error) // MustNamedExec is the same as NamedExec but panics if cannot insert. MustNamedExec(query string, arg map[string]interface{}) sql.Result // NamedGetContext execute the Named query and scan the first row to dest, dest must be a pointer. // if dest is a type supported by the database (string , int, []byte, time.Time, etc.) // and there is only one column, the row will be assigned to dest. // if dest is a struct, it will be mapped to the dbx tag field in the struct according to the name of each column. // A sql.ErrNoRows is returned if the result set is empty. NamedGetContext(ctx context.Context, dest interface{}, query string, arg map[string]interface{}) error // NamedGet execute the Named query and scan the first row to dest, dest must be a pointer. // if dest is a type supported by the database (string , int, []byte, time.Time, etc.) // and there is only one column, the row will be assigned to dest. // if dest is a struct, it will be mapped to the dbx tag field in the struct according to the name of each column. // A sql.ErrNoRows is returned if the result set is empty. NamedGet(dest interface{}, query string, arg map[string]interface{}) error // MustNamedGet is the same as NamedGet, if there is a error in query, it will panics, // but sql.ErrNoRows will return false MustNamedGet(dest interface{}, query string, arg map[string]interface{}) bool // NamedQueryContext execute the query and scan the rows to dest, dest must be a slice of pointer. // if dest is a type supported by the database ([]string , []int, []byte, []time.Time, etc.) // and there is only one column, the rows will be assigned to dest. // if dest is a struct, it will be mapped to the dbx tag field in the struct according to the name of each column. NamedQueryContext(ctx context.Context, dest interface{}, query string, arg map[string]interface{}) error // NamedQuery execute the query and scan the rows to dest, dest must be a slice of pointer. // if dest is a type supported by the database ([]string , []int, []byte, []time.Time, etc.) // and there is only one column, the rows will be assigned to dest. // if dest is a struct, it will be mapped to the dbx tag field in the struct according to the name of each column. NamedQuery(dest interface{}, query string, arg map[string]interface{}) error // MustNamedQuery like NamedQuery but panics if cannot query. MustNamedQuery(dest interface{}, query string, arg map[string]interface{}) // PrepareContext creates a prepared statement PrepareContext(ctx context.Context, query string) (*Stmt, error) // Prepare creates a prepared statement Prepare(query string) (*Stmt, error) // ExecContext executes a query without returning any rows. // The args are for any placeholder parameters in the query. ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) // Exec executes a query without returning any rows. // The args are for any placeholder parameters in the query. Exec(query string, args ...interface{}) (sql.Result, error) // MustExec is the same as Exec but panics if cannot insert. MustExec(query string, args ...interface{}) sql.Result // GetContext execute the query and scan the first row to dest, dest must be a pointer. // if dest is a type supported by the database (string , int, []byte, time.Time, etc.) // and there is only one column, the row will be assigned to dest. // if dest is a struct, it will be mapped to the dbx tag field in the struct according to the name of each column. // A sql.ErrNoRows is returned if the result set is empty. GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error) // Get execute the query and scan the first row to dest, dest must be a pointer. // If dest is a type supported by the database (string , int, []byte, time.Time, etc.) // and there is only one column, the row will be assigned to dest. // If dest is a struct, it will be mapped to the dbx tag field in the struct according to the name of each column. // A sql.ErrNoRows is returned, if the query selects no rows. Get(dest interface{}, query string, args ...interface{}) (err error) // MustGet is the same as Get, if there is a error in query, it will panics, // but sql.ErrNoRows will return false MustGet(dest interface{}, query string, args ...interface{}) bool // QueryContext execute the query and scan the rows to dest, dest must be a slice of pointer. // if dest is a type supported by the database ([]string , []int, []byte, []time.Time, etc.) // and there is only one column, the rows will be assigned to dest. // if dest is a struct, it will be mapped to the dbx tag field in the struct according to the name of each column. QueryContext(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error) // Query execute the query and scan the rows to dest, dest must be a slice of pointer. // if dest is a type supported by the database ([]string , []int, []byte, []time.Time, etc.) // and there is only one column, the rows will be assigned to dest. // if dest is a struct, it will be mapped to the dbx tag field in the struct according to the name of each column. Query(dest interface{}, query string, args ...interface{}) (err error) // MustQuery is the same as Query but panics if cannot query. MustQuery(dest interface{}, query string, args ...interface{}) // InsertContext insert a struct to database InsertContext(ctx context.Context, value interface{}) (rs sql.Result, err error) // Insert a struct to database Insert(value interface{}) (sql.Result, error) // MustInsert is the same as Insert but panics if cannot insert. MustInsert(value interface{}) sql.Result // UpdateContext update the rows according to the value of structure, if the column name is specified, // only the specified column is updated. UpdateContext(ctx context.Context, value interface{}, columns ...string) (rs sql.Result, err error) // Update the rows according to the value of structure, if the column name is specified, // only the specified column is updated. Update(value interface{}, columns ...string) (sql.Result, error) // MustUpdate is the same as Update, but panics if cannot update. MustUpdate(value interface{}, columns ...string) (rs sql.Result) }
type SQLGenerator ¶
type Stmt ¶
type Stmt struct {
// contains filtered or unexported fields
}
Stmt is a preparer statement. it is like sql.Stmt.
func (*Stmt) ExecContext ¶
func (*Stmt) GetContext ¶
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
func (Tx) Exec ¶
Exec executes a query without returning any rows. The args are for any placeholder parameters in the query.
func (Tx) ExecContext ¶
func (e Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (rs sql.Result, err error)
ExecContext executes a query without returning any rows. The args are for any placeholder parameters in the query.
func (Tx) Get ¶
Get execute the query and scan the first row to dest, dest must be a pointer. if dest is a type supported by the database (string , int, []byte, time.Time, etc.) and there is only one column, the row will be assigned to dest. if dest is a struct, it will be mapped to the dbx tag field in the struct according to the name of each column. An sql.ErrNoRows is returned if the result set is empty.
func (Tx) GetContext ¶
func (e Tx) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error)
GetContext execute the query and scan the first row to dest, dest must be a pointer. if dest is a type supported by the database (string , int, []byte, time.Time, etc.) and there is only one column, the row will be assigned to dest. if dest is a struct, it will be mapped to the dbx tag field in the struct according to the name of each column. An sql.ErrNoRows is returned if the result set is empty.
func (Tx) InsertContext ¶
InsertContext insert a struct to database
func (Tx) MustGet ¶
MustGet is the same as Get, if there is a error in query, it will panics, but sql.ErrNoRows will return false
func (Tx) MustInsert ¶
MustInsert is the same as Insert but panics if cannot insert.
func (Tx) MustNamedExec ¶
MustNamedExec is the same as NamedExec but panics if cannot insert.
func (Tx) MustNamedGet ¶
MustNamedGet is the same as NamedGet, if there is a error in query, it will panics, but sql.ErrNoRows will return false
func (Tx) MustNamedQuery ¶
MustNamedQuery like NamedQuery but panics if cannot query.
func (Tx) MustQuery ¶
func (e Tx) MustQuery(dest interface{}, query string, args ...interface{})
MustQuery is the same as Query but panics if cannot query.
func (Tx) MustUpdate ¶
MustUpdate is the same as Update, but panics if cannot update.
func (Tx) NamedExec ¶
NamedExec executes a Named query without returning any rows. The arg are for any placeholder parameters in the query.
func (Tx) NamedExecContext ¶
func (e Tx) NamedExecContext(ctx context.Context, query string, arg map[string]interface{}) (sql.Result, error)
NamedExecContext executes a Named query without returning any rows. The arg are for any placeholder parameters in the query.
func (Tx) NamedGet ¶
NamedGet execute the Named query and scan the first row to dest, dest must be a pointer. if dest is a type supported by the database (string , int, []byte, time.Time, etc.) and there is only one column, the row will be assigned to dest. if dest is a struct, it will be mapped to the dbx tag field in the struct according to the name of each column. A sql.ErrNoRows is returned if the result set is empty.
func (Tx) NamedGetContext ¶
func (e Tx) NamedGetContext(ctx context.Context, dest interface{}, query string, arg map[string]interface{}) (err error)
NamedGetContext execute the Named query and scan the first row to dest, dest must be a pointer. if dest is a type supported by the database (string , int, []byte, time.Time, etc.) and there is only one column, the row will be assigned to dest. if dest is a struct, it will be mapped to the dbx tag field in the struct according to the name of each column. A sql.ErrNoRows is returned if the result set is empty.
func (Tx) NamedQuery ¶
NamedQuery execute the query and scan the rows to dest, dest must be a slice of pointer. if dest is a type supported by the database ([]string , []int, []byte, []time.Time, etc.) and there is only one column, the rows will be assigned to dest. if dest is a struct, it will be mapped to the dbx tag field in the struct according to the name of each column.
func (Tx) NamedQueryContext ¶
func (e Tx) NamedQueryContext(ctx context.Context, dest interface{}, query string, arg map[string]interface{}) (err error)
NamedQueryContext execute the query and scan the rows to dest, dest must be a slice of pointer. if dest is a type supported by the database ([]string , []int, []byte, []time.Time, etc.) and there is only one column, the rows will be assigned to dest. if dest is a struct, it will be mapped to the dbx tag field in the struct according to the name of each column.
func (Tx) PrepareContext ¶
PrepareContext creates a prepared statement
func (Tx) Query ¶
Query execute the query and scan the rows to dest, dest must be a slice of pointer. if dest is a type supported by the database ([]string , []int, []byte, []time.Time, etc.) and there is only one column, the rows will be assigned to dest. if dest is a struct, it will be mapped to the dbx tag field in the struct according to the name of each column.
func (Tx) QueryContext ¶
func (e Tx) QueryContext(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error)
QueryContext execute the query and scan the rows to dest, dest must be a slice of pointer. if dest is a type supported by the database ([]string , []int, []byte, []time.Time, etc.) and there is only one column, the rows will be assigned to dest. if dest is a struct, it will be mapped to the dbx tag field in the struct according to the name of each column.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
internal/module
Code generated by dbx-generator.
|
Code generated by dbx-generator. |
internal
|
|