dbo

package
v1.7.6 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Migration dbMigration
View Source
var Seeder dbSeeder

Functions

func DB

func DB(i Instance, db ...*gorm.DB) (value *gorm.DB, err error)

func NewSession

func NewSession(db *gorm.DB) *gorm.DB

Types

type DRIVER

type DRIVER string
const (
	DRIVER_MYSQL  DRIVER = "mysql"
	DRIVER_PGSQL  DRIVER = "pgsql"
	DRIVER_SQLITE DRIVER = "sqlite"
)

type ENGINE

type ENGINE string
const (
	ENGINE_INNODB ENGINE = "InnoDB"
)

type Instance

type Instance interface {
	New() *gorm.DB
	DB(db ...*gorm.DB) (value *gorm.DB, err error)
	AddMigrations(models ...any)
	AddSeeders(handlers ...SeederHandler)
	Migrate(seed ...bool) (err error)
	Seed() (err error)
}

func Connect

func Connect(opts *Options) (i Instance, err error)

func NewInstance

func NewInstance(db *gorm.DB, opts *Options) Instance

type Json

type Json[T any] struct {
	Data T
}

func (Json[T]) MarshalJSON

func (n Json[T]) MarshalJSON() ([]byte, error)

func (*Json[T]) Scan

func (n *Json[T]) Scan(value any) (err error)

func (*Json[T]) UnmarshalJSON

func (n *Json[T]) UnmarshalJSON(b []byte) error

func (Json[T]) Value

func (n Json[T]) Value() (value driver.Value, err error)

type Null

type Null[T comparable] struct {
	Data  T
	Valid bool
}

func (Null[T]) MarshalJSON

func (n Null[T]) MarshalJSON() ([]byte, error)

func (*Null[T]) Scan

func (n *Null[T]) Scan(value any) (err error)

func (*Null[T]) UnmarshalJSON

func (n *Null[T]) UnmarshalJSON(b []byte) error

func (Null[T]) Value

func (n Null[T]) Value() (driver.Value, error)

type Options

type Options struct {
	Driver    DRIVER
	Host      string
	Port      string
	Username  string
	Password  string
	DBName    string
	Charset   string
	Collation string
	DSN       string
	Engine    ENGINE
	Config    *gorm.Config
}

type Pagination

type Pagination[T any] struct {
	CurrentPage uint `json:"current_page"`
	From        uint `json:"from"`
	LastPage    uint `json:"last_page"`
	PerPage     int  `json:"per_page"`
	To          uint `json:"to"`
	Total       uint `json:"total"`
	Data        []T  `json:"data"`
}

func Paginate

func Paginate[T any](tx *gorm.DB, page uint, limit ...uint) (value *Pagination[T], err error)

type SeederHandler

type SeederHandler func(db *gorm.DB) (err error)

Jump to

Keyboard shortcuts

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