Documentation
¶
Index ¶
- Variables
- func InterpolateForDialect(query string, value []interface{}, d Dialect) (string, error)
- func Load(rows *sql.Rows, value interface{}) (int, error)
- func Union(builder ...Builder) interface{ ... }
- func UnionAll(builder ...Builder) interface{ ... }
- type Buffer
- type BuildFunc
- type Builder
- func And(cond ...Builder) Builder
- func Eq(column string, value interface{}) Builder
- func Expr(query string, value ...interface{}) Builder
- func Gt(column string, value interface{}) Builder
- func Gte(column string, value interface{}) Builder
- func Lt(column string, value interface{}) Builder
- func Lte(column string, value interface{}) Builder
- func Neq(column string, value interface{}) Builder
- func Or(cond ...Builder) Builder
- func Proposed(column string) Builder
- type ConflictStmt
- type Connection
- type DeleteBuilder
- type DeleteStmt
- type Dialect
- type EventReceiver
- type I
- type InsertBuilder
- func (b *InsertBuilder) Columns(column ...string) *InsertBuilder
- func (b *InsertBuilder) Exec() (sql.Result, error)
- func (b *InsertBuilder) OnConflictMap(constraint string, actions map[string]interface{}) *InsertBuilder
- func (b *InsertBuilder) Pair(column string, value interface{}) *InsertBuilder
- func (b *InsertBuilder) Record(structValue interface{}) *InsertBuilder
- func (b *InsertBuilder) Values(value ...interface{}) *InsertBuilder
- type InsertStmt
- func (b *InsertStmt) Build(d Dialect, buf Buffer) error
- func (b *InsertStmt) Columns(column ...string) *InsertStmt
- func (b *InsertStmt) OnConflict(constraint string) *ConflictStmt
- func (b *InsertStmt) OnConflictMap(constraint string, actions map[string]interface{}) *InsertStmt
- func (b *InsertStmt) Record(structValue interface{}) *InsertStmt
- func (b *InsertStmt) Values(value ...interface{}) *InsertStmt
- type NullBool
- type NullEventReceiver
- func (n *NullEventReceiver) Event(eventName string)
- func (n *NullEventReceiver) EventErr(eventName string, err error) error
- func (n *NullEventReceiver) EventErrKv(eventName string, err error, kvs map[string]string) error
- func (n *NullEventReceiver) EventKv(eventName string, kvs map[string]string)
- func (n *NullEventReceiver) Timing(eventName string, nanoseconds int64)
- func (n *NullEventReceiver) TimingKv(eventName string, nanoseconds int64, kvs map[string]string)
- type NullFloat64
- type NullInt64
- type NullString
- type NullTime
- type SelectBuilder
- func (b *SelectBuilder) Distinct() *SelectBuilder
- func (b *SelectBuilder) ForUpdate() *SelectBuilder
- func (b *SelectBuilder) From(table interface{}) *SelectBuilder
- func (b *SelectBuilder) FullJoin(table, on interface{}) *SelectBuilder
- func (b *SelectBuilder) GroupBy(col ...string) *SelectBuilder
- func (b *SelectBuilder) Having(query interface{}, value ...interface{}) *SelectBuilder
- func (b *SelectBuilder) Join(table, on interface{}) *SelectBuilder
- func (b *SelectBuilder) LeftJoin(table, on interface{}) *SelectBuilder
- func (b *SelectBuilder) Limit(n uint64) *SelectBuilder
- func (b *SelectBuilder) Load(value interface{}) (int, error)
- func (b *SelectBuilder) LoadStruct(value interface{}) error
- func (b *SelectBuilder) LoadStructs(value interface{}) (int, error)
- func (b *SelectBuilder) LoadValue(value interface{}) error
- func (b *SelectBuilder) LoadValues(value interface{}) (int, error)
- func (b *SelectBuilder) Offset(n uint64) *SelectBuilder
- func (b *SelectBuilder) OrderBy(col string) *SelectBuilder
- func (b *SelectBuilder) OrderDir(col string, isAsc bool) *SelectBuilder
- func (b *SelectBuilder) Paginate(page, perPage uint64) *SelectBuilder
- func (b *SelectBuilder) ReturnInt64() (int64, error)
- func (b *SelectBuilder) ReturnInt64s() ([]int64, error)
- func (b *SelectBuilder) ReturnString() (string, error)
- func (b *SelectBuilder) ReturnStrings() ([]string, error)
- func (b *SelectBuilder) ReturnUint64() (uint64, error)
- func (b *SelectBuilder) ReturnUint64s() ([]uint64, error)
- func (b *SelectBuilder) RightJoin(table, on interface{}) *SelectBuilder
- func (b *SelectBuilder) Where(query interface{}, value ...interface{}) *SelectBuilder
- type SelectStmt
- func (b *SelectStmt) As(alias string) Builder
- func (b *SelectStmt) Build(d Dialect, buf Buffer) error
- func (b *SelectStmt) Distinct() *SelectStmt
- func (b *SelectStmt) ForUpdate() *SelectStmt
- func (b *SelectStmt) From(table interface{}) *SelectStmt
- func (b *SelectStmt) FullJoin(table, on interface{}) *SelectStmt
- func (b *SelectStmt) GroupBy(col ...string) *SelectStmt
- func (b *SelectStmt) Having(query interface{}, value ...interface{}) *SelectStmt
- func (b *SelectStmt) Join(table, on interface{}) *SelectStmt
- func (b *SelectStmt) LeftJoin(table, on interface{}) *SelectStmt
- func (b *SelectStmt) Limit(n uint64) *SelectStmt
- func (b *SelectStmt) Offset(n uint64) *SelectStmt
- func (b *SelectStmt) OrderAsc(col string) *SelectStmt
- func (b *SelectStmt) OrderDesc(col string) *SelectStmt
- func (b *SelectStmt) RightJoin(table, on interface{}) *SelectStmt
- func (b *SelectStmt) Where(query interface{}, value ...interface{}) *SelectStmt
- type Session
- func (sess *Session) Begin() (*Tx, error)
- func (sess *Session) DeleteBySql(query string, value ...interface{}) *DeleteBuilder
- func (sess *Session) DeleteFrom(table string) *DeleteBuilder
- func (sess *Session) Exec(query string, args ...interface{}) (sql.Result, error)
- func (sess *Session) InsertBySql(query string, value ...interface{}) *InsertBuilder
- func (sess *Session) InsertInto(table string) *InsertBuilder
- func (sess *Session) NewSession(log EventReceiver) *Session
- func (sess *Session) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (sess *Session) Select(column ...string) *SelectBuilder
- func (sess *Session) SelectBySql(query string, value ...interface{}) *SelectBuilder
- func (sess *Session) Update(table string) *UpdateBuilder
- func (sess *Session) UpdateBySql(query string, value ...interface{}) *UpdateBuilder
- type SessionRunner
- type Tx
- func (tx *Tx) Commit() error
- func (tx *Tx) DeleteBySql(query string, value ...interface{}) *DeleteBuilder
- func (tx *Tx) DeleteFrom(table string) *DeleteBuilder
- func (tx *Tx) Exec(query string, args ...interface{}) (sql.Result, error)
- func (tx *Tx) InsertBySql(query string, value ...interface{}) *InsertBuilder
- func (tx *Tx) InsertInto(table string) *InsertBuilder
- func (tx *Tx) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (tx *Tx) Rollback() error
- func (tx *Tx) RollbackUnlessCommitted()
- func (tx *Tx) Select(column ...string) *SelectBuilder
- func (tx *Tx) SelectBySql(query string, value ...interface{}) *SelectBuilder
- func (tx *Tx) Update(table string) *UpdateBuilder
- func (tx *Tx) UpdateBySql(query string, value ...interface{}) *UpdateBuilder
- type UpdateBuilder
- func (b *UpdateBuilder) Build(d Dialect, buf Buffer) error
- func (b *UpdateBuilder) Exec() (sql.Result, error)
- func (b *UpdateBuilder) Limit(n uint64) *UpdateBuilder
- func (b *UpdateBuilder) Set(column string, value interface{}) *UpdateBuilder
- func (b *UpdateBuilder) SetMap(m map[string]interface{}) *UpdateBuilder
- func (b *UpdateBuilder) Where(query interface{}, value ...interface{}) *UpdateBuilder
- type UpdateStmt
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("dbr: not found") ErrNotSupported = errors.New("dbr: not supported") ErrTableNotSpecified = errors.New("dbr: table not specified") ErrColumnNotSpecified = errors.New("dbr: column not specified") ErrInvalidPointer = errors.New("dbr: attempt to load into an invalid pointer") ErrPlaceholderCount = errors.New("dbr: wrong placeholder count") ErrInvalidSliceLength = errors.New("dbr: length of slice is 0. length must be >= 1") ErrCantConvertToTime = errors.New("dbr: can't convert to time.Time") ErrInvalidTimestring = errors.New("dbr: invalid time string") )
package errors
var Now = nowSentinel{}
Now is a value that serializes to the current time
Functions ¶
func InterpolateForDialect ¶
InterpolateForDialect replaces placeholder in query with corresponding value in dialect
Types ¶
type Buffer ¶
type Buffer interface { WriteString(s string) (n int, err error) String() string WriteValue(v ...interface{}) (err error) Value() []interface{} }
Buffer is an interface used by Builder to store intermediate results
type Builder ¶
Builder builds sql in one dialect like MySQL/PostgreSQL e.g. XxxBuilder
func Eq ¶
Eq is `=`. When value is nil, it will be translated to `IS NULL`. When value is a slice, it will be translated to `IN`. Otherwise it will be translated to `=`.
type ConflictStmt ¶
type ConflictStmt struct {
// contains filtered or unexported fields
}
ConflictStmt is ` ON CONFLICT ...` part of InsertStmt
func (*ConflictStmt) Action ¶
func (b *ConflictStmt) Action(column string, action interface{}) *ConflictStmt
Action adds action for column which will do if conflict happens
type Connection ¶
type Connection struct { *sql.DB Dialect Dialect EventReceiver }
Connection is a connection to the database with an EventReceiver to send events, errors, and timings to
func Open ¶
func Open(driver, dsn string, log EventReceiver) (*Connection, error)
Open instantiates a Connection for a given database/sql connection and event receiver
func (*Connection) NewSession ¶
func (conn *Connection) NewSession(log EventReceiver) *Session
NewSession instantiates a Session for the Connection
func (*Connection) NewSessionContext ¶
func (conn *Connection) NewSessionContext(ctx context.Context, log EventReceiver) *Session
NewSessionContext instantiates a Session with context for the Connection
type DeleteBuilder ¶
type DeleteBuilder struct { EventReceiver Dialect Dialect *DeleteStmt LimitCount int64 // contains filtered or unexported fields }
DeleteBuilder builds "DELETE ..." stmt
func (*DeleteBuilder) Build ¶
func (b *DeleteBuilder) Build(d Dialect, buf Buffer) error
Build builds `DELETE ...` in dialect
func (*DeleteBuilder) Exec ¶
func (b *DeleteBuilder) Exec() (sql.Result, error)
Exec executes the stmt
func (*DeleteBuilder) Limit ¶
func (b *DeleteBuilder) Limit(n uint64) *DeleteBuilder
Limit adds LIMIT
func (*DeleteBuilder) Where ¶
func (b *DeleteBuilder) Where(query interface{}, value ...interface{}) *DeleteBuilder
Where adds condition to the stmt
type DeleteStmt ¶
type DeleteStmt struct { Table string WhereCond []Builder // contains filtered or unexported fields }
DeleteStmt builds `DELETE ...`
func DeleteBySql ¶
func DeleteBySql(query string, value ...interface{}) *DeleteStmt
DeleteBySql creates a DeleteStmt from raw query
func (*DeleteStmt) Build ¶
func (b *DeleteStmt) Build(d Dialect, buf Buffer) error
Build builds `DELETE ...` in dialect
func (*DeleteStmt) Where ¶
func (b *DeleteStmt) Where(query interface{}, value ...interface{}) *DeleteStmt
Where adds a where condition
type Dialect ¶
type Dialect interface { QuoteIdent(id string) string EncodeString(s string) string EncodeBool(b bool) string EncodeTime(t time.Time) string EncodeBytes(b []byte) string Placeholder(n int) string OnConflict(constraint string) string Proposed(column string) string Limit(offset, limit int64) string }
Dialect abstracts database differences
type EventReceiver ¶
type EventReceiver interface { Event(eventName string) EventKv(eventName string, kvs map[string]string) EventErr(eventName string, err error) error EventErrKv(eventName string, err error, kvs map[string]string) error Timing(eventName string, nanoseconds int64) TimingKv(eventName string, nanoseconds int64, kvs map[string]string) }
EventReceiver gets events from dbr methods for logging purposes
type I ¶
type I string
I is a identifier, which always will be quoted
type InsertBuilder ¶
type InsertBuilder struct { EventReceiver Dialect Dialect RecordID reflect.Value *InsertStmt // contains filtered or unexported fields }
InsertBuilder builds "INSERT ..." stmt
func (*InsertBuilder) Columns ¶
func (b *InsertBuilder) Columns(column ...string) *InsertBuilder
Columns adds columns
func (*InsertBuilder) Exec ¶
func (b *InsertBuilder) Exec() (sql.Result, error)
Exec executes the stmt
func (*InsertBuilder) OnConflictMap ¶
func (b *InsertBuilder) OnConflictMap(constraint string, actions map[string]interface{}) *InsertBuilder
OnConflictMap allows to add actions for constraint violation, e.g UPSERT
func (*InsertBuilder) Pair ¶
func (b *InsertBuilder) Pair(column string, value interface{}) *InsertBuilder
Pair adds a new column value pair
func (*InsertBuilder) Record ¶
func (b *InsertBuilder) Record(structValue interface{}) *InsertBuilder
Record adds a tuple for columns from a struct
func (*InsertBuilder) Values ¶
func (b *InsertBuilder) Values(value ...interface{}) *InsertBuilder
Values adds a tuple for columns
type InsertStmt ¶
type InsertStmt struct { Table string Column []string Value [][]interface{} Conflict *ConflictStmt // contains filtered or unexported fields }
InsertStmt builds `INSERT INTO ...`
func InsertBySql ¶
func InsertBySql(query string, value ...interface{}) *InsertStmt
InsertBySql creates an InsertStmt from raw query
func (*InsertStmt) Build ¶
func (b *InsertStmt) Build(d Dialect, buf Buffer) error
Build builds `INSERT INTO ...` in dialect
func (*InsertStmt) Columns ¶
func (b *InsertStmt) Columns(column ...string) *InsertStmt
Columns adds columns
func (*InsertStmt) OnConflict ¶
func (b *InsertStmt) OnConflict(constraint string) *ConflictStmt
OnConflict creates an empty OnConflict section fo insert statement , e.g UPSERT
func (*InsertStmt) OnConflictMap ¶
func (b *InsertStmt) OnConflictMap(constraint string, actions map[string]interface{}) *InsertStmt
OnConflictMap allows to add actions for constraint violation, e.g UPSERT
func (*InsertStmt) Record ¶
func (b *InsertStmt) Record(structValue interface{}) *InsertStmt
Record adds a tuple for columns from a struct
func (*InsertStmt) Values ¶
func (b *InsertStmt) Values(value ...interface{}) *InsertStmt
Values adds a tuple for columns
type NullBool ¶
NullBool is a type that can be null or a bool
func NewNullBool ¶
func NewNullBool(v interface{}) (n NullBool)
NewNullBool create a NullBool from v
func (NullBool) MarshalJSON ¶
MarshalJSON correctly serializes a NullBool to JSON
func (*NullBool) UnmarshalJSON ¶
UnmarshalJSON correctly deserializes a NullBool from JSON
type NullEventReceiver ¶
type NullEventReceiver struct{}
NullEventReceiver is a sentinel EventReceiver; use it if the caller doesn't supply one
func (*NullEventReceiver) Event ¶
func (n *NullEventReceiver) Event(eventName string)
Event receives a simple notification when various events occur
func (*NullEventReceiver) EventErr ¶
func (n *NullEventReceiver) EventErr(eventName string, err error) error
EventErr receives a notification of an error if one occurs
func (*NullEventReceiver) EventErrKv ¶
EventErrKv receives a notification of an error if one occurs along with optional key/value data
func (*NullEventReceiver) EventKv ¶
func (n *NullEventReceiver) EventKv(eventName string, kvs map[string]string)
EventKv receives a notification when various events occur along with optional key/value data
func (*NullEventReceiver) Timing ¶
func (n *NullEventReceiver) Timing(eventName string, nanoseconds int64)
Timing receives the time an event took to happen
type NullFloat64 ¶
type NullFloat64 struct {
sql.NullFloat64
}
NullFloat64 is a type that can be null or a float64
func NewNullFloat64 ¶
func NewNullFloat64(v interface{}) (n NullFloat64)
NewNullFloat64 create a NullFloat64 from v
func (NullFloat64) MarshalJSON ¶
func (n NullFloat64) MarshalJSON() ([]byte, error)
MarshalJSON correctly serializes a NullFloat64 to JSON
func (*NullFloat64) UnmarshalJSON ¶
func (n *NullFloat64) UnmarshalJSON(b []byte) error
UnmarshalJSON correctly deserializes a NullFloat64 from JSON
type NullInt64 ¶
NullInt64 is a type that can be null or an int
func NewNullInt64 ¶
func NewNullInt64(v interface{}) (n NullInt64)
NewNullInt64 create a NullInt64 from v
func (NullInt64) MarshalJSON ¶
MarshalJSON correctly serializes a NullInt64 to JSON
func (*NullInt64) UnmarshalJSON ¶
UnmarshalJSON correctly deserializes a NullInt64 from JSON
type NullString ¶
type NullString struct {
sql.NullString
}
NullString is a type that can be null or a string
func NewNullString ¶
func NewNullString(v interface{}) (n NullString)
NewNullString create a NullString from v
func (NullString) MarshalJSON ¶
func (n NullString) MarshalJSON() ([]byte, error)
MarshalJSON correctly serializes a NullString to JSON
func (*NullString) UnmarshalJSON ¶
func (n *NullString) UnmarshalJSON(b []byte) error
UnmarshalJSON correctly deserializes a NullString from JSON
type NullTime ¶
NullTime is a type that can be null or a time
func NewNullTime ¶
func NewNullTime(v interface{}) (n NullTime)
NewNullTime create a NullTime from v
func (NullTime) MarshalJSON ¶
MarshalJSON correctly serializes a NullTime to JSON
func (*NullTime) Scan ¶
Scan implements the Scanner interface. The value type must be time.Time or string / []byte (formatted time-string), otherwise Scan fails.
func (*NullTime) UnmarshalJSON ¶
UnmarshalJSON correctly deserializes a NullTime from JSON
type SelectBuilder ¶
type SelectBuilder struct { EventReceiver Dialect Dialect *SelectStmt // contains filtered or unexported fields }
SelectBuilder build "SELECT" stmt
func (*SelectBuilder) Distinct ¶
func (b *SelectBuilder) Distinct() *SelectBuilder
Distinct adds `DISTINCT`
func (*SelectBuilder) ForUpdate ¶
func (b *SelectBuilder) ForUpdate() *SelectBuilder
ForUpdate adds lock via FOR UPDATE
func (*SelectBuilder) From ¶
func (b *SelectBuilder) From(table interface{}) *SelectBuilder
From specifies table
func (*SelectBuilder) FullJoin ¶
func (b *SelectBuilder) FullJoin(table, on interface{}) *SelectBuilder
FullJoin joins table on condition via FULL JOIN
func (*SelectBuilder) GroupBy ¶
func (b *SelectBuilder) GroupBy(col ...string) *SelectBuilder
GroupBy specifies columns for grouping
func (*SelectBuilder) Having ¶
func (b *SelectBuilder) Having(query interface{}, value ...interface{}) *SelectBuilder
Having adds a having condition
func (*SelectBuilder) Join ¶
func (b *SelectBuilder) Join(table, on interface{}) *SelectBuilder
Join joins table on condition
func (*SelectBuilder) LeftJoin ¶
func (b *SelectBuilder) LeftJoin(table, on interface{}) *SelectBuilder
LeftJoin joins table on condition via LEFT JOIN
func (*SelectBuilder) Limit ¶
func (b *SelectBuilder) Limit(n uint64) *SelectBuilder
Limit adds LIMIT
func (*SelectBuilder) Load ¶
func (b *SelectBuilder) Load(value interface{}) (int, error)
Load loads any value from query result
func (*SelectBuilder) LoadStruct ¶
func (b *SelectBuilder) LoadStruct(value interface{}) error
LoadStruct loads struct from query result, returns ErrNotFound if there is no result
func (*SelectBuilder) LoadStructs ¶
func (b *SelectBuilder) LoadStructs(value interface{}) (int, error)
LoadStructs loads structures from query result
func (*SelectBuilder) LoadValue ¶
func (b *SelectBuilder) LoadValue(value interface{}) error
LoadValue loads any value from query result, returns ErrNotFound if there is no result
func (*SelectBuilder) LoadValues ¶
func (b *SelectBuilder) LoadValues(value interface{}) (int, error)
LoadValues loads any values from query result
func (*SelectBuilder) Offset ¶
func (b *SelectBuilder) Offset(n uint64) *SelectBuilder
Offset adds OFFSET, works only if LIMIT is set
func (*SelectBuilder) OrderBy ¶
func (b *SelectBuilder) OrderBy(col string) *SelectBuilder
OrderBy specifies column for ordering
func (*SelectBuilder) OrderDir ¶
func (b *SelectBuilder) OrderDir(col string, isAsc bool) *SelectBuilder
OrderDir specifies columns for ordering in direction
func (*SelectBuilder) Paginate ¶
func (b *SelectBuilder) Paginate(page, perPage uint64) *SelectBuilder
Paginate adds LIMIT and OFFSET
func (*SelectBuilder) ReturnInt64 ¶
func (b *SelectBuilder) ReturnInt64() (int64, error)
ReturnInt64 executes the SelectStmt and returns the value as an int64
func (*SelectBuilder) ReturnInt64s ¶
func (b *SelectBuilder) ReturnInt64s() ([]int64, error)
ReturnInt64s executes the SelectStmt and returns the value as a slice of int64s
func (*SelectBuilder) ReturnString ¶
func (b *SelectBuilder) ReturnString() (string, error)
ReturnString executes the SelectStmt and returns the value as a string
func (*SelectBuilder) ReturnStrings ¶
func (b *SelectBuilder) ReturnStrings() ([]string, error)
ReturnStrings executes the SelectStmt and returns the value as a slice of strings
func (*SelectBuilder) ReturnUint64 ¶
func (b *SelectBuilder) ReturnUint64() (uint64, error)
ReturnUint64 executes the SelectStmt and returns the value as an uint64
func (*SelectBuilder) ReturnUint64s ¶
func (b *SelectBuilder) ReturnUint64s() ([]uint64, error)
ReturnUint64s executes the SelectStmt and returns the value as a slice of uint64s
func (*SelectBuilder) RightJoin ¶
func (b *SelectBuilder) RightJoin(table, on interface{}) *SelectBuilder
RightJoin joins table on condition via RIGHT JOIN
func (*SelectBuilder) Where ¶
func (b *SelectBuilder) Where(query interface{}, value ...interface{}) *SelectBuilder
Where adds a where condition
type SelectStmt ¶
type SelectStmt struct { IsDistinct bool Column []interface{} Table interface{} JoinTable []Builder WhereCond []Builder Group []Builder HavingCond []Builder Order []Builder LimitCount int64 OffsetCount int64 IsForUpdate bool // contains filtered or unexported fields }
SelectStmt builds `SELECT ...`
func SelectBySql ¶
func SelectBySql(query string, value ...interface{}) *SelectStmt
SelectBySql creates a SelectStmt from raw query
func (*SelectStmt) As ¶
func (b *SelectStmt) As(alias string) Builder
As creates alias for select statement
func (*SelectStmt) Build ¶
func (b *SelectStmt) Build(d Dialect, buf Buffer) error
Build builds `SELECT ...` in dialect
func (*SelectStmt) ForUpdate ¶
func (b *SelectStmt) ForUpdate() *SelectStmt
ForUpdate adds `FOR UPDATE`
func (*SelectStmt) From ¶
func (b *SelectStmt) From(table interface{}) *SelectStmt
From specifies table
func (*SelectStmt) FullJoin ¶
func (b *SelectStmt) FullJoin(table, on interface{}) *SelectStmt
FullJoin joins table on condition via FULL JOIN
func (*SelectStmt) GroupBy ¶
func (b *SelectStmt) GroupBy(col ...string) *SelectStmt
GroupBy specifies columns for grouping
func (*SelectStmt) Having ¶
func (b *SelectStmt) Having(query interface{}, value ...interface{}) *SelectStmt
Having adds a having condition
func (*SelectStmt) Join ¶
func (b *SelectStmt) Join(table, on interface{}) *SelectStmt
Join joins table on condition
func (*SelectStmt) LeftJoin ¶
func (b *SelectStmt) LeftJoin(table, on interface{}) *SelectStmt
LeftJoin joins table on condition via LEFT JOIN
func (*SelectStmt) Offset ¶
func (b *SelectStmt) Offset(n uint64) *SelectStmt
Offset adds OFFSET, works only if LIMIT is set
func (*SelectStmt) OrderAsc ¶
func (b *SelectStmt) OrderAsc(col string) *SelectStmt
OrderAsc specifies columns for ordering in asc direction
func (*SelectStmt) OrderDesc ¶
func (b *SelectStmt) OrderDesc(col string) *SelectStmt
OrderDesc specifies columns for ordering in desc direction
func (*SelectStmt) RightJoin ¶
func (b *SelectStmt) RightJoin(table, on interface{}) *SelectStmt
RightJoin joins table on condition via RIGHT JOIN
func (*SelectStmt) Where ¶
func (b *SelectStmt) Where(query interface{}, value ...interface{}) *SelectStmt
Where adds a where condition
type Session ¶
type Session struct { *Connection EventReceiver // contains filtered or unexported fields }
Session represents a business unit of execution for some connection
func (*Session) DeleteBySql ¶
func (sess *Session) DeleteBySql(query string, value ...interface{}) *DeleteBuilder
DeleteBySql creates a DeleteBuilder from raw query
func (*Session) DeleteFrom ¶
func (sess *Session) DeleteFrom(table string) *DeleteBuilder
DeleteFrom creates a DeleteBuilder
func (*Session) Exec ¶
Exec executes a query without returning any rows. The args are for any placeholder parameters in the query.
func (*Session) InsertBySql ¶
func (sess *Session) InsertBySql(query string, value ...interface{}) *InsertBuilder
InsertBySql creates a InsertBuilder from raw query
func (*Session) InsertInto ¶
func (sess *Session) InsertInto(table string) *InsertBuilder
InsertInto creates a InsertBuilder
func (*Session) NewSession ¶
func (sess *Session) NewSession(log EventReceiver) *Session
NewSession forks current session
func (*Session) Query ¶
Query executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (*Session) Select ¶
func (sess *Session) Select(column ...string) *SelectBuilder
Select creates a SelectBuilder
func (*Session) SelectBySql ¶
func (sess *Session) SelectBySql(query string, value ...interface{}) *SelectBuilder
SelectBySql creates a SelectBuilder from raw query
func (*Session) Update ¶
func (sess *Session) Update(table string) *UpdateBuilder
Update creates a UpdateBuilder
func (*Session) UpdateBySql ¶
func (sess *Session) UpdateBySql(query string, value ...interface{}) *UpdateBuilder
UpdateBySql creates a UpdateBuilder from raw query
type SessionRunner ¶
type SessionRunner interface { Select(column ...string) *SelectBuilder SelectBySql(query string, value ...interface{}) *SelectBuilder InsertInto(table string) *InsertBuilder InsertBySql(query string, value ...interface{}) *InsertBuilder Update(table string) *UpdateBuilder UpdateBySql(query string, value ...interface{}) *UpdateBuilder DeleteFrom(table string) *DeleteBuilder DeleteBySql(query string, value ...interface{}) *DeleteBuilder }
SessionRunner can do anything that a Session can except start a transaction.
type Tx ¶
type Tx struct { EventReceiver Dialect Dialect *sql.Tx // contains filtered or unexported fields }
Tx is a transaction for the given Session
func (*Tx) DeleteBySql ¶
func (tx *Tx) DeleteBySql(query string, value ...interface{}) *DeleteBuilder
DeleteBySql creates a DeleteBuilder from raw query
func (*Tx) DeleteFrom ¶
func (tx *Tx) DeleteFrom(table string) *DeleteBuilder
DeleteFrom creates a DeleteBuilder
func (*Tx) Exec ¶
Exec executes a query without returning any rows. The args are for any placeholder parameters in the query.
func (*Tx) InsertBySql ¶
func (tx *Tx) InsertBySql(query string, value ...interface{}) *InsertBuilder
InsertBySql creates a InsertBuilder from raw query
func (*Tx) InsertInto ¶
func (tx *Tx) InsertInto(table string) *InsertBuilder
InsertInto creates a InsertBuilder
func (*Tx) Query ¶
Query executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (*Tx) RollbackUnlessCommitted ¶
func (tx *Tx) RollbackUnlessCommitted()
RollbackUnlessCommitted rollsback the transaction unless it has already been committed or rolled back. Useful to defer tx.RollbackUnlessCommitted() -- so you don't have to handle N failure cases Keep in mind the only way to detect an error on the rollback is via the event log.
func (*Tx) Select ¶
func (tx *Tx) Select(column ...string) *SelectBuilder
Select creates a SelectBuilder
func (*Tx) SelectBySql ¶
func (tx *Tx) SelectBySql(query string, value ...interface{}) *SelectBuilder
SelectBySql creates a SelectBuilder from raw query
func (*Tx) Update ¶
func (tx *Tx) Update(table string) *UpdateBuilder
Update creates a UpdateBuilder
func (*Tx) UpdateBySql ¶
func (tx *Tx) UpdateBySql(query string, value ...interface{}) *UpdateBuilder
UpdateBySql creates a UpdateBuilder from raw query
type UpdateBuilder ¶
type UpdateBuilder struct { EventReceiver Dialect Dialect *UpdateStmt LimitCount int64 // contains filtered or unexported fields }
UpdateBuilder builds `UPDATE ...`
func (*UpdateBuilder) Build ¶
func (b *UpdateBuilder) Build(d Dialect, buf Buffer) error
Build builds `UPDATE ...` in dialect
func (*UpdateBuilder) Exec ¶
func (b *UpdateBuilder) Exec() (sql.Result, error)
Exec executes the stmt
func (*UpdateBuilder) Limit ¶
func (b *UpdateBuilder) Limit(n uint64) *UpdateBuilder
Limit adds LIMIT
func (*UpdateBuilder) Set ¶
func (b *UpdateBuilder) Set(column string, value interface{}) *UpdateBuilder
Set adds "SET column=value"
func (*UpdateBuilder) SetMap ¶
func (b *UpdateBuilder) SetMap(m map[string]interface{}) *UpdateBuilder
SetMap adds "SET column=value" for each key value pair in m
func (*UpdateBuilder) Where ¶
func (b *UpdateBuilder) Where(query interface{}, value ...interface{}) *UpdateBuilder
Where adds condition to the stmt
type UpdateStmt ¶
type UpdateStmt struct { Table string Value map[string]interface{} WhereCond []Builder // contains filtered or unexported fields }
UpdateStmt builds `UPDATE ...`
func UpdateBySql ¶
func UpdateBySql(query string, value ...interface{}) *UpdateStmt
UpdateBySql creates an UpdateStmt with raw query
func (*UpdateStmt) Build ¶
func (b *UpdateStmt) Build(d Dialect, buf Buffer) error
Build builds `UPDATE ...` in dialect
func (*UpdateStmt) Set ¶
func (b *UpdateStmt) Set(column string, value interface{}) *UpdateStmt
Set specifies a key-value pair
func (*UpdateStmt) SetMap ¶
func (b *UpdateStmt) SetMap(m map[string]interface{}) *UpdateStmt
SetMap specifies a list of key-value pair
func (*UpdateStmt) Where ¶
func (b *UpdateStmt) Where(query interface{}, value ...interface{}) *UpdateStmt
Where adds a where condition
Source Files
¶
- buffer.go
- builder.go
- condition.go
- dbr.go
- dbr_go18.go
- delete.go
- delete_builder.go
- dialect.go
- errors.go
- event.go
- expr.go
- ident.go
- insert.go
- insert_builder.go
- interpolate.go
- join.go
- load.go
- now.go
- order.go
- select.go
- select_builder.go
- select_return.go
- transaction.go
- types.go
- union.go
- update.go
- update_builder.go
- util.go