sql

package module
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2023 License: MIT Imports: 7 Imported by: 6

README

sql

GoDoc Test Go Report Card codecov Gitter chat

Base SQL adapter for REL.

Documentation

Index

Constants

View Source
const DefaultTimeLayout = "2006-01-02 15:04:05"

DefaultTimeLayout default time layout.

Variables

This section is empty.

Functions

func ColumnMapper

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

ColumnMapper function.

func ColumnOptionsMapper added in v0.16.0

func ColumnOptionsMapper(column *rel.Column) string

ColumnOptionsMapper function.

func DropKeyMapper added in v0.14.0

func DropKeyMapper(keyType rel.KeyType) string

func ExtractString

func ExtractString(s, left, right string) string

ExtractString between two string.

Types

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() any

NopScanner for this adapter.

type DeleteBuilder

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

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, []any)
}

type InsertBuilder

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

type QueryBuilder

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

type SQL

type SQL struct {
	QueryBuilder     QueryBuilder
	InsertBuilder    InsertBuilder
	InsertAllBuilder InsertAllBuilder
	UpdateBuilder    UpdateBuilder
	DeleteBuilder    DeleteBuilder
	TableBuilder     TableBuilder
	IndexBuilder     IndexBuilder
	Increment        int
	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 deprecated

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 []any) (sql.Result, error)

DoExec using active database connection.

func (SQL) DoQuery

func (s SQL) DoQuery(ctx context.Context, statement string, args []any) (*sql.Rows, error)

DoQuery using active database connection.

func (SQL) Exec

func (s SQL) Exec(ctx context.Context, statement string, args []any) (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) (any, 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) ([]any, 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) Name added in v0.16.0

func (s SQL) Name() string

Name returns database adapter name.

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, []any)
}

Directories

Path Synopsis
Package specs defines test specifications for rel's adapter.
Package specs defines test specifications for rel's adapter.

Jump to

Keyboard shortcuts

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