jackgodb

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: Unlicense Imports: 22 Imported by: 0

README

jackgodb

Extends bun to implement database ORM and DAO

Documentation

Index

Constants

View Source
const (
	DialectMySQL      = "mysql"
	DialectSQLite     = "sqlite"
	DialectPostgreSQL = "pgsql"
)
View Source
const (
	MaxOpenConns = 25
	MaxIdleConns = 25
	MaxLifetime  = 5 * time.Minute
)

Variables

View Source
var (
	StringType = reflect.TypeFor[string]()
	TimeType   = reflect.TypeFor[time.Time]()
)
View Source
var (
	SQLDebug = false
)

Functions

func AnyToInt

func AnyToInt(v any) int

func AnyToInt64

func AnyToInt64(v any) int64

func AnyToString

func AnyToString(value any) string

func AnyToTime

func AnyToTime(value any) time.Time

func ConvertTo

func ConvertTo(value any, targetType reflect.Type) (any, error)

func ParseUTCDateTime

func ParseUTCDateTime(value string) (time.Time, error)

func StringValue

func StringValue(value *string) string

Types

type DAO

type DAO struct {
	Db *bun.DB
	// contains filtered or unexported fields
}

func NewDAO

func NewDAO(db *bun.DB) *DAO

func OpenMySQLDBConnection

func OpenMySQLDBConnection(dsn string) *DAO

func OpenPostgreSQLDBConnection added in v1.2.0

func OpenPostgreSQLDBConnection(dsn string) *DAO

func OpenSQLiteDBConnection

func OpenSQLiteDBConnection(dsn string) *DAO

func (*DAO) Close

func (dao *DAO) Close()

func (*DAO) DbIn

func (dao *DAO) DbIn(start, count int) string

type DBModel

type DBModel interface {
	GetID() int64
	SetID(int64)
}

type ModelDAO

type ModelDAO[T DBModel] struct {
	Db *bun.DB
	// contains filtered or unexported fields
}

func NewModelDAO

func NewModelDAO[T DBModel](dao *DAO, alias map[string]string, newRecord func() T) *ModelDAO[T]

func (*ModelDAO[T]) Attach

func (dao *ModelDAO[T]) Attach(record T)

func (*ModelDAO[T]) AttachList

func (dao *ModelDAO[T]) AttachList(recordList []T)

func (*ModelDAO[T]) New

func (dao *ModelDAO[T]) New() T

type ModelDAOAttacher

type ModelDAOAttacher[T DBModel] interface {
	AttachModelDAO(*ModelDAO[T], T)
}

type ModelMetadata

type ModelMetadata struct {
	TableName     string         `json:"TableName,omitempty"`
	PKField       string         `json:"PKField,omitempty"`
	PKColumn      string         `json:"PKColumn,omitempty"`
	Columns       []string       `json:"Columns,omitempty"`
	FieldByColumn map[string]int `json:"FieldByColumn,omitempty"`
}

type ModelRecord

type ModelRecord[T DBModel] struct {
	Dao *ModelDAO[T]

	Self T
	// contains filtered or unexported fields
}

func (*ModelRecord[T]) AttachModelDAO

func (m *ModelRecord[T]) AttachModelDAO(dao *ModelDAO[T], self T)

func (*ModelRecord[T]) Clean

func (m *ModelRecord[T]) Clean()

func (*ModelRecord[T]) Delete

func (m *ModelRecord[T]) Delete() int64

func (*ModelRecord[T]) Dirty

func (m *ModelRecord[T]) Dirty(column string)

func (*ModelRecord[T]) FromAPI

func (m *ModelRecord[T]) FromAPI(apiData map[string]any) T

func (*ModelRecord[T]) GetID

func (m *ModelRecord[T]) GetID() int64

func (*ModelRecord[T]) GetModelMetadata

func (m *ModelRecord[T]) GetModelMetadata() *ModelMetadata

func (*ModelRecord[T]) GetValue

func (m *ModelRecord[T]) GetValue(columnName string) any

func (*ModelRecord[T]) Insert

func (m *ModelRecord[T]) Insert() int64

func (*ModelRecord[T]) InsertIgnore

func (m *ModelRecord[T]) InsertIgnore() int64

func (*ModelRecord[T]) IsClean

func (m *ModelRecord[T]) IsClean() bool

func (*ModelRecord[T]) IsDirty

func (m *ModelRecord[T]) IsDirty() bool

func (*ModelRecord[T]) Load

func (m *ModelRecord[T]) Load(id int64) T

func (*ModelRecord[T]) Save

func (m *ModelRecord[T]) Save() int64

func (*ModelRecord[T]) SetID

func (m *ModelRecord[T]) SetID(id int64)

func (*ModelRecord[T]) SetValue

func (m *ModelRecord[T]) SetValue(columnName string, value any) bool

func (*ModelRecord[T]) ToAPI

func (m *ModelRecord[T]) ToAPI() map[string]any

func (*ModelRecord[T]) ToWhere

func (m *ModelRecord[T]) ToWhere(query *bun.SelectQuery, args map[string]any) *bun.SelectQuery

func (*ModelRecord[T]) Update

func (m *ModelRecord[T]) Update() int64

Directories

Path Synopsis
cmd
jackgodb command
modelgen command
internal

Jump to

Keyboard shortcuts

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