gorm

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2023 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorMissingWhereClause = errors.New("WHERE conditions required")
)

Functions

func FileWithLineNum

func FileWithLineNum() string

FileWithLineNum return the file name and line number of the current file

func New

func New(connection string) (*gormio.DB, error)

DEPRECATED: Not recommended, if you must, use NewGormImpl.

func NewLogger

func NewLogger(writer logger.Writer, config logger.Config) logger.Interface

Types

type Dialector

type Dialector interface {
	Make(configs []databasecontract.Config) ([]gorm.Dialector, error)
}

type DialectorImpl

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

func NewDialectorImpl

func NewDialectorImpl(config config.Config, connection string) *DialectorImpl

func (*DialectorImpl) Make

func (d *DialectorImpl) Make(configs []databasecontract.Config) ([]gorm.Dialector, error)

type Event

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

func NewEvent

func NewEvent(query *QueryImpl, model, dest any) *Event

func (*Event) ColumnNamesWithDbColumnNames

func (e *Event) ColumnNamesWithDbColumnNames() map[string]string

func (*Event) Context

func (e *Event) Context() context.Context

func (*Event) DestOfMap

func (e *Event) DestOfMap() map[string]any

func (*Event) GetAttribute

func (e *Event) GetAttribute(key string) any

func (*Event) GetOriginal

func (e *Event) GetOriginal(key string, def ...any) any

func (*Event) IsClean

func (e *Event) IsClean(fields ...string) bool

func (*Event) IsDirty

func (e *Event) IsDirty(columns ...string) bool

func (*Event) ModelOfMap

func (e *Event) ModelOfMap() map[string]any

func (*Event) Query

func (e *Event) Query() orm.Query

func (*Event) SetAttribute

func (e *Event) SetAttribute(key string, value any)

type Gorm

type Gorm interface {
	Make() (*gormio.DB, error)
}

type GormImpl

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

func InitializeGorm

func InitializeGorm(config2 config.Config, connection string) *GormImpl

func NewGormImpl

func NewGormImpl(config config.Config, connection string, dbConfig db.Config, dialector Dialector) *GormImpl

func (*GormImpl) Make

func (r *GormImpl) Make() (*gormio.DB, error)

type Logger

type Logger struct {
	logger.Writer
	logger.Config
	// contains filtered or unexported fields
}

func (Logger) Error

func (l Logger) Error(ctx context.Context, msg string, data ...any)

Error print error messages

func (Logger) Info

func (l Logger) Info(ctx context.Context, msg string, data ...any)

Info print info

func (*Logger) LogMode

func (l *Logger) LogMode(level logger.LogLevel) logger.Interface

LogMode log mode

func (Logger) Trace

func (l Logger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)

Trace print sql message

func (Logger) Warn

func (l Logger) Warn(ctx context.Context, msg string, data ...any)

Warn print warn messages

type MysqlDocker

type MysqlDocker struct {
	MockConfig *configmock.Config
	Port       int
	// contains filtered or unexported fields
}

func NewMysqlDocker

func NewMysqlDocker() *MysqlDocker

func (*MysqlDocker) Init

func (r *MysqlDocker) Init() (*dockertest.Pool, *dockertest.Resource, error)

func (*MysqlDocker) MockReadWrite

func (r *MysqlDocker) MockReadWrite(readPort, writePort int)

func (*MysqlDocker) New

func (r *MysqlDocker) New() (*dockertest.Pool, *dockertest.Resource, orm.Query, error)

func (*MysqlDocker) Query

func (r *MysqlDocker) Query(createTable bool) (orm.Query, error)

func (*MysqlDocker) QueryWithPrefixAndSingular

func (r *MysqlDocker) QueryWithPrefixAndSingular() (orm.Query, error)

type PostgresqlDocker

type PostgresqlDocker struct {
	MockConfig *configmock.Config
	Port       int
	// contains filtered or unexported fields
}

func NewPostgresqlDocker

func NewPostgresqlDocker() *PostgresqlDocker

func (*PostgresqlDocker) Init

func (r *PostgresqlDocker) Init() (*dockertest.Pool, *dockertest.Resource, error)

func (*PostgresqlDocker) MockReadWrite

func (r *PostgresqlDocker) MockReadWrite(readPort, writePort int)

func (*PostgresqlDocker) New

func (r *PostgresqlDocker) New() (*dockertest.Pool, *dockertest.Resource, orm.Query, error)

func (*PostgresqlDocker) Query

func (r *PostgresqlDocker) Query(createTable bool) (orm.Query, error)

func (*PostgresqlDocker) QueryWithPrefixAndSingular

func (r *PostgresqlDocker) QueryWithPrefixAndSingular() (orm.Query, error)

type QueryImpl

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

func InitializeQuery

func InitializeQuery(ctx context.Context, config2 config.Config, connection string) (*QueryImpl, error)

func NewQueryImpl

func NewQueryImpl(ctx context.Context, config config.Config, gorm Gorm) (*QueryImpl, error)

func NewQueryWithWithoutEvents

func NewQueryWithWithoutEvents(instance *gormio.DB, withoutEvents bool) *QueryImpl

func (*QueryImpl) Association

func (r *QueryImpl) Association(association string) ormcontract.Association

func (*QueryImpl) Begin

func (r *QueryImpl) Begin() (ormcontract.Transaction, error)

func (*QueryImpl) Count

func (r *QueryImpl) Count(count *int64) error

func (*QueryImpl) Create

func (r *QueryImpl) Create(value any) error

func (*QueryImpl) Delete

func (r *QueryImpl) Delete(dest any, conds ...any) (*ormcontract.Result, error)

func (*QueryImpl) Distinct

func (r *QueryImpl) Distinct(args ...any) ormcontract.Query

func (*QueryImpl) Driver

func (r *QueryImpl) Driver() ormcontract.Driver

func (*QueryImpl) Exec

func (r *QueryImpl) Exec(sql string, values ...any) (*ormcontract.Result, error)

func (*QueryImpl) Find

func (r *QueryImpl) Find(dest any, conds ...any) error

func (*QueryImpl) FindOrFail

func (r *QueryImpl) FindOrFail(dest any, conds ...any) error

func (*QueryImpl) First

func (r *QueryImpl) First(dest any) error

func (*QueryImpl) FirstOr

func (r *QueryImpl) FirstOr(dest any, callback func() error) error

func (*QueryImpl) FirstOrCreate

func (r *QueryImpl) FirstOrCreate(dest any, conds ...any) error

func (*QueryImpl) FirstOrFail

func (r *QueryImpl) FirstOrFail(dest any) error

func (*QueryImpl) FirstOrNew

func (r *QueryImpl) FirstOrNew(dest any, attributes any, values ...any) error

func (*QueryImpl) ForceDelete

func (r *QueryImpl) ForceDelete(value any, conds ...any) (*ormcontract.Result, error)

func (*QueryImpl) Get

func (r *QueryImpl) Get(dest any) error

func (*QueryImpl) Group

func (r *QueryImpl) Group(name string) ormcontract.Query

func (*QueryImpl) Having

func (r *QueryImpl) Having(query any, args ...any) ormcontract.Query

func (*QueryImpl) Instance

func (r *QueryImpl) Instance() *gormio.DB

func (*QueryImpl) Join

func (r *QueryImpl) Join(query string, args ...any) ormcontract.Query

func (*QueryImpl) Limit

func (r *QueryImpl) Limit(limit int) ormcontract.Query

func (*QueryImpl) Load

func (r *QueryImpl) Load(model any, relation string, args ...any) error

func (*QueryImpl) LoadMissing

func (r *QueryImpl) LoadMissing(model any, relation string, args ...any) error

func (*QueryImpl) LockForUpdate

func (r *QueryImpl) LockForUpdate() ormcontract.Query

func (*QueryImpl) Model

func (r *QueryImpl) Model(value any) ormcontract.Query

func (*QueryImpl) Offset

func (r *QueryImpl) Offset(offset int) ormcontract.Query

func (*QueryImpl) Omit

func (r *QueryImpl) Omit(columns ...string) ormcontract.Query

func (*QueryImpl) OrWhere

func (r *QueryImpl) OrWhere(query any, args ...any) ormcontract.Query

func (*QueryImpl) Order

func (r *QueryImpl) Order(value any) ormcontract.Query

func (*QueryImpl) Paginate

func (r *QueryImpl) Paginate(page, limit int, dest any, total *int64) error

func (*QueryImpl) Pluck

func (r *QueryImpl) Pluck(column string, dest any) error

func (*QueryImpl) Raw

func (r *QueryImpl) Raw(sql string, values ...any) ormcontract.Query

func (*QueryImpl) Save

func (r *QueryImpl) Save(value any) error

func (*QueryImpl) SaveQuietly

func (r *QueryImpl) SaveQuietly(value any) error

func (*QueryImpl) Scan

func (r *QueryImpl) Scan(dest any) error

func (*QueryImpl) Scopes

func (r *QueryImpl) Scopes(funcs ...func(ormcontract.Query) ormcontract.Query) ormcontract.Query

func (*QueryImpl) Select

func (r *QueryImpl) Select(query any, args ...any) ormcontract.Query

func (*QueryImpl) SharedLock

func (r *QueryImpl) SharedLock() ormcontract.Query

func (*QueryImpl) Table

func (r *QueryImpl) Table(name string, args ...any) ormcontract.Query

func (*QueryImpl) Update

func (r *QueryImpl) Update(column any, value ...any) (*ormcontract.Result, error)

func (*QueryImpl) UpdateOrCreate

func (r *QueryImpl) UpdateOrCreate(dest any, attributes any, values any) error

func (*QueryImpl) Where

func (r *QueryImpl) Where(query any, args ...any) ormcontract.Query

func (*QueryImpl) With

func (r *QueryImpl) With(query string, args ...any) ormcontract.Query

func (*QueryImpl) WithTrashed

func (r *QueryImpl) WithTrashed() ormcontract.Query

func (*QueryImpl) WithoutEvents

func (r *QueryImpl) WithoutEvents() ormcontract.Query

type SqliteDocker

type SqliteDocker struct {
	MockConfig *configmock.Config
	// contains filtered or unexported fields
}

func NewSqliteDocker

func NewSqliteDocker(dbName string) *SqliteDocker

func (*SqliteDocker) Init

func (r *SqliteDocker) Init() (*dockertest.Pool, *dockertest.Resource, error)

func (*SqliteDocker) MockReadWrite

func (r *SqliteDocker) MockReadWrite()

func (*SqliteDocker) New

func (r *SqliteDocker) New() (*dockertest.Pool, *dockertest.Resource, orm.Query, error)

func (*SqliteDocker) Query

func (r *SqliteDocker) Query(createTable bool) (orm.Query, error)

func (*SqliteDocker) QueryWithPrefixAndSingular

func (r *SqliteDocker) QueryWithPrefixAndSingular() (orm.Query, error)

type SqlserverDocker

type SqlserverDocker struct {
	MockConfig *configmock.Config
	Port       int
	// contains filtered or unexported fields
}

func NewSqlserverDocker

func NewSqlserverDocker() *SqlserverDocker

func (*SqlserverDocker) Init

func (r *SqlserverDocker) Init() (*dockertest.Pool, *dockertest.Resource, error)

func (*SqlserverDocker) MockReadWrite

func (r *SqlserverDocker) MockReadWrite(readPort, writePort int)

func (*SqlserverDocker) New

func (r *SqlserverDocker) New() (*dockertest.Pool, *dockertest.Resource, orm.Query, error)

func (*SqlserverDocker) Query

func (r *SqlserverDocker) Query(createTable bool) (orm.Query, error)

func (*SqlserverDocker) QueryWithPrefixAndSingular

func (r *SqlserverDocker) QueryWithPrefixAndSingular() (orm.Query, error)

type Table

type Table struct {
}

func (Table) Create

func (r Table) Create(driver orm.Driver, db orm.Query) error

func (Table) CreateWithPrefixAndSingular

func (r Table) CreateWithPrefixAndSingular(driver orm.Driver, db orm.Query) error

type Transaction

type Transaction struct {
	orm.Query
	// contains filtered or unexported fields
}

func NewTransaction

func NewTransaction(tx *gorm.DB) *Transaction

func (*Transaction) Commit

func (r *Transaction) Commit() error

func (*Transaction) Rollback

func (r *Transaction) Rollback() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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