Documentation
¶
Index ¶
- Constants
- func GenerateAddOnQuery(ctx context.Context, reqData *TableRequest) (string, []interface{}, error)
- type BaseColumn
- type CUDConstructData
- type CUDResponse
- type Follower
- type ISQL
- type Master
- type QueryOpts
- type ResponseMetaData
- type SQL
- func (this *SQL) Get(dest interface{}, query string, args ...interface{}) error
- func (this *SQL) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
- func (this *SQL) GetTransaction() Transactions
- func (this *SQL) NamedQuery(query string, arg interface{}) (*sqlx.Rows, error)
- func (this *SQL) NamedQueryContext(ctx context.Context, query string, arg interface{}) (*sqlx.Rows, error)
- func (this *SQL) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (this *SQL) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (this *SQL) QueryRow(query string, args ...interface{}) *sql.Row
- func (this *SQL) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
- func (this *SQL) QueryRowx(query string, args ...interface{}) *sqlx.Row
- func (this *SQL) QueryRowxContext(ctx context.Context, query string, args ...interface{}) *sqlx.Row
- func (this *SQL) QueryxContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error)
- func (this *SQL) Read(ctx context.Context, opts *QueryOpts, additionalParams ...interface{}) error
- func (this *SQL) Rebind(sql string) string
- func (this *SQL) Select(dest interface{}, query string, args ...interface{}) error
- func (this *SQL) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
- func (this *SQL) Write(ctx context.Context, opts *QueryOpts, isSoftDelete ...bool) (*CUDResponse, error)
- type SQLConfig
- type SQLs
- type SelectResponse
- type TableRequest
- type TimeCol
- type Transaction
- type Transactions
Constants ¶
View Source
const ( ActionInsert = "insert" ActionUpdate = "update" ActionUpsert = "upsert" ActionDelete = "delete" ActionBulkInsert = "bulk_insert" ActionBulkUpdate = "bulk_update" ActionUpdateById = "update_by_id" ActionDeleteById = "delete_by_id" MySQLEngine = "mysql" NRMySQLEngine = "nrmysql" PostgresEngine = "postgres" NRPostgresEngine = "nrpostgres" LockUpdate = "update" NewRelicAttributeQuery = "query" NewRelicAttributeParams = "params" )
Variables ¶
This section is empty.
Functions ¶
func GenerateAddOnQuery ¶
func GenerateAddOnQuery(ctx context.Context, reqData *TableRequest) (string, []interface{}, error)
Types ¶
type BaseColumn ¶
type CUDConstructData ¶
type CUDConstructData struct {
Cols []string `json:"cols"`
Values []interface{} `json:"values"`
ColsInsert string
BulkValues string
BulkQuery string
Action string
TableName string
}
func (*CUDConstructData) SetValues ¶
func (req *CUDConstructData) SetValues(value interface{})
type CUDResponse ¶
type CUDResponse struct {
Status bool `json:"status"`
RowsAffected int64 `json:"rows_affected"`
LastInsertID int64 `json:"last_insert_id"`
Message string `json:"message,omitempty"`
// contains filtered or unexported fields
}
func (*CUDResponse) GetGeneratedQuery ¶
func (e *CUDResponse) GetGeneratedQuery() map[string][]interface{}
GetGeneratedQuery - return query + params with format map[<query>]<params>
type Follower ¶
type Follower interface {
// Get from follower database
Get(dest interface{}, query string, args ...interface{}) error
// Select from follower database
Select(dest interface{}, query string, args ...interface{}) error
// Query from follower database
Query(query string, args ...interface{}) (*sql.Rows, error)
// NamedQuery do named query on follower DB
NamedQuery(query string, arg interface{}) (*sqlx.Rows, error)
// GetContext from sql database
GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
// SelectContext from sql database
SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
// QueryContext from sql database
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
// QueryxContext queries the database and returns an *sqlx.Rows. Any placeholder parameters are replaced with supplied args.
QueryxContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error)
// QueryRowxContext queries the database and returns an *sqlx.Row. Any placeholder parameters are replaced with supplied args.
QueryRowxContext(ctx context.Context, query string, args ...interface{}) *sqlx.Row
// NamedQueryContext do named query on follower DB
NamedQueryContext(ctx context.Context, query string, arg interface{}) (*sqlx.Rows, error)
// contains filtered or unexported methods
}
Follower defines operation that will be executed to follower DB
type Master ¶
type Master interface {
Exec(query string, args ...interface{}) (sql.Result, error)
// ExecContext use master database to exec query
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
// Begin transaction on master DB
Begin() (*sql.Tx, error)
// Begin transaction on master DB
Beginx() (*sqlx.Tx, error)
// BeginTx begins transaction on master DB
BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
// NamedExec do named exec on master DB
NamedExec(query string, arg interface{}) (sql.Result, error)
// NamedExecContext do named exec on master DB
NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error)
// BindNamed do BindNamed on master DB
BindNamed(query string, arg interface{}) (string, []interface{}, error)
Follower
}
type QueryOpts ¶
type QueryOpts struct {
BaseQuery string
Conditions func(ctx context.Context) `json:"-"`
ExcludeColumns string
Columns string
OptionalTableName string // for view name
SelectRequest *TableRequest
CUDRequest *CUDConstructData
Result interface{}
IsList bool
UpsertInsertId int64
Trx *sqlx.Tx
LockingType string
UseMaster bool
// contains filtered or unexported fields
}
func (*QueryOpts) GetGeneratedQuery ¶
func (e *QueryOpts) GetGeneratedQuery() map[string][]interface{}
GetGeneratedQuery - return query + params with format map[<query>]<params>
type ResponseMetaData ¶
type SQL ¶
func (*SQL) GetContext ¶ added in v2.29.0
func (*SQL) GetTransaction ¶ added in v2.13.0
func (this *SQL) GetTransaction() Transactions
func (*SQL) NamedQuery ¶ added in v2.29.0
func (*SQL) NamedQueryContext ¶ added in v2.29.0
func (this *SQL) NamedQueryContext(ctx context.Context, query string, arg interface{}) (*sqlx.Rows, error)
NamedQueryContext do named query on follower DB
func (*SQL) QueryContext ¶ added in v2.29.0
func (this *SQL) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
QueryContext from sql database
func (*SQL) QueryRowContext ¶ added in v2.13.1
func (*SQL) QueryRowxContext ¶ added in v2.28.0
func (*SQL) QueryxContext ¶ added in v2.29.0
func (this *SQL) QueryxContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error)
QueryxContext queries the database and returns an *sqlx.Rows. Any placeholder parameters are replaced with supplied args.
type SQLConfig ¶
type SQLConfig struct {
Username string `yaml:"username"`
Password string `yaml:"password"`
Host string `yaml:"host"`
Port string `yaml:"port"`
Engine string `yaml:"engine"`
DBName string `yaml:"db_name"`
Timeout int `yaml:"timeout"`
MaxConnLifetime int `yaml:"max_conn_lifetime"`
MaxIdleTime int `yaml:"max_idle_time"`
MaxOpenConn int `yaml:"max_open_conn"`
MaxIdleConn int `yaml:"max_idle_conn"`
ConnString string `yaml:"conn_string"`
}
type SelectResponse ¶
type SelectResponse struct {
Data interface{} `json:"data"`
*ResponseMetaData
}
type TableRequest ¶
type TableRequest struct {
Keyword string `json:"keyword,omitempty" schema:"keyword"`
SearchColsStr string `json:"search_cols,omitempty" schema:"search_cols"`
SearchCols []string `json:"-"`
Page int `json:"page,omitempty" schema:"page"`
Limit int `json:"limit,omitempty" schema:"limit"`
OrderBy string `json:"order_by,omitempty" schema:"order_by"`
GroupBy string `json:"group_by,omitempty,omitempty" schema:"group_by"`
CreatedStart string `json:"date_start,omitempty" schema:"date_start"`
CreatedEnd string `json:"date_end,omitempty" schema:"date_end"`
CustomDateColFilter string `json:"-"` // specify this field manually at each of usecase services
InitiateWhere []string `json:"-"` // will be defined manually at each of usecase services
InitiateWhereValues []interface{} `json:"-"` // will be defined manually at each of usecase services
IncludeDeleted bool `json:"-"`
NotContainsDeletedCol bool `json:"-"`
MainTableAlias string `json:"-"`
IsDeleted string `json:"is_deleted,omitempty" schema:"is_deleted"`
// contains filtered or unexported fields
}
func (*TableRequest) SetWhereCondition ¶
func (req *TableRequest) SetWhereCondition(condition string, value ...interface{})
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
func NewTransaction ¶
func NewTransaction(db Master) *Transaction
Click to show internal directories.
Click to hide internal directories.