orm

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HookBefore = "before"
	HookAfter  = "after"
	HookError  = "error"
)
View Source
const (
	ErrDatabaseAlreadyExists = errors.String("database already exists")
	ErrDatabaseNotFound      = errors.String("database not found")
	ErrDatabaseNotOpen       = errors.String("database not open")
	ErrDatabaseNotClosed     = errors.String("database not closed")
	ErrDatabaseNotConnected  = errors.String("database not connected")
	ErrDatabaseNotConnecting = errors.String("database not connecting")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Context      context.Context
	Debug        bool
	Once         bool // use once for close db,when connector used same driver
	Names        []string
	Connector    Connector            // use for single database
	Connectors   map[string]Connector // use for multi database, if needed
	Dialect      string               // mysql/postgres/sqlite3/...
	ORM          string               // gorm,ent,xorm,...
	DSN          string
	MaxLifetime  int
	MaxIdleTime  int
	MaxOpenConns int
	MaxIdleConns int
	Hooks        map[string]Hook
}

type Connector

type Connector interface {
	Open(config Config) (any, error)
	Close() error
}

type Hook

type Hook func(dsn string) error

type ORM

type ORM interface {
	Config() Config
	Connect(name string, connector Connector) error
	DB(name string) any
	Close() error
}

func New

func New(config Config) (ORM, error)

New creates a new ORM instance.

Jump to

Keyboard shortcuts

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