sql

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2021 License: MIT Imports: 9 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 Escape

func Escape(config Config, field string) string

Escape field or table name.

func ExtractString

func ExtractString(s, left, right string) string

ExtractString between two string.

func MapColumn

func MapColumn(column *rel.Column) (string, int, int)

MapColumn func.

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 (a *Adapter) Aggregate(ctx context.Context, query rel.Query, mode string, field string) (int, error)

Aggregate record using given query.

func (*Adapter) Apply

func (a *Adapter) Apply(ctx context.Context, migration rel.Migration) error

Apply table.

func (*Adapter) Begin

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

Begin begins a new transaction.

func (*Adapter) Close

func (a *Adapter) Close() error

Close database connection.

func (*Adapter) Commit

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

Commit commits current transaction.

func (*Adapter) Delete

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

Delete deletes all results that match the query.

func (*Adapter) Exec

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

Exec performs exec operation.

func (*Adapter) Insert

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

Insert inserts a record to database and returns its id.

func (*Adapter) InsertAll

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

InsertAll inserts all record to database and returns its ids.

func (*Adapter) Instrumentation

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

Instrumentation set instrumenter for this adapter.

func (*Adapter) Ping

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

Ping database.

func (*Adapter) Query

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

Query performs query operation.

func (*Adapter) Rollback

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

Rollback revert current transaction.

func (*Adapter) Update

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

Update updates a record in database.

type Buffer

type Buffer struct {
	strings.Builder
	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) Index

func (b *Builder) Index(index rel.Index) string

Index generates query for index.

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

func (b *Builder) Table(table rel.Table) string

Table generates query for table creation and modification.

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
	DropIndexOnTable    bool
	EscapeChar          string
	ErrorFunc           func(error) error
	IncrementFunc       func(Adapter) int
	IndexToSQL          func(config Config, buffer *Buffer, index rel.Index) bool
	MapColumnFunc       func(column *rel.Column) (string, int, 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