sql

package
v0.0.0-...-d631984 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2019 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	CodeNotAvailable   int = 0
	TableAlreadyExists int = 1
)

Error code constants

Variables

This section is empty.

Functions

func GetErrorCode

func GetErrorCode(err error) int

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

func (p *Paginator) Apply(ctx context.Context, list interface{}) (err error)

Apply runs the paginating query against the database, inserting it into the given list

func (*Paginator) CurrentPage

func (p *Paginator) CurrentPage() int

CurrentPage returns the current page of the pagintor

func (*Paginator) Init

func (p *Paginator) Init(ctx context.Context) (err error)

Init initializes the paginator by running the initial count query

func (*Paginator) ItemCount

func (p *Paginator) ItemCount() int

ItemCount returns the totel item count of the paginator

func (*Paginator) Next

func (p *Paginator) Next() bool

Next increases the current page by one, unless the current page is the last page.

func (*Paginator) PageCount

func (p *Paginator) PageCount() int

PageCount returns the number of pages of this paginator

func (*Paginator) PerPageCount

func (p *Paginator) PerPageCount() int

PerPageCount returns the per-page count of the pagintor

func (*Paginator) Prev

func (p *Paginator) Prev() bool

Prev decreases the current page by one, unless the current page is 0

type Table

type Table struct {
	Name string
	// contains filtered or unexported fields
}

Table defines the Collection that interacts with a sqlx.DB connection

func New

func New(db *sqlx.DB, table string) *Table

New defines a new Table based on the database connection and table name.

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

func (sql *Table) Delete(ctx context.Context) (err error)

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) ExecRaw

func (sql *Table) ExecRaw(ctx context.Context, query string) error

ExecRaw executes a raw statement against the collection

func (Table) Filter

func (sql Table) Filter(pred cm.Predicate) cm.Collection

Filter filters the collection on the given predicate

func (*Table) Init

func (sql *Table) Init(iface interface{}) error

Init initializes the sql table by performing reflection operations on the interface

func (*Table) Insert

func (sql *Table) Insert(ctx context.Context, i interface{}) (err error)

Insert inserts the given object

func (*Table) List

func (sql *Table) List(ctx context.Context, list interface{}) (err error)

List resolves the collection and applies the results to the given slice pointer

func (*Table) Page

func (sql *Table) Page(ctx context.Context, perPageCount int) (cm.Paginator, error)

Page returns a pagination object which is responsible for resolving the collection

func (*Table) Single

func (sql *Table) Single(ctx context.Context, single interface{}) (err error)

Single resolves the collection and applies the results to the given slice pointer.

func (*Table) Update

func (sql *Table) Update(ctx context.Context) (err error)

Update resolves the collection using the filters and updates the filtered elements using the operations

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) Commit

func (t *Transaction) Commit() error

Commit commits the transaction

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

Jump to

Keyboard shortcuts

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