gorm2

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: May 26, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPlugin

func NewPlugin(plugin *sqlConfig) *sqlConfig

func WithOmitVariablesFromTrace

func WithOmitVariablesFromTrace(ctx context.Context) context.Context

Types

type Client

type Client struct {
	Client map[string]*gorm.DB
	// contains filtered or unexported fields
}

func NewDb

func NewDb(opts ...Option) *Client

func (*Client) DB

func (c *Client) DB(dbName ...string) (conn *gorm.DB)

type DB

type DB struct {
	Client *gorm.DB
}

func (*DB) Assign

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

func (*DB) Attrs

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

func (*DB) Distinct

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

Distinct specify distinct fields that you want querying

func (*DB) Group

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

Group specify the group method on the find

func (*DB) Having

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

Having specify HAVING conditions for GROUP BY

func (*DB) Joins

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

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

Limit specify the number of records to be retrieved

func (*DB) Model

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

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

Not add NOT conditions

func (*DB) Offset

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

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

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

func (*DB) Or

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

Or add OR conditions

func (*DB) Order

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

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

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

func (*DB) Select

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

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

func (*DB) Table

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

Table specify the table you would like to run db operations

func (*DB) Unscoped

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

func (*DB) Where

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

Where add conditions

type LogSql

type LogSql struct {
	Logger glog.ILogger
	// contains filtered or unexported fields
}

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{})

type Option

type Option func(p *config)

func WithAttributes

func WithAttributes(attrs ...attribute.KeyValue) Option

WithAttributes configures attributes that are used to create a span.

func WithConnMaxIdleTime

func WithConnMaxIdleTime(connMaxIdleTime time.Duration) Option

WithConnMaxIdleTime connMaxIdleTime

func WithDBName

func WithDBName(name string) Option

WithDBName configures a db.name attribute.

func WithDNS

func WithDNS(dsn map[string]string) Option

WithDNS dsn

func WithDefaultStringSize

func WithDefaultStringSize(defaultStringSize uint) Option

WithDefaultStringSize defaultStringSize

func WithDisableDatetimePrecision

func WithDisableDatetimePrecision(disableDatetimePrecision bool) Option

WithDisableDatetimePrecision disableDatetimePrecision

func WithDontSupportRenameColumn

func WithDontSupportRenameColumn(dontSupportRenameColumn bool) Option

WithDontSupportRenameColumn dontSupportRenameColumn

func WithDontSupportRenameIndex

func WithDontSupportRenameIndex(dontSupportRenameIndex bool) Option

WithDontSupportRenameIndex dontSupportRenameIndex

func WithIgnoreRecordNotFoundError

func WithIgnoreRecordNotFoundError(ignoreRecordNotFoundError bool) Option

WithIgnoreRecordNotFoundError ignoreRecordNotFoundError

func WithLogger

func WithLogger(logger glog.ILogger) Option

WithLogger prevents logger.

func WithMaxIdleCons

func WithMaxIdleCons(maxIdleCons int) Option

WithMaxIdleCons maxIdleCons

func WithMaxOpenCons

func WithMaxOpenCons(maxOpenCons int) Option

WithMaxOpenCons maxOpenCons

func WithQueryFormatter

func WithQueryFormatter(queryFormatter func(query string) string) Option

WithQueryFormatter configures a query formatter

func WithSkipInitializeWithVersion

func WithSkipInitializeWithVersion(skipInitializeWithVersion bool) Option

WithSkipInitializeWithVersion skipInitializeWithVersion

func WithSlowThreshold

func WithSlowThreshold(slowThreshold time.Duration) Option

WithSlowThreshold slowThreshold

func WithTracer

func WithTracer(tracerServer *tracer.Server) Option

WithTracer tracerServer tracer.Server

func WithoutMetrics

func WithoutMetrics() Option

WithoutMetrics prevents DBStats metrics from being reported.

func WithoutQueryVariables

func WithoutQueryVariables() Option

WithoutQueryVariables configures the db.statement attribute to exclude query variables

Jump to

Keyboard shortcuts

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