sqlx

package
v0.0.0-...-ac9c04b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2019 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EQ   = Op("eq")   // =
	NEQ  = Op("neq")  // <>
	LT   = Op("lt")   // <
	GT   = Op("gt")   // >
	LTE  = Op("lte")  // <=
	GTE  = Op("gte")  // >=
	LIKE = Op("like") // LIKE "PATTERN"
	OR   = Op("or")   // disjunction
	AND  = Op("and")  // conjunction
)

Operators that support by rql.

View Source
const POSTGRES string = "postgres"

Variables

This section is empty.

Functions

func Contains

func Contains(a []string, x string) bool

func FieldAlias

func FieldAlias(val string, a string) string

func GetPagination

func GetPagination(p *Pagination) (string, error)

func GetParam

func GetParam(params url.Values, key string, defaultVal string) []string

func TagsToField

func TagsToField(tag string, value interface{}) (result map[string][]interface{}, err error)

Types

type DB

type DB struct {
	*sql.DB
	RetryCount int
	Timeout    int
	Concurrent int
}

func New

func New(driverName, connString string, retryCount, timeout, concurrent int) (*DB, error)

func (*DB) BeginCtx

func (r *DB) BeginCtx() (context.Context, context.CancelFunc)

func (*DB) BeginTx

func (r *DB) BeginTx(ctx context.Context) (*sql.Tx, context.CancelFunc)

func (*DB) Close

func (r *DB) Close() error

func (*DB) ExecContext

func (r *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

func (*DB) PrepareContext

func (r *DB) PrepareContext(ctx context.Context, query string) (stmt *sql.Stmt, err error)

func (*DB) QueryCtx

func (r *DB) QueryCtx(ctx context.Context, fn func(rs *sql.Rows) error, query string, args ...interface{}) error

func (*DB) QueryRowCtx

func (r *DB) QueryRowCtx(ctx context.Context, fn func(rs *sql.Row) error, query string, args ...interface{}) error

func (*DB) TxCommit

func (r *DB) TxCommit(ctx context.Context, tx *sql.Tx) error

func (*DB) TxExecContext

func (r *DB) TxExecContext(ctx context.Context, tx *sql.Tx, query string, args ...interface{}) (affected int64, err error)

func (*DB) TxExecContextWithID

func (r *DB) TxExecContextWithID(ctx context.Context, tx *sql.Tx, query string, args ...interface{}) (ids interface{}, err error)

func (*DB) WithTransaction

func (r *DB) WithTransaction(ctx context.Context, fn func(tx *sql.Tx) error) error

type Factory

type Factory interface {
	Close() error
	BeginCtx() (context.Context, context.CancelFunc)
	BeginTx(ctx context.Context) (*sql.Tx, context.CancelFunc)
	QueryCtx(ctx context.Context, fn func(rs *sql.Rows) error, query string, args ...interface{}) error
	QueryRowCtx(ctx context.Context, fn func(rs *sql.Row) error, query string, args ...interface{}) error
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	TxExecContextWithID(ctx context.Context, tx *sql.Tx, query string, args ...interface{}) (ids interface{}, err error)
	TxExecContext(ctx context.Context, tx *sql.Tx, query string, args ...interface{}) (affected int64, err error)
	TxCommit(ctx context.Context, tx *sql.Tx) error
	WithTransaction(ctx context.Context, fn func(tx *sql.Tx) error) error
	PrepareContext(ctx context.Context, query string) (stmt *sql.Stmt, err error)
}

type Model

type Model interface {
	TableName() string
}

type NullBool

type NullBool struct {
	sql.NullBool
}

NullBool is an alias for sql.NullBool data type

func Bool

func Bool(value bool) NullBool

func (NullBool) MarshalJSON

func (nb NullBool) MarshalJSON() ([]byte, error)

MarshalJSON for NullBool

type NullFloat64

type NullFloat64 struct {
	sql.NullFloat64
}

NullFloat64 is an alias for sql.NullFloat64 data type

func Float64

func Float64(value float64) NullFloat64

func (NullFloat64) MarshalJSON

func (nf NullFloat64) MarshalJSON() ([]byte, error)

MarshalJSON for NullFloat64

type NullInt64

type NullInt64 struct {
	sql.NullInt64
}

NullInt64 is an alias for sql.NullInt64 data type

func Int64

func Int64(value int64) NullInt64

func (NullInt64) Int

func (ni NullInt64) Int() int

func (NullInt64) MarshalJSON

func (ni NullInt64) MarshalJSON() ([]byte, error)

MarshalJSON for NullInt64

type NullString

type NullString struct {
	sql.NullString
}

NullString is an alias for sql.NullString data type

func String

func String(value string) NullString

func (NullString) MarshalJSON

func (ns NullString) MarshalJSON() ([]byte, error)

MarshalJSON for NullString

type NullTime

type NullTime struct {
	Time  time.Time
	Valid bool // Valid is true if Time is not NULL
}

func Time

func Time(value time.Time) NullTime

func (NullTime) MarshalJSON

func (nt NullTime) MarshalJSON() ([]byte, error)

MarshalJSON for NullTime

func (NullTime) Scan

func (nt NullTime) Scan(value interface{}) error

Scan implements the Scanner interface.

func (NullTime) Value

func (nt NullTime) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Op

type Op string

Op is a filter operator used by rql.

func (Op) SQL

func (o Op) SQL() string

SQL returns the SQL representation of the operator.

type Pagination

type Pagination struct {
	Query        string
	Params       url.Values
	Model        interface{}
	AllowFields  []string
	DefaultValue string
	InjectWhere  string
	Aka          string
	Args         []interface{}
	QueryAll     string
	Limit        int
	Page         int
	Total        int
}

type Query

type Query struct {
	Query string
	Args  []interface{}
	// contains filtered or unexported fields
}

func Build

func Build() *Query

func (*Query) Insert

func (s *Query) Insert(model interface{}) *Query

func (*Query) Inserts

func (s *Query) Inserts(model interface{}) *Query

func (*Query) Join

func (s *Query) Join(model interface{}, fields ...string) *Query

inner join ref_user refUser on refUser.id = refGame.user_id

func (*Query) NewScope

func (s *Query) NewScope(model interface{}) *SQL

func (*Query) Select

func (s *Query) Select(model interface{}) *Query

func (*Query) SetTag

func (s *Query) SetTag(tag string) *Query

func (*Query) ToSQL

func (s *Query) ToSQL() (string, []interface{})

func (*Query) Updates

func (s *Query) Updates(model interface{}) *Query

func (*Query) Where

func (s *Query) Where(query interface{}, args ...interface{}) *Query

type QueryFilter

type QueryFilter struct {
	*bytes.Buffer
	Model    interface{}
	TagName  string
	FieldSep string
	Args     []interface{}
	Filter   interface{} `json:"filter"`
	Log      func(string, ...interface{})
}

func NewQueryFilter

func NewQueryFilter(model interface{}) (*QueryFilter, error)

NewParser creates a new Parser. it fails if the configuration is invalid.

func (*QueryFilter) QueryStringParser

func (p *QueryFilter) QueryStringParser(params url.Values, alias string, allowFields []string) (*QueryFilter, error)

type SQL

type SQL struct {
	Model   interface{}
	TagName string
	// contains filtered or unexported fields
}

func (*SQL) Exec

func (r *SQL) Exec()

func (*SQL) Where

func (r *SQL) Where(query interface{}, values ...interface{}) *SQL

type TxArgs

type TxArgs struct {
	Query string
	Args  []interface{}
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL