gorms

package module
v0.0.0-...-a7d8d75 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: MIT Imports: 9 Imported by: 1 module, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

gorms

use gorm.DB anywhere!

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GlobalDB = make(Manager)

Functions

func Caller

func Caller(skip int) (file string)

Caller returns the file path where this function is called.

The `skip` parameter has a default value 1.

func Close

func Close() error

func Exists

func Exists[T any](conds ...any) bool

func Find

func Find[T any, V any](conds ...any) (dest []T, v V)

func First

func First[T any, V any](conds ...any) (*T, V)

func FirstOrCreate

func FirstOrCreate[T any](x *T, conds ...any) caller

func Found

func Found(err error) bool
func Link(relative string)

Link links the DB represented by the relative path to the caller path.

func MustFind

func MustFind[T any](conds ...any) (dest []T)

func MustFirst

func MustFirst[T any](conds ...any) (dest *T)

func MustPreload

func MustPreload[T any](conds ...any) (dest *T)

func MustPreloads

func MustPreloads[T any](conds ...any) (dest []T)

func Preload

func Preload[T any, V any](conds ...any) (*T, V)

func Preloads

func Preloads[T any, V any](conds ...any) (dest []T, v V)

Types

type DB

type DB struct {
	*gorm.DB
	// contains filtered or unexported fields
}

Superset of gorm.DB

func AutoMigrate

func AutoMigrate(dst ...any) *DB

func Get

func Get() *DB

Get returns the DB represented by the caller path.

func NewDB

func NewDB(file string, gormDB *gorm.DB) *DB

func Relative

func Relative(elem string) *DB

Relative returns the DB represented by the path relative to the caller path.

func Select

func Select(fields ...string) *DB

func SetDialector

func SetDialector(dialector gorm.Dialector, opts ...gorm.Option) *DB

func SetGormDB

func SetGormDB(gormDB *gorm.DB) (db *DB)

func SetSQLite

func SetSQLite(file string, opts ...gorm.Option) *DB

func (*DB) AutoMigrate

func (db *DB) AutoMigrate(dst ...any) *DB

func (*DB) Clone

func (db *DB) Clone() *DB

func (*DB) Close

func (db *DB) Close() error

Close fetch the original sql.DB and attempt to close it.

It returns nil if the DB has been closed successfully.

Otherwise an error will be returned.

func (*DB) Debug

func (db *DB) Debug() *DB

func (*DB) Do

func (db *DB) Do(fn func(db *DB)) *DB

func (*DB) Error

func (db *DB) Error() error

func (*DB) File

func (db *DB) File() string

func (*DB) Find

func (db *DB) Find(dest any, conds ...any) *DB

func (*DB) FindOK

func (db *DB) FindOK(dest any, conds ...any) bool

func (*DB) First

func (db *DB) First(dest any, conds ...any) *DB

func (*DB) FirstOK

func (db *DB) FirstOK(dest any, conds ...any) bool

func (*DB) FirstOrCreate

func (db *DB) FirstOrCreate(x any, conds ...any) caller

func (*DB) Found

func (db *DB) Found() bool

Found returns whether record is found.

func (*DB) GetInstance

func (db *DB) GetInstance(r *gorm.DB) *DB

func (*DB) PkgPath

func (db *DB) PkgPath() string

PkgPath returns package path where this DB is created.

func (*DB) Preload

func (db *DB) Preload(t any, conds ...any) *DB

func (*DB) PreloadOK

func (db *DB) PreloadOK(t any, conds ...any) bool

func (*DB) PreloadType

func (db *DB) PreloadType(in any, m map[string][]any) (tx *DB)

func (*DB) Preloads

func (db *DB) Preloads(t any, conds ...any) *DB

func (*DB) PreloadsOK

func (db *DB) PreloadsOK(t any, conds ...any) bool

func (*DB) Select

func (db *DB) Select(fields ...string) (tx *DB)

func (*DB) Succeed

func (db *DB) Succeed() bool

type Manager

type Manager map[string]*DB

func (Manager) Get

func (m Manager) Get(file string) *DB

Get returns the DB represented by the given file path.

func (Manager) Set

func (m Manager) Set(db *DB, pkg ...string)

Set sets the DB in different paths.

type Model

type Model[T constraints.Integer] struct {
	ID T `gorm:"primaryKey;autoIncrement" json:"id" yaml:"id" form:"id"`
}

type Parser

type Parser int

func (Parser) Parse

func (Parser) Parse(ref *Reflect.Map[[]string], elem reflect.Type) (r []string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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