orm

package
v0.0.0-...-a98f5d9 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine is the main struct of geeorm, manages all db sessions and transactions.

func NewEngine

func NewEngine(driverName, dbName, dbSource string) (eng *Engine, err error)

NewEngine create a instance of Engine connect database and ping it to test whether it's alive.

func (*Engine) Close

func (own *Engine) Close() error

Close closes database connection.

func (*Engine) NewSession

func (own *Engine) NewSession(models ...any) *session.Session

NewSession creates a new session for next operations (recommend assigning a data model). QEMU Virtual CPU version 2.5+ eg: engine.NewSession().SetModel(&User{}) Benchmark-1 736880 1389 ns/op 904 B/op 17 allocs/op Benchmark-2 801439 1292 ns/op 904 B/op 17 allocs/op eg: engine.NewSession(&User{}) Benchmark-1 5557647 215.2 ns/op 160 B/op 3 allocs/op Benchmark-2 6056534 202.6 ns/op 160 B/op 3 allocs/op

func (*Engine) Transaction

func (own *Engine) Transaction(fn TxFunc) (result any, err error)

Transaction executes sql wrapped in a transaction, then automatically commit if no error occurs

type TxFunc

type TxFunc func(*session.Session) (any, error)

TxFunc will be called between tx.Begin() and tx.Commit()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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