Skip to content

sql

import "github.com/go-rel/sql"

Overview

Constants

const DefaultTimeLayout = "2006-01-02 15:04:05"
DefaultTimeLayout default time layout.

func ColumnMapper

func ColumnMapper(column *rel.Column) (string, int, int)
ColumnMapper function.

func ExtractString

func ExtractString(s, left, right string) string
ExtractString between two string.

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.

type DeleteBuilder

type DeleteBuilder interface {
    Build(table string, filter rel.FilterQuery) (string, []interface{})
}

type ErrorMapper

type ErrorMapper func(error) error
ErrorMapper function.

type IncrementFunc

type IncrementFunc func(SQL) int
IncrementFunc function.

type IndexBuilder

type IndexBuilder interface {
    Build(index rel.Index) string
}

type InsertAllBuilder

type InsertAllBuilder interface {
    Build(table string, primaryField string, fields []string, bulkMutates []map[string]rel.Mutate, onConflict rel.OnConflict) (string, []interface{})
}

type InsertBuilder

type InsertBuilder interface {
    Build(table string, primaryField string, mutates map[string]rel.Mutate, onConflict rel.OnConflict) (string, []interface{})
}

type QueryBuilder

type QueryBuilder interface {
    Build(query rel.Query) (string, []interface{})
}

type SQL

type SQL struct {
    QueryBuilder     QueryBuilder
    InsertBuilder    InsertBuilder
    InsertAllBuilder InsertAllBuilder
    UpdateBuilder    UpdateBuilder
    DeleteBuilder    DeleteBuilder
    TableBuilder     TableBuilder
    IndexBuilder     IndexBuilder
    IncrementFunc    IncrementFunc
    ErrorMapper      ErrorMapper
    DB               *sql.DB
    Tx               *sql.Tx
    Savepoint        int
    Instrumenter     rel.Instrumenter
}
SQL base adapter.

func (SQL) Aggregate

func (s SQL) Aggregate(ctx context.Context, query rel.Query, mode string, field string) (int, error)
Aggregate record using given query.

func (SQL) Apply

func (s SQL) Apply(ctx context.Context, migration rel.Migration) error
Apply performs migration to database.

Deprecated: Use Schema Apply instead.

func (SQL) Begin

func (s SQL) Begin(ctx context.Context) (rel.Adapter, error)
Begin begins a new transaction.

func (SQL) Close

func (s SQL) Close() error
Close database connection.

TODO: add closer to adapter interface

func (SQL) Commit

func (s SQL) Commit(ctx context.Context) error
Commit commits current transaction.

func (SQL) Delete

func (s SQL) Delete(ctx context.Context, query rel.Query) (int, error)
Delete deletes all results that match the query.

func (SQL) DoExec

func (s SQL) DoExec(ctx context.Context, statement string, args []interface{}) (sql.Result, error)
DoExec using active database connection.

func (SQL) DoQuery

func (s SQL) DoQuery(ctx context.Context, statement string, args []interface{}) (*sql.Rows, error)
DoQuery using active database connection.

func (SQL) Exec

func (s SQL) Exec(ctx context.Context, statement string, args []interface{}) (int64, int64, error)
Exec performs exec operation.

func (SQL) Insert

func (s SQL) Insert(ctx context.Context, query rel.Query, primaryField string, mutates map[string]rel.Mutate, onConflict rel.OnConflict) (interface{}, error)
Insert inserts a record to database and returns its id.

func (SQL) InsertAll

func (s SQL) InsertAll(ctx context.Context, query rel.Query, primaryField string, fields []string, bulkMutates []map[string]rel.Mutate, onConflict rel.OnConflict) ([]interface{}, error)
InsertAll inserts multiple records to database and returns its ids.

func (*SQL) Instrumentation

func (s *SQL) Instrumentation(instrumenter rel.Instrumenter)
Instrumentation set instrumenter for this adapter.

func (SQL) Ping

func (s SQL) Ping(ctx context.Context) error
Ping database.

func (SQL) Query

func (s SQL) Query(ctx context.Context, query rel.Query) (rel.Cursor, error)
Query performs query operation.

func (SQL) Rollback

func (s SQL) Rollback(ctx context.Context) error
Rollback revert current transaction.

func (SQL) SchemaApply

func (s SQL) SchemaApply(ctx context.Context, migration rel.Migration) error
SchemaApply performs migration to database.

func (SQL) Update

func (s SQL) Update(ctx context.Context, query rel.Query, primaryField string, mutates map[string]rel.Mutate) (int, error)
Update updates a record in database.

type TableBuilder

type TableBuilder interface {
    Build(table rel.Table) string
}

type UpdateBuilder

type UpdateBuilder interface {
    Build(table string, primaryField string, mutates map[string]rel.Mutate, filter rel.FilterQuery) (string, []interface{})
}

Last update: 2022-06-25