Documentation
¶
Index ¶
- Constants
- func GetErrorCode(err error) int
- type CodedError
- type EqPredicate
- type LikePredicate
- type NotEqPredicate
- type Paginator
- func (p *Paginator) Apply(ctx context.Context, list interface{}) (err error)
- func (p *Paginator) CurrentPage() int
- func (p *Paginator) Init(ctx context.Context) (err error)
- func (p *Paginator) ItemCount() int
- func (p *Paginator) Next() bool
- func (p *Paginator) PageCount() int
- func (p *Paginator) PerPageCount() int
- func (p *Paginator) Prev() bool
- type Table
- func (sql Table) BeginTx() (cm.Transaction, error)
- func (sql *Table) C() cm.Collection
- func (sql *Table) Delete(ctx context.Context) (err error)
- func (sql Table) Edit(op cm.Operation) cm.Collection
- func (sql *Table) ExecRaw(ctx context.Context, query string) error
- func (sql Table) Filter(pred cm.Predicate) cm.Collection
- func (sql *Table) Init(iface interface{}) error
- func (sql *Table) Insert(ctx context.Context, i interface{}) (err error)
- func (sql *Table) List(ctx context.Context, list interface{}) (err error)
- func (sql *Table) Page(ctx context.Context, perPageCount int) (cm.Paginator, error)
- func (sql *Table) Single(ctx context.Context, single interface{}) (err error)
- func (sql *Table) Update(ctx context.Context) (err error)
- type Transaction
- type UpdateOperation
- type ValueColumn
- func (c ValueColumn) AutoIncrement() ValueColumn
- func (c ValueColumn) Build() string
- func (c ValueColumn) Eq(i interface{}) cm.Predicate
- func (c ValueColumn) FromFunction(fn func() interface{}) ValueColumn
- func (c ValueColumn) Like(caseSensitive bool, i interface{}) cm.Predicate
- func (c ValueColumn) Name() string
- func (c ValueColumn) NotEq(i interface{}) cm.Predicate
- func (c ValueColumn) NotNull() ValueColumn
- func (c ValueColumn) PrimaryKey() ValueColumn
- func (c ValueColumn) Set(i interface{}) cm.Operation
- func (c ValueColumn) Type() string
Constants ¶
const ( CodeNotAvailable int = 0 TableAlreadyExists int = 1 )
Error code constants
Variables ¶
This section is empty.
Functions ¶
func GetErrorCode ¶
GetErrorCode extracts out the error code for the given object
Types ¶
type CodedError ¶
type CodedError interface {
Code() int
}
CodedError is an error with an attached code
type EqPredicate ¶
type EqPredicate struct {
Column cm.ValueColumn
Value interface{}
}
EqPredicate is the predicate which wraps a SQL equal comparison
func (*EqPredicate) Apply ¶
func (pred *EqPredicate) Apply(c cm.Collection) error
Apply modifies the collection to add the equal operation
type LikePredicate ¶
type LikePredicate struct {
Column cm.ValueColumn
Value interface{}
CaseSensitive bool
}
LikePredicate is the predicate which wraps a SQL like comparison
func (*LikePredicate) Apply ¶
func (pred *LikePredicate) Apply(c cm.Collection) error
Apply modifies the collection to add the like operation
type NotEqPredicate ¶
type NotEqPredicate struct {
Column cm.ValueColumn
Value interface{}
}
NotEqPredicate is the predicate which wraps a SQL not equal comparison
func (*NotEqPredicate) Apply ¶
func (pred *NotEqPredicate) Apply(c cm.Collection) error
Apply modifies the collection to add the not equal operation
type Paginator ¶
type Paginator struct {
// contains filtered or unexported fields
}
Paginator is the SQL implementation of the cm.Paginator
func (*Paginator) Apply ¶
Apply runs the paginating query against the database, inserting it into the given list
func (*Paginator) CurrentPage ¶
CurrentPage returns the current page of the pagintor
func (*Paginator) Next ¶
Next increases the current page by one, unless the current page is the last page.
func (*Paginator) PerPageCount ¶
PerPageCount returns the per-page count of the pagintor
type Table ¶
type Table struct {
Name string
// contains filtered or unexported fields
}
Table defines the Collection that interacts with a sqlx.DB connection
func (Table) BeginTx ¶
func (sql Table) BeginTx() (cm.Transaction, error)
BeginTx begins a transaction
func (*Table) C ¶
func (sql *Table) C() cm.Collection
C returns the underlying implementation of the collection, which is just ourselves.
func (*Table) Delete ¶
Delete resolves the collection using the filters and deletes the filtered elements.
func (Table) Edit ¶
func (sql Table) Edit(op cm.Operation) cm.Collection
Edit updates the collection for the given operation
func (Table) Filter ¶
func (sql Table) Filter(pred cm.Predicate) cm.Collection
Filter filters the collection on the given predicate
func (*Table) Init ¶
Init initializes the sql table by performing reflection operations on the interface
func (*Table) List ¶
List resolves the collection and applies the results to the given slice pointer
func (*Table) Page ¶
Page returns a pagination object which is responsible for resolving the collection
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
Transaction is the sql-specific transaction struct
func (*Transaction) Active ¶
func (t *Transaction) Active() bool
Active returns true if the transaction is active
func (*Transaction) Rollback ¶
func (t *Transaction) Rollback() error
Rollback rolls the transaction back
type UpdateOperation ¶
type UpdateOperation struct {
Column cm.ValueColumn
Value interface{}
}
UpdateOperation is the predicate which wraps a SQL update operation
func (*UpdateOperation) Apply ¶
func (op *UpdateOperation) Apply(c cm.Collection) error
Apply modifies the collection to add the equal operation
type ValueColumn ¶
type ValueColumn struct {
// contains filtered or unexported fields
}
ValueColumn is a value column that contains metadata about the database column
func Column ¶
func Column(name string, ctype string) ValueColumn
Column returns a column object given the name and type
func Integer ¶
func Integer(name string, size int) ValueColumn
Integer returns an integer given the size
func Varchar ¶
func Varchar(name string, size int) ValueColumn
Varchar returns a column object given the name and size of string
func (ValueColumn) AutoIncrement ¶
func (c ValueColumn) AutoIncrement() ValueColumn
AutoIncrement returns the value column definition with autoincrement added
func (ValueColumn) Build ¶
func (c ValueColumn) Build() string
Build builds the SQL column expression
func (ValueColumn) Eq ¶
func (c ValueColumn) Eq(i interface{}) cm.Predicate
Eq creates an equal predicate used for filtering
func (ValueColumn) FromFunction ¶
func (c ValueColumn) FromFunction(fn func() interface{}) ValueColumn
FromFunction returns a value column that is populated, on insert, from the given function
func (ValueColumn) Like ¶
func (c ValueColumn) Like(caseSensitive bool, i interface{}) cm.Predicate
Like creates a like predicate used for filtering
func (ValueColumn) Name ¶
func (c ValueColumn) Name() string
Name returns the name of the SQL value column
func (ValueColumn) NotEq ¶
func (c ValueColumn) NotEq(i interface{}) cm.Predicate
NotEq creates a not equal predicate used for filtering
func (ValueColumn) NotNull ¶
func (c ValueColumn) NotNull() ValueColumn
NotNull returns a column object that does not allow null values
func (ValueColumn) PrimaryKey ¶
func (c ValueColumn) PrimaryKey() ValueColumn
PrimaryKey returns a value column that is a primary key
func (ValueColumn) Set ¶
func (c ValueColumn) Set(i interface{}) cm.Operation
Set creates a modify operation
func (ValueColumn) Type ¶
func (c ValueColumn) Type() string
Type returns the type of the SQL value column