Documentation
¶
Index ¶
- Constants
- Variables
- func CamelToUnderscore(camelCase string) string
- func DbField(ent Entity, fieldName string) string
- func FindAll[T any](call Rs) ([]T, error)
- func GetStructFieldNames(v any) []string
- func GetStructFieldNamesWithExclude(v any, excludeNames []string) []string
- func GetStructFieldValues(v any, fieldList []string) []any
- func HasBasedType(t reflect.Type, targetType reflect.Type) bool
- func IsNilPointer(v any) bool
- func IsPointer(v any) bool
- func ListTo[T any](values []Entity) ([]T, error)
- func NewEntity[T Entity](ent T) T
- func PointerReadVal[T any](p Pointer, val *T) (bool, error)
- func PointerVal[T any](p Pointer) (T, error)
- func To[T any](value Entity) (T, error)
- type Base
- func (e *Base) Compound(name string) Entity
- func (e *Base) Compounds() []Entity
- func (e *Base) Entity() Entity
- func (e *Base) Field(fieldName string) (string, bool)
- func (e *Base) Fields() []string
- func (e *Base) GetBase() *Base
- func (e *Base) Id() int64
- func (e *Base) IdAddr() any
- func (e *Base) Init()
- func (e *Base) InitialId() int64
- func (e *Base) Name(fieldName string) string
- func (e *Base) Names() []string
- func (e *Base) New() Entity
- func (e *Base) Pointer(fieldName string) (Pointer, bool)
- func (e *Base) Pointers() []Pointer
- func (e *Base) SetId(id int64)
- func (e *Base) Type(fieldName string) (*reflect.Type, bool)
- func (e *Base) Types() []reflect.Type
- func (e *Base) Value(fieldName string) (any, bool)
- func (e *Base) Values() []any
- type BaseModel
- func (m *BaseModel) ApplyOnRow(e *Base) bool
- func (m *BaseModel) ApplyOnRowCompound(e *Base)
- func (m *BaseModel) ApplyOnRows(rows *sql.Rows, ent Entity) ([]Entity, error)
- func (m *BaseModel) CheckValidPointer(ent Entity, ptr any) int
- func (m *BaseModel) DbGetListFields(e *Base) []string
- func (m *BaseModel) DbInsert(ent Entity) (bool, error)
- func (m *BaseModel) DbOnConflictUpdateFields(e *Base) string
- func (m *BaseModel) DbOnInsert(rs sql.Result, e *Base) (bool, error)
- func (m *BaseModel) DbPrepareAllFields(e *Base) string
- func (m *BaseModel) DbPrepareFields(e *Base) string
- func (m *BaseModel) DbPrepareInsert(e *Base, tableName string) (*sql.Stmt, error)
- func (m *BaseModel) DbPrepareInsertFields(e *Base) string
- func (m *BaseModel) DbPrepareValues(e *Base) string
- func (m *BaseModel) DbReceivValues(e *Base) []any
- func (m *BaseModel) DbResolvValues(e *Base) []any
- func (m *BaseModel) FilterFields(e *Base, list []string) []string
- func (m *BaseModel) FindAll(ent Entity, limit int, index int) ([]Entity, error)
- func (m *BaseModel) FindAllById(ent Entity, dir OrderDir, limit int, index int) ([]Entity, error)
- func (m *BaseModel) FindById(ent Entity) bool
- func (m *BaseModel) FindOneBy(ent Entity, ptr any) bool
- func (m *BaseModel) GetFieldOps(ent Entity) []FieldOpDef
- func (m *BaseModel) RegisterFieldOp(typ reflect.Type, name string, isPreOp bool, op PointerOp)
- type Entity
- type FieldOp
- type FieldOpDef
- type FuncDef
- type OrderDir
- type OrderEntry
- type Pointer
- type PointerOp
- type Prefix
- type QueryOrder
- type Rs
- type SqliteDb
- type SqliteFmt
- func (f *SqliteFmt) OnConflictUpdateFields(fields []string) string
- func (f *SqliteFmt) PrefixField(fieldName string, alias string) string
- func (f *SqliteFmt) PrefixFields(fields []string, alias string) []string
- func (f *SqliteFmt) PrefixList(fields []string, alias string) string
- func (f *SqliteFmt) Quote(val string) string
- func (f *SqliteFmt) QuoteList(fields []string) string
- func (f *SqliteFmt) TableAlias(tableName string, alias string) string
- type StrDate
- type StrTime
Constants ¶
const ( BaseType = "Base" Unknowned = "__unknowned__" DateLayout = "2006-01-02" TimeLayout = "2006-01-02 15:04:05.999999999 -0700 MST" )
Variables ¶
Functions ¶
func CamelToUnderscore ¶
Transform entity field in db field
func GetStructFieldNames ¶
func GetStructFieldValues ¶
func HasBasedType ¶
Check if specified type embed specified target type
func PointerReadVal ¶ added in v0.0.37
Fill specified value with specified Pointer value
func PointerVal ¶
Dereference specified Pointer as specified T <any> type value
Types ¶
type Base ¶
type Base struct {
// contains filtered or unexported fields
}
Base Entity structure defining an abstract entity
type BaseModel ¶
type BaseModel struct { Db *SqliteDb Prefix *Prefix ListOpDef []FieldOpDef }
func NewBaseModel ¶
func (*BaseModel) ApplyOnRow ¶
func (*BaseModel) ApplyOnRowCompound ¶ added in v0.0.17
func (*BaseModel) ApplyOnRows ¶
func (*BaseModel) CheckValidPointer ¶
func (*BaseModel) DbGetListFields ¶
func (*BaseModel) DbOnConflictUpdateFields ¶ added in v0.0.32
func (*BaseModel) DbPrepareAllFields ¶
func (*BaseModel) DbPrepareFields ¶
func (*BaseModel) DbPrepareInsert ¶
func (*BaseModel) DbPrepareInsertFields ¶
func (*BaseModel) DbPrepareValues ¶
func (*BaseModel) DbReceivValues ¶
func (*BaseModel) DbResolvValues ¶
func (*BaseModel) FindAllById ¶
func (*BaseModel) GetFieldOps ¶ added in v0.0.27
func (m *BaseModel) GetFieldOps(ent Entity) []FieldOpDef
type Entity ¶
type Entity interface { Compounds() []Entity Compound(name string) Entity Entity() Entity Field(fieldName string) (string, bool) Fields() []string GetBase() *Base Id() int64 IdAddr() any Init() InitialId() int64 Names() []string New() Entity Pointer(fieldName string) (Pointer, bool) Pointers() []Pointer SetId(id int64) Type(fieldName string) (*reflect.Type, bool) Types() []reflect.Type Value(fieldName string) (any, bool) Values() []any }
Entity interface. The Base Struct implements this interface. In order to use a custom entity struct, you should declare a struct type that embed the *liteMng.Base type, as is, without naming a field. Then you should declare your fields as exportable variables (Beginning with UpperCase)
example :
type Session struct { *liteMng.Base Uuid string Data string Updated liteMng.StrTime }
Before using your entity you should register it to the liteMng.Registry and specify the related table name :
liteMng.Registry.RegisterTable(&Session{}, "session")
Then you can use the liteMng.NewEntity function to get a new instance. New instances should be a pointer of your struct :
s := lm.NewEntity(&Session{})
type FieldOp ¶ added in v0.0.20
type FieldOp struct {
// contains filtered or unexported fields
}
Struct representing nature of Field & operation
type FieldOpDef ¶ added in v0.0.20
type FieldOpDef struct {
// contains filtered or unexported fields
}
Struct representing a FieldOp definition
type OrderEntry ¶
func (*OrderEntry) Resolve ¶
func (e *OrderEntry) Resolve() string
type Pointer ¶
Convenient struct to manage arbitrary type via pointer and reflection
type Prefix ¶
type Prefix struct {
// contains filtered or unexported fields
}
Structure managing Prefix Fields
type QueryOrder ¶
type QueryOrder struct { Entries []OrderEntry Limit int Index int }
func NewQueryOrder ¶
func NewQueryOrder(limit int, index int) *QueryOrder
func (*QueryOrder) NewEntry ¶
func (o *QueryOrder) NewEntry(dir OrderDir, fieldName string)
func (*QueryOrder) NewEntryPfx ¶
func (o *QueryOrder) NewEntryPfx(dir OrderDir, fieldName string, prefix string)
func (*QueryOrder) Resolve ¶
func (o *QueryOrder) Resolve() string
type SqliteDb ¶
type SqliteDb struct { Debug bool // contains filtered or unexported fields }
struct to manage sqlite connection
type SqliteFmt ¶
type SqliteFmt struct { FieldListSep string // field list separator FieldQuote string // field quote FieldSep string // field & table alias separator }
SqliteFmt is an utility struct that help managing sqlite formating
func (*SqliteFmt) OnConflictUpdateFields ¶ added in v0.0.32
Give query fields update list on conflict update [sqlite UPSERT]
func (*SqliteFmt) PrefixField ¶
Prefix specified fieldName with given table alias prefix
func (*SqliteFmt) PrefixFields ¶
prefix specified fields list with given table alias prefix as a string array
func (*SqliteFmt) PrefixList ¶
prefix specified fields list with given table alias prefix as a string
type StrDate ¶
type StrDate struct {
// contains filtered or unexported fields
}
Convenient Struct to manage Sqlite Date field
func NewStrDate ¶
StrDate constructor initialized with specified date <string>
func (*StrDate) GetStrPointer ¶
Give a pointer on val field as any
type StrTime ¶
type StrTime struct {
// contains filtered or unexported fields
}
Convenient Struct to manage Sqlite DateTime field
func NewStrTime ¶
StrTime constructor initialized with specified time.Time
func (*StrTime) GetStrPointer ¶
Give a pointer on value field as any