sql

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2020 License: MIT Imports: 8 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 ExtractString

func ExtractString(s, left, right string) string

ExtractString between two string.

Types

type Adapter

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

Adapter definition for database database.

func New

func New(config *Config) *Adapter

New initialize adapter without db.

func (*Adapter) Aggregate

func (adapter *Adapter) Aggregate(ctx context.Context, query rel.Query, mode string, field string) (int, error)

Aggregate record using given query.

func (*Adapter) Begin

func (adapter *Adapter) Begin(ctx context.Context) (rel.Adapter, error)

Begin begins a new transaction.

func (*Adapter) Close

func (adapter *Adapter) Close() error

Close database connection.

func (*Adapter) Commit

func (adapter *Adapter) Commit(ctx context.Context) error

Commit commits current transaction.

func (*Adapter) Delete

func (adapter *Adapter) Delete(ctx context.Context, query rel.Query) (int, error)

Delete deletes all results that match the query.

func (*Adapter) Exec

func (adapter *Adapter) Exec(ctx context.Context, statement string, args []interface{}) (int64, int64, error)

Exec performs exec operation.

func (*Adapter) Insert

func (adapter *Adapter) Insert(ctx context.Context, query rel.Query, mutates map[string]rel.Mutate) (interface{}, error)

Insert inserts a record to database and returns its id.

func (*Adapter) InsertAll

func (adapter *Adapter) InsertAll(ctx context.Context, query rel.Query, fields []string, bulkMutates []map[string]rel.Mutate) ([]interface{}, error)

InsertAll inserts all record to database and returns its ids.

func (*Adapter) Instrument added in v0.3.0

func (adapter *Adapter) Instrument(ctx context.Context, op string, message string) func(err error)

Instrument call instrumenter, if no instrumenter is set, this will be a no op.

func (*Adapter) Instrumentation added in v0.3.0

func (adapter *Adapter) Instrumentation(instrumenter rel.Instrumenter)

Instrumentation set instrumenter for this adapter.

func (*Adapter) Ping added in v0.2.0

func (adapter *Adapter) Ping(ctx context.Context) error

Ping database.

func (*Adapter) Query

func (adapter *Adapter) Query(ctx context.Context, query rel.Query) (rel.Cursor, error)

Query performs query operation.

func (*Adapter) Rollback

func (adapter *Adapter) Rollback(ctx context.Context) error

Rollback revert current transaction.

func (*Adapter) Update

func (adapter *Adapter) Update(ctx context.Context, query rel.Query, mutates map[string]rel.Mutate) (int, error)

Update updates a record in database.

type Buffer

type Buffer struct {
	bytes.Buffer
	Arguments []interface{}
}

Buffer used to strings buffer and argument of the query.

func (*Buffer) Append

func (b *Buffer) Append(args ...interface{})

Append argumetns.

func (*Buffer) Reset

func (b *Buffer) Reset()

Reset buffer.

type Builder

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

Builder defines information of query b.

func NewBuilder

func NewBuilder(config *Config) *Builder

NewBuilder create new SQL builder.

func (*Builder) Aggregate

func (b *Builder) Aggregate(query rel.Query, mode string, field string) (string, []interface{})

Aggregate generates query for aggregation.

func (*Builder) Delete

func (b *Builder) Delete(table string, filter rel.FilterQuery) (string, []interface{})

Delete generates query for delete.

func (*Builder) Find

func (b *Builder) Find(query rel.Query) (string, []interface{})

Find generates query for select.

func (*Builder) Insert

func (b *Builder) Insert(table string, mutates map[string]rel.Mutate) (string, []interface{})

Insert generates query for insert.

func (*Builder) InsertAll

func (b *Builder) InsertAll(table string, fields []string, bulkMutates []map[string]rel.Mutate) (string, []interface{})

InsertAll generates query for multiple insert.

func (*Builder) Returning

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

Returning append returning to insert rel.

func (*Builder) Update

func (b *Builder) Update(table string, mutates map[string]rel.Mutate, filter rel.FilterQuery) (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 Cursor

type Cursor struct {
	*sql.Rows
}

Cursor used for retrieving result.

func (*Cursor) Fields

func (c *Cursor) Fields() ([]string, error)

Fields returned in the result.

func (*Cursor) NopScanner

func (c *Cursor) NopScanner() interface{}

NopScanner for this adapter.

Jump to

Keyboard shortcuts

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