sql

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package sql is general sql adapter that wraps database/sql.

Index

Constants

This section is empty.

Variables

View Source
var UnescapeCharacter byte = '^'

UnescapeCharacter disable field escaping when it starts with this character.

Functions

func Scan

func Scan(value interface{}, rows Rows) (int64, error)

Scan rows into interface

Types

type Adapter

type Adapter struct {
	Config *Config
	DB     *sql.DB
	Tx     *sql.Tx
	// contains filtered or unexported fields
}

Adapter definition for mysql database.

func New

func New(config *Config) *Adapter

New initialize adapter without db.

func (*Adapter) Aggregate

func (adapter *Adapter) Aggregate(query grimoire.Query, doc interface{}, loggers ...grimoire.Logger) error

Aggregate record using given query.

func (*Adapter) All

func (adapter *Adapter) All(query grimoire.Query, doc interface{}, loggers ...grimoire.Logger) (int, error)

All retrieves all record that match the query.

func (*Adapter) Begin

func (adapter *Adapter) Begin() (grimoire.Adapter, error)

Begin begins a new transaction.

func (*Adapter) Close

func (adapter *Adapter) Close() error

Close mysql connection.

func (*Adapter) Commit

func (adapter *Adapter) Commit() error

Commit commits current transaction.

func (*Adapter) Delete

func (adapter *Adapter) Delete(query grimoire.Query, loggers ...grimoire.Logger) error

Delete deletes all results that match the query.

func (*Adapter) Exec

func (adapter *Adapter) Exec(statement string, args []interface{}, loggers ...grimoire.Logger) (int64, int64, error)

Exec performs exec operation.

func (*Adapter) Insert

func (adapter *Adapter) Insert(query grimoire.Query, changes map[string]interface{}, loggers ...grimoire.Logger) (interface{}, error)

Insert inserts a record to database and returns its id.

func (*Adapter) InsertAll

func (adapter *Adapter) InsertAll(query grimoire.Query, fields []string, allchanges []map[string]interface{}, loggers ...grimoire.Logger) ([]interface{}, error)

InsertAll inserts all record to database and returns its ids.

func (*Adapter) Query

func (adapter *Adapter) Query(out interface{}, statement string, args []interface{}, loggers ...grimoire.Logger) (int64, error)

Query performs query operation.

func (*Adapter) Rollback

func (adapter *Adapter) Rollback() error

Rollback revert current transaction.

func (*Adapter) Update

func (adapter *Adapter) Update(query grimoire.Query, changes map[string]interface{}, loggers ...grimoire.Logger) error

Update updates a record in database.

type Builder

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

Builder defines information of query builder.

func NewBuilder

func NewBuilder(config *Config) *Builder

NewBuilder create new SQL builder.

func (*Builder) Aggregate

func (builder *Builder) Aggregate(q grimoire.Query) (string, []interface{})

Aggregate generates query for aggregation.

func (*Builder) Delete

func (builder *Builder) Delete(collection string, cond c.Condition) (string, []interface{})

Delete generates query for delete.

func (*Builder) Find

func (builder *Builder) Find(q grimoire.Query) (string, []interface{})

Find generates query for select.

func (*Builder) Insert

func (builder *Builder) Insert(collection string, changes map[string]interface{}) (string, []interface{})

Insert generates query for insert.

func (*Builder) InsertAll

func (builder *Builder) InsertAll(collection string, fields []string, allchanges []map[string]interface{}) (string, []interface{})

InsertAll generates query for multiple insert.

func (*Builder) Returning

func (builder *Builder) Returning(field string) *Builder

Returning append returning to insert query.

func (*Builder) Update

func (builder *Builder) Update(collection string, changes map[string]interface{}, cond c.Condition) (string, []interface{})

Update generates query for update.

type Config

type Config struct {
	Placeholder         string
	Ordinal             bool
	InsertDefaultValues bool
	EscapeChar          string
	ErrorFunc           func(error) error
	IncrementFunc       func(Adapter) int
}

Config holds configuration for adapter.

type Rows

type Rows interface {
	Scan(dest ...interface{}) error
	Columns() ([]string, error)
	Next() bool
}

Rows is minimal rows interface for test purpose

Jump to

Keyboard shortcuts

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