gorm

package
v1.13.9 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 38 Imported by: 5

Documentation

Index

Constants

View Source
const (
	DbPassword = "Goravel(!)"
	DbUser     = "root"
)

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 NewLogger

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

func ToCarbonHookFunc added in v1.13.0

func ToCarbonHookFunc() mapstructure.DecodeHookFunc

func ToDeletedAtHookFunc added in v1.13.0

func ToDeletedAtHookFunc() mapstructure.DecodeHookFunc

func ToTimeHookFunc added in v1.13.0

func ToTimeHookFunc() mapstructure.DecodeHookFunc

Types

type Address added in v1.13.5

type Address struct {
	orm.Model
	UserID   uint
	Name     string
	Province string
	User     *User
}

type Author added in v1.13.5

type Author struct {
	orm.Model
	BookID uint
	Name   string
}

type Book added in v1.13.5

type Book struct {
	orm.Model
	UserID uint
	Name   string
	User   *User
	Author *Author
}

type Box added in v1.13.5

type Box struct {
	orm.Model
	orm.SoftDeletes
	Name string
}

func (*Box) Connection added in v1.13.5

func (p *Box) Connection() string

type Conditions added in v1.13.5

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

type CursorImpl added in v1.13.0

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

func (*CursorImpl) Scan added in v1.13.0

func (c *CursorImpl) Scan(value any) error

type Dialector added in v1.12.0

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

type DialectorImpl added in v1.12.0

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

func NewDialectorImpl added in v1.12.0

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

func (*DialectorImpl) Make added in v1.12.0

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

type Event added in v1.11.0

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

func NewEvent added in v1.11.0

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

func (*Event) ColumnNamesWithDbColumnNames added in v1.11.0

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

func (*Event) Context added in v1.11.0

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

func (*Event) DestOfMap added in v1.11.0

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

func (*Event) GetAttribute added in v1.11.0

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

func (*Event) GetOriginal added in v1.11.0

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

func (*Event) IsClean added in v1.11.0

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

func (*Event) IsDirty added in v1.11.0

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

func (*Event) ModelOfMap added in v1.11.0

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

func (*Event) Query added in v1.11.0

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

func (*Event) SetAttribute added in v1.11.0

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

type Gorm added in v1.12.0

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

type GormImpl added in v1.12.0

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

func InitializeGorm added in v1.12.0

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

func NewGormImpl added in v1.12.0

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

func (*GormImpl) Make added in v1.12.0

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

type Having added in v1.13.5

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

type House added in v1.13.5

type House struct {
	orm.Model
	Name          string
	HouseableID   uint
	HouseableType string
}

func (*House) Factory added in v1.13.5

func (h *House) Factory() string

type Initialize added in v1.13.0

type Initialize interface {
	InitializeGorm(config config.Config, connection string) *GormImpl
	InitializeQuery(ctx context.Context, config config.Config, connection string) (*QueryImpl, error)
}

type InitializeImpl added in v1.13.0

type InitializeImpl struct{}

func NewInitializeImpl added in v1.13.0

func NewInitializeImpl() *InitializeImpl

func (*InitializeImpl) InitializeGorm added in v1.13.0

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

func (*InitializeImpl) InitializeQuery added in v1.13.0

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

type Join added in v1.13.5

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

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 added in v1.12.0

func NewMysqlDocker() *MysqlDocker

func (*MysqlDocker) Init added in v1.12.0

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

func (*MysqlDocker) MockReadWrite added in v1.12.0

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

func (*MysqlDocker) New added in v1.12.0

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

func (*MysqlDocker) Query added in v1.12.0

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

func (*MysqlDocker) QueryWithPrefixAndSingular added in v1.12.0

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

type People added in v1.13.5

type People struct {
	orm.Model
	orm.SoftDeletes
	Body string
}

func (*People) Connection added in v1.13.5

func (p *People) Connection() string

type Person added in v1.13.5

type Person struct {
	orm.Model
	orm.SoftDeletes
	Name string
}

func (*Person) Connection added in v1.13.5

func (p *Person) Connection() string

type Phone added in v1.13.5

type Phone struct {
	orm.Model
	Name          string
	PhoneableID   uint
	PhoneableType string
}

type PostgresqlDocker

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

func NewPostgresqlDocker added in v1.12.0

func NewPostgresqlDocker() *PostgresqlDocker

func (*PostgresqlDocker) Init added in v1.12.0

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

func (*PostgresqlDocker) MockReadWrite added in v1.12.0

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

func (*PostgresqlDocker) New added in v1.12.0

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

func (*PostgresqlDocker) Query added in v1.12.0

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

func (*PostgresqlDocker) QueryWithPrefixAndSingular added in v1.12.0

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

type Product added in v1.13.5

type Product struct {
	orm.Model
	orm.SoftDeletes
	Name string
}

func (*Product) Connection added in v1.13.5

func (p *Product) Connection() string

type QueryImpl added in v1.12.0

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

func BuildQueryImpl added in v1.13.5

func BuildQueryImpl(ctx context.Context, config config.Config, connection string, gorm Gorm) (*QueryImpl, error)

func InitializeQuery added in v1.12.0

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

func NewQueryImpl added in v1.12.0

func NewQueryImpl(ctx context.Context, config config.Config, connection string, db *gormio.DB, conditions *Conditions) *QueryImpl

func (*QueryImpl) Association added in v1.12.0

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

func (*QueryImpl) Begin added in v1.12.0

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

func (*QueryImpl) Count added in v1.12.0

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

func (*QueryImpl) Create added in v1.12.0

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

func (*QueryImpl) Cursor added in v1.13.0

func (r *QueryImpl) Cursor() (chan ormcontract.Cursor, error)

func (*QueryImpl) Delete added in v1.12.0

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

func (*QueryImpl) Distinct added in v1.12.0

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

func (*QueryImpl) Driver added in v1.12.0

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

func (*QueryImpl) Exec added in v1.12.0

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

func (*QueryImpl) Find added in v1.12.0

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

func (*QueryImpl) FindOrFail added in v1.12.0

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

func (*QueryImpl) First added in v1.12.0

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

func (*QueryImpl) FirstOr added in v1.12.0

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

func (*QueryImpl) FirstOrCreate added in v1.12.0

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

func (*QueryImpl) FirstOrFail added in v1.12.0

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

func (*QueryImpl) FirstOrNew added in v1.12.0

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

func (*QueryImpl) ForceDelete added in v1.12.0

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

func (*QueryImpl) Get added in v1.12.0

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

func (*QueryImpl) Group added in v1.12.0

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

func (*QueryImpl) Having added in v1.12.0

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

func (*QueryImpl) Instance added in v1.12.0

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

func (*QueryImpl) Join added in v1.12.0

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

func (*QueryImpl) Limit added in v1.12.0

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

func (*QueryImpl) Load added in v1.12.0

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

func (*QueryImpl) LoadMissing added in v1.12.0

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

func (*QueryImpl) LockForUpdate added in v1.12.0

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

func (*QueryImpl) Model added in v1.12.0

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

func (*QueryImpl) Offset added in v1.12.0

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

func (*QueryImpl) Omit added in v1.12.0

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

func (*QueryImpl) OrWhere added in v1.12.0

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

func (*QueryImpl) Order added in v1.12.0

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

func (*QueryImpl) Paginate added in v1.12.0

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

func (*QueryImpl) Pluck added in v1.12.0

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

func (*QueryImpl) Raw added in v1.12.0

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

func (*QueryImpl) Save added in v1.12.0

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

func (*QueryImpl) SaveQuietly added in v1.12.0

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

func (*QueryImpl) Scan added in v1.12.0

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

func (*QueryImpl) Scopes added in v1.12.0

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

func (*QueryImpl) Select added in v1.12.0

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

func (*QueryImpl) SetContext added in v1.13.8

func (r *QueryImpl) SetContext(ctx context.Context)

func (*QueryImpl) SharedLock added in v1.12.0

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

func (*QueryImpl) Sum added in v1.13.0

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

func (*QueryImpl) Table added in v1.12.0

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

func (*QueryImpl) Update added in v1.12.0

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

func (*QueryImpl) UpdateOrCreate added in v1.12.0

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

func (*QueryImpl) Where added in v1.12.0

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

func (*QueryImpl) With added in v1.12.0

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

func (*QueryImpl) WithTrashed added in v1.12.0

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

func (*QueryImpl) WithoutEvents added in v1.12.0

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

type Review added in v1.13.5

type Review struct {
	orm.Model
	orm.SoftDeletes
	Body string
}

func (*Review) Connection added in v1.13.5

func (r *Review) Connection() string

type Role added in v1.13.5

type Role struct {
	orm.Model
	Name  string
	Users []*User `gorm:"many2many:role_user"`
}

type Select added in v1.13.5

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

type SqliteDocker

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

func NewSqliteDocker added in v1.12.0

func NewSqliteDocker(dbName string) *SqliteDocker

func (*SqliteDocker) Init added in v1.12.0

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

func (*SqliteDocker) MockReadWrite added in v1.12.0

func (r *SqliteDocker) MockReadWrite()

func (*SqliteDocker) New added in v1.12.0

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

func (*SqliteDocker) Query added in v1.12.0

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

func (*SqliteDocker) QueryWithPrefixAndSingular added in v1.12.0

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

type SqlserverDocker

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

func NewSqlserverDocker added in v1.12.0

func NewSqlserverDocker() *SqlserverDocker

func (*SqlserverDocker) Init added in v1.12.0

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

func (*SqlserverDocker) MockReadWrite added in v1.12.0

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

func (*SqlserverDocker) New added in v1.12.0

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

func (*SqlserverDocker) Query added in v1.12.0

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

func (*SqlserverDocker) QueryWithPrefixAndSingular added in v1.12.0

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

type Table added in v1.12.0

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

type Tables added in v1.13.5

type Tables struct {
}

func (Tables) Create added in v1.13.5

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

func (Tables) CreateWithPrefixAndSingular added in v1.13.5

func (r Tables) 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, config config.Config, connection string) *Transaction

func (*Transaction) Commit

func (r *Transaction) Commit() error

func (*Transaction) Rollback

func (r *Transaction) Rollback() error

type User added in v1.13.5

type User struct {
	orm.Model
	orm.SoftDeletes
	Name    string
	Avatar  string
	Address *Address
	Books   []*Book
	House   *House   `gorm:"polymorphic:Houseable"`
	Phones  []*Phone `gorm:"polymorphic:Phoneable"`
	Roles   []*Role  `gorm:"many2many:role_user"`
	// contains filtered or unexported fields
}

func (*User) DispatchesEvents added in v1.13.5

func (u *User) DispatchesEvents() map[ormcontract.EventType]func(ormcontract.Event) error

type Where added in v1.13.5

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

type With added in v1.13.5

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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