gorm

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: MIT Imports: 17 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v0.2.7

type Config struct {
	Logger           glog.ILoggerEntry
	TracerServer     *tracer.Server
	Attrs            []attribute.KeyValue
	ExcludeQueryVars bool
	ExcludeMetrics   bool
	QueryFormatter   func(query string) string
}

func NewPlugin

func NewPlugin(plugin *Config) *Config

func (*Config) Initialize added in v0.2.7

func (p *Config) Initialize(db *gorm.DB) (err error)

func (*Config) Name added in v0.2.7

func (p *Config) Name() string

type DB added in v0.2.1

type DB struct {
	Client *gorm.DB
}

func (*DB) Assign added in v0.2.1

func (db *DB) Assign(attrs ...interface{}) db.IDB

func (*DB) Attrs added in v0.2.1

func (db *DB) Attrs(attrs ...interface{}) db.IDB

func (*DB) Distinct added in v0.2.1

func (db *DB) Distinct(args ...interface{}) db.IDB

Distinct specify distinct fields that you want querying

func (*DB) Group added in v0.2.1

func (db *DB) Group(name string) db.IDB

Group specify the group method on the find

func (*DB) Having added in v0.2.1

func (db *DB) Having(query interface{}, args ...interface{}) db.IDB

Having specify HAVING conditions for GROUP BY

func (*DB) Joins added in v0.2.1

func (db *DB) Joins(query string, args ...interface{}) db.IDB

Joins specify Joins conditions

db.Joins("Account").Find(&user)
db.Joins("JOIN emails ON emails.user_id = users.id AND emails.email = ?", "jinzhu@example.org").Find(&user)
db.Joins("Account", DB.Select("id").Where("user_id = users.id AND name = ?", "someName").Model(&Account{}))

func (*DB) Limit added in v0.2.1

func (db *DB) Limit(limit int) db.IDB

Limit specify the number of records to be retrieved

func (*DB) Model added in v0.2.1

func (db *DB) Model(value interface{}) db.IDB

Model specify the model you would like to run db operations

// update all users is name to `hello`
db.Model(&User{}).Update("name", "hello")
// if user's primary key is non-blank, will use it as condition, then will only update the user's name to `hello`
db.Model(&user).Update("name", "hello")

func (*DB) Not added in v0.2.1

func (db *DB) Not(query interface{}, args ...interface{}) db.IDB

Not add NOT conditions

func (*DB) Offset added in v0.2.1

func (db *DB) Offset(offset int) db.IDB

Offset specify the number of records to skip before starting to return the records

func (*DB) Omit added in v0.2.1

func (db *DB) Omit(columns ...string) db.IDB

Omit specify fields that you want to ignore when creating, updating and querying

func (*DB) Or added in v0.2.1

func (db *DB) Or(query interface{}, args ...interface{}) db.IDB

Or add OR conditions

func (*DB) Order added in v0.2.1

func (db *DB) Order(value interface{}) db.IDB

Order specify order when retrieve records from database

db.Order("name DESC")
db.Order(clause.OrderByColumn{Column: clause.Column{Name: "name"}, Desc: true})

func (*DB) Preload added in v0.2.1

func (db *DB) Preload(query string, args ...interface{}) db.IDB

Preload associations with given conditions

db.Preload("Orders", "state NOT IN (?)", "cancelled").Find(&users)

func (*DB) Raw added in v0.2.1

func (db *DB) Raw(sql string, values ...interface{}) db.IDB

func (*DB) Select added in v0.2.1

func (db *DB) Select(query interface{}, args ...interface{}) db.IDB

Select specify fields that you want when querying, creating, updating

func (*DB) Table added in v0.2.1

func (db *DB) Table(name string, args ...interface{}) db.IDB

Table specify the table you would like to run db operations

func (*DB) Unscoped added in v0.2.1

func (db *DB) Unscoped() db.IDB

func (*DB) Where added in v0.2.1

func (db *DB) Where(query interface{}, args ...interface{}) db.IDB

Where add conditions

type LogSql

type LogSql struct {
	SlowThreshold             time.Duration
	IgnoreRecordNotFoundError bool
	Logger                    glog.ILoggerEntry
}

func (*LogSql) Error

func (l *LogSql) Error(ctx context.Context, msg string, data ...interface{})

func (*LogSql) Info

func (l *LogSql) Info(ctx context.Context, msg string, data ...interface{})

func (*LogSql) LogMode

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

func (*LogSql) Trace

func (l *LogSql) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error)

func (*LogSql) Warn

func (l *LogSql) Warn(ctx context.Context, msg string, data ...interface{})

Jump to

Keyboard shortcuts

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