sql

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2018 License: Apache-2.0 Imports: 24 Imported by: 10

Documentation

Index

Constants

View Source
const (
	OrCondition  = "__or__"
	AndCondition = "__and__"
)

Variables

This section is empty.

Functions

func AddFilterToQuery

func AddFilterToQuery(s *schema.Schema, q sq.SelectBuilder, filter map[string]interface{}, join bool) (sq.SelectBuilder, error)

func MakeColumns

func MakeColumns(s *schema.Schema, tableName string, fields []string, join bool) []string

MakeColumns generates an array that has Gohan style column names

Types

type CachedState

type CachedState struct {
	// contains filtered or unexported fields
}

type CachedTransaction

type CachedTransaction struct {
	TxInterface
	QueryCache map[string]CachedState
}

func (*CachedTransaction) ClearCache

func (tx *CachedTransaction) ClearCache()

func (*CachedTransaction) Create

func (tx *CachedTransaction) Create(resource *schema.Resource) error

func (*CachedTransaction) CreateContext

func (tx *CachedTransaction) CreateContext(ctx context.Context, resource *schema.Resource) error

func (*CachedTransaction) Delete

func (tx *CachedTransaction) Delete(s *schema.Schema, resourceID interface{}) error

func (*CachedTransaction) DeleteContext

func (tx *CachedTransaction) DeleteContext(ctx context.Context, s *schema.Schema, resourceID interface{}) error

func (*CachedTransaction) Fetch

func (*CachedTransaction) FetchContext

func (tx *CachedTransaction) FetchContext(ctx context.Context, s *schema.Schema, filter transaction.Filter, options *transaction.ViewOptions) (*schema.Resource, error)

func (*CachedTransaction) List

func (tx *CachedTransaction) List(s *schema.Schema, filter transaction.Filter, options *transaction.ViewOptions, pg *pagination.Paginator) (list []*schema.Resource, total uint64, err error)

func (*CachedTransaction) ListContext

func (tx *CachedTransaction) ListContext(ctx context.Context, s *schema.Schema, filter transaction.Filter, options *transaction.ViewOptions, pg *pagination.Paginator) (list []*schema.Resource, total uint64, err error)

List resources in the db

func (*CachedTransaction) LockFetch

func (tx *CachedTransaction) LockFetch(s *schema.Schema, filter transaction.Filter, lockPolicy schema.LockPolicy, options *transaction.ViewOptions) (*schema.Resource, error)

func (*CachedTransaction) LockFetchContext

func (tx *CachedTransaction) LockFetchContext(ctx context.Context, s *schema.Schema, filter transaction.Filter, lockPolicy schema.LockPolicy, options *transaction.ViewOptions) (*schema.Resource, error)

func (*CachedTransaction) LockList

func (tx *CachedTransaction) LockList(s *schema.Schema, filter transaction.Filter, options *transaction.ViewOptions, pg *pagination.Paginator, lockPolicy schema.LockPolicy) (list []*schema.Resource, total uint64, err error)

func (*CachedTransaction) LockListContext

func (tx *CachedTransaction) LockListContext(ctx context.Context, s *schema.Schema, filter transaction.Filter, options *transaction.ViewOptions, pg *pagination.Paginator, lockPolicy schema.LockPolicy) (list []*schema.Resource, total uint64, err error)

func (*CachedTransaction) Query

func (tx *CachedTransaction) Query(s *schema.Schema, query string, arguments []interface{}) (list []*schema.Resource, err error)

func (*CachedTransaction) QueryContext

func (tx *CachedTransaction) QueryContext(ctx context.Context, s *schema.Schema, query string, arguments []interface{}) (list []*schema.Resource, err error)

func (*CachedTransaction) StateUpdate

func (tx *CachedTransaction) StateUpdate(resource *schema.Resource, state *transaction.ResourceState) error

func (*CachedTransaction) StateUpdateContext

func (tx *CachedTransaction) StateUpdateContext(ctx context.Context, resource *schema.Resource, state *transaction.ResourceState) error

func (*CachedTransaction) Update

func (tx *CachedTransaction) Update(resource *schema.Resource) error

func (*CachedTransaction) UpdateContext

func (tx *CachedTransaction) UpdateContext(ctx context.Context, resource *schema.Resource) error

type DB

type DB struct {
	DB *sqlx.DB
	// contains filtered or unexported fields
}

DB is sql implementation of DB

func NewDB

func NewDB(options options.Options) *DB

NewDB constructor

func (*DB) AlterTableDef

func (db *DB) AlterTableDef(s *schema.Schema, cascade bool) (string, []string, error)

AlterTableDef generates alter table sql

func (*DB) Begin

func (db *DB) Begin() (tx transaction.Transaction, err error)

Begin starts new transaction

func (*DB) BeginTx

func (db *DB) BeginTx(ctx context.Context, options *transaction.TxOptions) (tx transaction.Transaction, err error)

BeginTx starts new transaction with given transaction options

func (*DB) Close

func (db *DB) Close()

Close closes db connection

func (*DB) Connect

func (db *DB) Connect(sqlType, conn string, maxOpenConn int) (err error)

Connect connects to the db

func (*DB) DropTable

func (db *DB) DropTable(s *schema.Schema) error

DropTable drop table definition

func (*DB) GenTableDef

func (db *DB) GenTableDef(s *schema.Schema, cascade bool) (string, []string)

GenTableDef generates create table sql

func (*DB) Options

func (db *DB) Options() options.Options

Options returns DB options

func (*DB) RegisterTable

func (db *DB) RegisterTable(s *schema.Schema, cascade, migrate bool) error

RegisterTable creates table in the db

func (*DB) SetMaxOpenConns

func (db *DB) SetMaxOpenConns(maxIdleConns int)

SetMaxOpenConns limit maximum connections

type Transaction

type Transaction struct {
	// contains filtered or unexported fields
}

Transaction is sql implementation of Transaction

func (*Transaction) Close

func (tx *Transaction) Close() error

Close closes connection

func (*Transaction) Closed

func (tx *Transaction) Closed() bool

Closed returns whether the transaction is closed

func (*Transaction) Commit

func (tx *Transaction) Commit() error

Commit commits transaction

func (*Transaction) CountContext

func (tx *Transaction) CountContext(ctx context.Context, s *schema.Schema, filter transaction.Filter) (res uint64, err error)

CountContext count all matching resources in the db

func (*Transaction) Create

func (tx *Transaction) Create(resource *schema.Resource) error

func (*Transaction) CreateContext

func (tx *Transaction) CreateContext(ctx context.Context, resource *schema.Resource) error

Create create resource in the db

func (*Transaction) Delete

func (tx *Transaction) Delete(s *schema.Schema, resourceID interface{}) error

func (*Transaction) DeleteContext

func (tx *Transaction) DeleteContext(ctx context.Context, s *schema.Schema, resourceID interface{}) error

Delete delete resource from db

func (*Transaction) Exec

func (tx *Transaction) Exec(sql string, args ...interface{}) error

func (*Transaction) ExecContext

func (tx *Transaction) ExecContext(ctx context.Context, sql string, args ...interface{}) error

Exec executes sql in transaction

func (*Transaction) Fetch

func (tx *Transaction) Fetch(s *schema.Schema, filter transaction.Filter, options *transaction.ViewOptions) (*schema.Resource, error)

func (*Transaction) FetchContext

func (tx *Transaction) FetchContext(ctx context.Context, s *schema.Schema, filter transaction.Filter, options *transaction.ViewOptions) (*schema.Resource, error)

Fetch resources by ID in the db

func (*Transaction) GetIsolationLevel

func (tx *Transaction) GetIsolationLevel() transaction.Type

GetIsolationLevel returns tx isolation level

func (*Transaction) List

func (tx *Transaction) List(s *schema.Schema, filter transaction.Filter, options *transaction.ViewOptions, pg *pagination.Paginator) (list []*schema.Resource, total uint64, err error)

func (*Transaction) ListContext

func (tx *Transaction) ListContext(ctx context.Context, s *schema.Schema, filter transaction.Filter, options *transaction.ViewOptions, pg *pagination.Paginator) (list []*schema.Resource, total uint64, err error)

List resources in the db

func (*Transaction) LockFetch

func (tx *Transaction) LockFetch(s *schema.Schema, filter transaction.Filter, lockPolicy schema.LockPolicy, options *transaction.ViewOptions) (*schema.Resource, error)

func (*Transaction) LockFetchContext

func (tx *Transaction) LockFetchContext(ctx context.Context, s *schema.Schema, filter transaction.Filter, lockPolicy schema.LockPolicy, options *transaction.ViewOptions) (*schema.Resource, error)

LockFetch fetches & locks a resource

func (*Transaction) LockList

func (tx *Transaction) LockList(s *schema.Schema, filter transaction.Filter, options *transaction.ViewOptions, pg *pagination.Paginator, lockPolicy schema.LockPolicy) (list []*schema.Resource, total uint64, err error)

func (*Transaction) LockListContext

func (tx *Transaction) LockListContext(ctx context.Context, s *schema.Schema, filter transaction.Filter, options *transaction.ViewOptions, pg *pagination.Paginator, lockPolicy schema.LockPolicy) (list []*schema.Resource, total uint64, err error)

LockList locks resources in the db

func (*Transaction) Query

func (tx *Transaction) Query(s *schema.Schema, query string, arguments []interface{}) (list []*schema.Resource, err error)

func (*Transaction) QueryContext

func (tx *Transaction) QueryContext(ctx context.Context, s *schema.Schema, query string, arguments []interface{}) (list []*schema.Resource, err error)

Query with raw sql string

func (*Transaction) RawTransaction

func (tx *Transaction) RawTransaction() *sqlx.Tx

RawTransaction returns raw transaction

func (*Transaction) StateFetch

func (tx *Transaction) StateFetch(s *schema.Schema, filter transaction.Filter) (state transaction.ResourceState, err error)

func (*Transaction) StateFetchContext

func (tx *Transaction) StateFetchContext(ctx context.Context, s *schema.Schema, filter transaction.Filter) (state transaction.ResourceState, err error)

StateFetch fetches the state of the specified resource

func (*Transaction) StateUpdate

func (tx *Transaction) StateUpdate(resource *schema.Resource, state *transaction.ResourceState) error

func (*Transaction) StateUpdateContext

func (tx *Transaction) StateUpdateContext(ctx context.Context, resource *schema.Resource, state *transaction.ResourceState) error

StateUpdate update resource state

func (*Transaction) Update

func (tx *Transaction) Update(resource *schema.Resource) error

func (*Transaction) UpdateContext

func (tx *Transaction) UpdateContext(ctx context.Context, resource *schema.Resource) error

Update update resource in the db

type TxInterface

type TxInterface transaction.Transaction

func MakeCachedTransaction

func MakeCachedTransaction(transx TxInterface) TxInterface

Jump to

Keyboard shortcuts

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