Documentation ¶
Index ¶
- Constants
- Variables
- func FromContext(ctx context.Context) *gorm.DB
- func LogrusLogger(config logger.Config) logger.Interface
- func MustOpen(c Config, options ...GORMOption) *gorm.DB
- func Open(c Config, options ...GORMOption) (*gorm.DB, error)
- func OpenMemory(options ...GORMOption) (*gorm.DB, error)
- func RegisterDriver(name string, driver Driver)
- func StdLogger(level ...logger.LogLevel) logger.Interface
- func Tx(ctx context.Context, f func(ctx context.Context) error) error
- func WithContext(ctx context.Context, db *gorm.DB) context.Context
- type Config
- type Driver
- type Duration
- type GORMOption
- func WithAllowGlobalUpdate(AllowGlobalUpdate bool) GORMOption
- func WithClauseBuilders(ClauseBuilders map[string]clause.ClauseBuilder) GORMOption
- func WithConnPool(ConnPool gorm.ConnPool) GORMOption
- func WithCreateBatchSize(CreateBatchSize int) GORMOption
- func WithDisableAutomaticPing(DisableAutomaticPing bool) GORMOption
- func WithDisableForeignKeyConstraintWhenMigrating(DisableForeignKeyConstraintWhenMigrating bool) GORMOption
- func WithDisableNestedTransaction(DisableNestedTransaction bool) GORMOption
- func WithDryRun(DryRun bool) GORMOption
- func WithFullSaveAssociations(FullSaveAssociations bool) GORMOption
- func WithIgnoreRelationshipsWhenMigrating(IgnoreRelationshipsWhenMigrating bool) GORMOption
- func WithLogger(Logger logger.Interface) GORMOption
- func WithNamingStrategy(NamingStrategy schema.Namer) GORMOption
- func WithNowFunc(NowFunc func() time.Time) GORMOption
- func WithPlugins(Plugins map[string]gorm.Plugin) GORMOption
- func WithPrepareStmt(PrepareStmt bool) GORMOption
- func WithQueryFields(QueryFields bool) GORMOption
- func WithSkipDefaultTransaction(SkipDefaultTransaction bool) GORMOption
- func WithStdLogger(level ...logger.LogLevel) GORMOption
- func WithTranslateError(TranslateError bool) GORMOption
- type LogLevel
- type LoggerConfig
- type Option
- type Repository
- func (r *Repository[T]) Count(ctx context.Context, where any) (int64, error)
- func (r *Repository[T]) Delete(ctx context.Context, where any) (int64, error)
- func (r *Repository[T]) FindOne(ctx context.Context, where any) (dst *T, err error)
- func (r *Repository[T]) GetDB(ctx context.Context) *gorm.DB
- func (r *Repository[T]) Insert(ctx context.Context, data any) (int64, error)
- func (r *Repository[T]) Iterate(ctx context.Context, column string, where any) (repository.Iterator[T], error)
- func (r *Repository[T]) List(ctx context.Context, where any, offset, limit int, order ...any) ([]*T, int64, error)
- func (r *Repository[T]) SetDB(db *gorm.DB)
- func (r *Repository[T]) Update(ctx context.Context, where any, update any) (int64, error)
Constants ¶
View Source
const ( LoggerStd = "std" LoggerLogrus = "logrus" )
View Source
const ( MYSQL = "mysql" SQLITE = "sqlite" )
Variables ¶
View Source
var ErrIterationEoF = errors.New("iteration eof")
Functions ¶
func OpenMemory ¶
func OpenMemory(options ...GORMOption) (*gorm.DB, error)
func RegisterDriver ¶
Types ¶
type Config ¶
type Config struct { Driver string MaxOpenConns int MaxIdleConns int ConnMaxIdleTime Duration ConnMaxLifetime Duration Logger LoggerConfig Option Option }
func MemoryOption ¶
func MemoryOption() Config
type GORMOption ¶
func WithAllowGlobalUpdate ¶
func WithAllowGlobalUpdate(AllowGlobalUpdate bool) GORMOption
func WithClauseBuilders ¶
func WithClauseBuilders(ClauseBuilders map[string]clause.ClauseBuilder) GORMOption
func WithConnPool ¶
func WithConnPool(ConnPool gorm.ConnPool) GORMOption
func WithCreateBatchSize ¶
func WithCreateBatchSize(CreateBatchSize int) GORMOption
func WithDisableAutomaticPing ¶
func WithDisableAutomaticPing(DisableAutomaticPing bool) GORMOption
func WithDisableForeignKeyConstraintWhenMigrating ¶
func WithDisableForeignKeyConstraintWhenMigrating(DisableForeignKeyConstraintWhenMigrating bool) GORMOption
func WithDisableNestedTransaction ¶
func WithDisableNestedTransaction(DisableNestedTransaction bool) GORMOption
func WithDryRun ¶
func WithDryRun(DryRun bool) GORMOption
func WithFullSaveAssociations ¶
func WithFullSaveAssociations(FullSaveAssociations bool) GORMOption
func WithIgnoreRelationshipsWhenMigrating ¶
func WithIgnoreRelationshipsWhenMigrating(IgnoreRelationshipsWhenMigrating bool) GORMOption
func WithLogger ¶
func WithLogger(Logger logger.Interface) GORMOption
func WithNamingStrategy ¶
func WithNamingStrategy(NamingStrategy schema.Namer) GORMOption
func WithNowFunc ¶
func WithNowFunc(NowFunc func() time.Time) GORMOption
func WithPlugins ¶
func WithPlugins(Plugins map[string]gorm.Plugin) GORMOption
func WithPrepareStmt ¶
func WithPrepareStmt(PrepareStmt bool) GORMOption
func WithQueryFields ¶
func WithQueryFields(QueryFields bool) GORMOption
func WithSkipDefaultTransaction ¶
func WithSkipDefaultTransaction(SkipDefaultTransaction bool) GORMOption
func WithStdLogger ¶
func WithStdLogger(level ...logger.LogLevel) GORMOption
func WithTranslateError ¶
func WithTranslateError(TranslateError bool) GORMOption
type LoggerConfig ¶
type Repository ¶
type Repository[T any] struct { // contains filtered or unexported fields }
func NewRepository ¶
func NewRepository[T any](db *gorm.DB) *Repository[T]
func (*Repository[T]) FindOne ¶
func (r *Repository[T]) FindOne(ctx context.Context, where any) (dst *T, err error)
func (*Repository[T]) Iterate ¶
func (r *Repository[T]) Iterate(ctx context.Context, column string, where any) (repository.Iterator[T], error)
func (*Repository[T]) SetDB ¶
func (r *Repository[T]) SetDB(db *gorm.DB)
Click to show internal directories.
Click to hide internal directories.