db

package
v0.0.0-...-221f2c5 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package db code

Index

Constants

This section is empty.

Variables

View Source
var CreatedFiledName = "created_time"
View Source
var DateTimeFormat = "2006-01-02 15:04:05"
View Source
var DeletedFiledName = "deleted_time"
View Source
var UpdatedFiledName = "updated_time"

Functions

func New

func New(cfg Config) (*gorm.DB, func())

New just like Open

func Open

func Open(conf Config) (*gorm.DB, func())

Open the database connection

func RegisterCallback

func RegisterCallback(db *gorm.DB)

func Trace

func Trace(ctx context.Context, db *gorm.DB) *gorm.DB

Trace return clone DB with trace ctx

Types

type CUDTime

type CUDTime struct {
	CreatedTime DateTime `json:"created_time"`
	UpdatedTime DateTime `json:"updated_time"`
	DeletedTime DateTime `json:"deleted_time"`
}

type Config

type Config struct {
	Dsn         string `yaml:"dsn"`
	MaxIdle     int    `yaml:"maxIdle"`
	MaxOpen     int    `yaml:"maxOpen"`
	MaxLifetime int    `yaml:"maxLifetime"`
	LogMode     bool   `yaml:"logMode"`
}

Config the db config

type DateTime

type DateTime struct {
	time.Time
}

func (DateTime) MarshalJSON

func (t DateTime) MarshalJSON() ([]byte, error)

func (*DateTime) Scan

func (t *DateTime) Scan(v interface{}) error

func (DateTime) Value

func (t DateTime) Value() (driver.Value, error)

type Entity

type Entity struct {
	ID int64 `gorm:"primary_key" json:"id"`
}

type Repository

type Repository struct {
	DB *gorm.DB
}

func (*Repository) Create

func (d *Repository) Create(ctx context.Context, entity interface{}) error

func (*Repository) CreateTx

func (d *Repository) CreateTx(ctx context.Context, tx *gorm.DB, entity interface{}) error

func (*Repository) Delete

func (d *Repository) Delete(ctx context.Context, entity interface{}, where ...interface{}) error

func (*Repository) DeleteTx

func (d *Repository) DeleteTx(ctx context.Context, tx *gorm.DB, entity interface{}, where ...interface{}) error

func (*Repository) Find

func (d *Repository) Find(ctx context.Context, tx *gorm.DB, entity interface{}, out interface{}, limit interface{}, offset interface{}, where ...interface{}) (interface{}, error)

func (*Repository) FindTx

func (d *Repository) FindTx(ctx context.Context, tx *gorm.DB, entity interface{}, out interface{}, limit interface{}, offset interface{}, where ...interface{}) (interface{}, error)

func (*Repository) Save

func (d *Repository) Save(ctx context.Context, entity interface{}) error

func (*Repository) SaveTx

func (d *Repository) SaveTx(ctx context.Context, tx *gorm.DB, entity interface{}) error

Jump to

Keyboard shortcuts

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