database

package
v0.0.0-...-9c44629 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRecordNotFound = gorm.ErrRecordNotFound
)

Functions

func ErrNotFound

func ErrNotFound(err error) bool

Types

type Association

type Association interface {
	Find(value interface{}) Association
	Append(values ...interface{}) Association
	Replace(values ...interface{}) Association
	Delete(values ...interface{}) Association
	Count() int
	Error() error
}

type Cache

type Cache interface {
	Get(key interface{}) (value interface{}, ok bool)
	Add(key interface{}, value interface{})
	Remove(key interface{})
}

type Config

type Config struct {
	Host     string
	Port     int
	Name     string
	User     string
	Password string
	Migrate  string
	Debug    bool
}

func (Config) DSN

func (c Config) DSN() gorm.DSN

type DB

type DB struct {
	DBCache Cache `inject:"db_cache"`
	// contains filtered or unexported fields
}

func (*DB) AddError

func (d *DB) AddError(err error) error

func (*DB) AddForeignKey

func (d *DB) AddForeignKey(field string, dest string, onDelete string, onUpdate string) DBEngine

func (*DB) AddIndex

func (d *DB) AddIndex(indexName string, columns ...string) DBEngine

func (*DB) AddUniqueIndex

func (d *DB) AddUniqueIndex(indexName string, columns ...string) DBEngine

func (*DB) Assign

func (d *DB) Assign(attrs ...interface{}) DBEngine

func (*DB) Association

func (d *DB) Association(column string) Association

func (*DB) Attrs

func (d *DB) Attrs(attrs ...interface{}) DBEngine

func (*DB) AutoMigrate

func (d *DB) AutoMigrate(values ...interface{}) DBEngine

func (*DB) Begin

func (d *DB) Begin() DBEngine

func (*DB) Cache

func (d *DB) Cache() Cache

func (*DB) Close

func (d *DB) Close() error

func (*DB) Commit

func (d *DB) Commit() DBEngine

func (*DB) Count

func (d *DB) Count(value interface{}) DBEngine

func (*DB) Create

func (d *DB) Create(value interface{}) DBEngine

func (*DB) CreateTable

func (d *DB) CreateTable(values ...interface{}) DBEngine

func (*DB) DB

func (d *DB) DB() *sql.DB

func (*DB) Debug

func (d *DB) Debug() DBEngine

func (*DB) Delete

func (d *DB) Delete(value interface{}, where ...interface{}) DBEngine

func (*DB) DropColumn

func (d *DB) DropColumn(column string) DBEngine

func (*DB) DropTable

func (d *DB) DropTable(values ...interface{}) DBEngine

func (*DB) DropTableIfExists

func (d *DB) DropTableIfExists(values ...interface{}) DBEngine

func (*DB) Error

func (d *DB) Error() error

func (*DB) Exec

func (d *DB) Exec(sql string, values ...interface{}) DBEngine

func (*DB) Filter

func (d *DB) Filter(query interface{}, arg interface{}) DBEngine

func (*DB) Find

func (d *DB) Find(out interface{}, where ...interface{}) DBEngine

func (*DB) First

func (d *DB) First(out interface{}, where ...interface{}) DBEngine

func (*DB) FirstOrCreate

func (d *DB) FirstOrCreate(out interface{}, where ...interface{}) DBEngine

func (*DB) FirstOrInit

func (d *DB) FirstOrInit(out interface{}, where ...interface{}) DBEngine

func (*DB) Get

func (d *DB) Get(name string) (interface{}, bool)

func (*DB) GetErrors

func (d *DB) GetErrors() (errors []error)

func (*DB) Group

func (d *DB) Group(query string) DBEngine

func (*DB) HasTable

func (d *DB) HasTable(value interface{}) bool

func (*DB) Having

func (d *DB) Having(query string, values ...interface{}) DBEngine

func (*DB) InstantSet

func (d *DB) InstantSet(name string, value interface{}) DBEngine

func (*DB) Joins

func (d *DB) Joins(query string, args ...interface{}) DBEngine

func (*DB) Last

func (d *DB) Last(out interface{}, where ...interface{}) DBEngine

func (*DB) Limit

func (d *DB) Limit(value int) DBEngine

func (*DB) LogMode

func (d *DB) LogMode(enable bool) DBEngine

func (*DB) Model

func (d *DB) Model(value interface{}) DBEngine

func (*DB) ModifyColumn

func (d *DB) ModifyColumn(column string, typ string) DBEngine

func (*DB) New

func (d *DB) New() DBEngine

func (*DB) NewRecord

func (d *DB) NewRecord(value interface{}) bool

func (*DB) Not

func (d *DB) Not(query interface{}, args ...interface{}) DBEngine

func (*DB) Offset

func (d *DB) Offset(value int) DBEngine

func (*DB) Omit

func (d *DB) Omit(columns ...string) DBEngine

func (*DB) Or

func (d *DB) Or(query interface{}, args ...interface{}) DBEngine

func (*DB) Order

func (d *DB) Order(value string, reorder ...bool) DBEngine

func (*DB) Pluck

func (d *DB) Pluck(column string, value interface{}) DBEngine

func (*DB) Preload

func (d *DB) Preload(column string, conditions ...interface{}) DBEngine

func (*DB) Raw

func (d *DB) Raw(sql string, values ...interface{}) DBEngine

func (*DB) RecordNotFound

func (d *DB) RecordNotFound() bool

func (*DB) Related

func (d *DB) Related(value interface{}, foreignKeys ...string) DBEngine

func (*DB) RemoveIndex

func (d *DB) RemoveIndex(indexName string) DBEngine

func (*DB) Rollback

func (d *DB) Rollback() DBEngine

func (*DB) Row

func (d *DB) Row() *sql.Row

func (*DB) Rows

func (d *DB) Rows() (*sql.Rows, error)

func (*DB) RowsAffected

func (d *DB) RowsAffected() int64

func (*DB) Save

func (d *DB) Save(value interface{}) DBEngine

func (*DB) Scan

func (d *DB) Scan(dest interface{}) DBEngine

func (*DB) ScanRows

func (d *DB) ScanRows(rows *sql.Rows, result interface{}) error

func (*DB) Select

func (d *DB) Select(query interface{}, args ...interface{}) DBEngine

func (*DB) Set

func (d *DB) Set(name string, value interface{}) DBEngine

func (*DB) SingularTable

func (d *DB) SingularTable(enable bool)

func (*DB) Table

func (d *DB) Table(name string) DBEngine

func (*DB) Unscoped

func (d *DB) Unscoped() DBEngine

func (*DB) Update

func (d *DB) Update(attrs ...interface{}) DBEngine

func (*DB) UpdateColumn

func (d *DB) UpdateColumn(attrs ...interface{}) DBEngine

func (*DB) UpdateColumns

func (d *DB) UpdateColumns(values interface{}) DBEngine

func (*DB) Updates

func (d *DB) Updates(values interface{}, ignoreProtectedAttrs ...bool) DBEngine

func (*DB) Where

func (d *DB) Where(query interface{}, args ...interface{}) DBEngine

type DBEngine

type DBEngine interface {
	Close() error
	DB() *sql.DB
	New() DBEngine
	LogMode(enable bool) DBEngine
	SingularTable(enable bool)
	Where(query interface{}, args ...interface{}) DBEngine
	Filter(query interface{}, by interface{}) DBEngine
	Or(query interface{}, args ...interface{}) DBEngine
	Not(query interface{}, args ...interface{}) DBEngine
	Limit(value int) DBEngine
	Offset(value int) DBEngine
	Order(value string, reorder ...bool) DBEngine
	Select(query interface{}, args ...interface{}) DBEngine
	Omit(columns ...string) DBEngine
	Group(query string) DBEngine
	Having(query string, values ...interface{}) DBEngine
	Joins(query string, args ...interface{}) DBEngine
	Unscoped() DBEngine
	Attrs(attrs ...interface{}) DBEngine
	Assign(attrs ...interface{}) DBEngine
	First(out interface{}, where ...interface{}) DBEngine
	Last(out interface{}, where ...interface{}) DBEngine
	Find(out interface{}, where ...interface{}) DBEngine
	Scan(dest interface{}) DBEngine
	Row() *sql.Row
	Rows() (*sql.Rows, error)
	ScanRows(rows *sql.Rows, result interface{}) error
	Pluck(column string, value interface{}) DBEngine
	Count(value interface{}) DBEngine
	Related(value interface{}, foreignKeys ...string) DBEngine
	FirstOrInit(out interface{}, where ...interface{}) DBEngine
	FirstOrCreate(out interface{}, where ...interface{}) DBEngine
	Update(attrs ...interface{}) DBEngine
	Updates(values interface{}, ignoreProtectedAttrs ...bool) DBEngine
	UpdateColumn(attrs ...interface{}) DBEngine
	UpdateColumns(values interface{}) DBEngine
	Save(value interface{}) DBEngine
	Create(value interface{}) DBEngine
	Delete(value interface{}, where ...interface{}) DBEngine
	Raw(sql string, values ...interface{}) DBEngine
	Exec(sql string, values ...interface{}) DBEngine
	Model(value interface{}) DBEngine
	Table(name string) DBEngine
	Debug() DBEngine
	Begin() DBEngine
	Commit() DBEngine
	Rollback() DBEngine
	NewRecord(value interface{}) bool
	RecordNotFound() bool
	CreateTable(values ...interface{}) DBEngine
	DropTable(values ...interface{}) DBEngine
	DropTableIfExists(values ...interface{}) DBEngine
	HasTable(value interface{}) bool
	AutoMigrate(values ...interface{}) DBEngine
	ModifyColumn(column string, typ string) DBEngine
	DropColumn(column string) DBEngine
	AddIndex(indexName string, column ...string) DBEngine
	AddUniqueIndex(indexName string, column ...string) DBEngine
	RemoveIndex(indexName string) DBEngine
	AddForeignKey(field string, dest string, onDelete string, onUpdate string) DBEngine
	Preload(column string, conditions ...interface{}) DBEngine
	Set(name string, value interface{}) DBEngine
	InstantSet(name string, value interface{}) DBEngine
	Get(name string) (value interface{}, ok bool)
	Association(column string) Association
	AddError(err error) error
	GetErrors() (errors []error)

	// extra
	Error() error
	RowsAffected() int64
	Cache() Cache
}

DBEngine is an interface which DB implements. By then all test are well organized

func Open

func Open(cfg Config) (DBEngine, error)

Open is a drop-in replacement for Open()

func OpenInMemorySqlite

func OpenInMemorySqlite(opts ...Option) (DBEngine, error)

Creates an sqlite memory db which will be database.DBEngine If WithCache is not provided, lru cache will be created as default.

type Option

type Option func(o *options)

func WithCache

func WithCache(cache Cache) Option

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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