Documentation
¶
Index ¶
- Variables
- func CacheHydrator(ctx context.Context) func() ([]any, error)
- func CacheSpew()
- func CacheSynchroniser(ctx context.Context) func(any) error
- func ClearDown(ctx context.Context) error
- func Close()
- func Count() (int, error)
- func CountWhere(field entities.Field, value any) (int, error)
- func Delete(ctx context.Context, id int, note string) error
- func DeleteBy(ctx context.Context, field entities.Field, value any, note string) error
- func DeleteByKey(key any) error
- func Drop() error
- func ExportAllAsCSV(msg string) error
- func ExportAllAsJSON(message string)
- func FlushCache() error
- func GetDatabaseConnections() func() ([]*database.DB, error)
- func GetDefaultLookup() (lookup.Lookup, error)
- func GetLookup(field, value entities.Field) (lookup.Lookup, error)
- func HydrateCache() error
- func ImportAllFromCSV() error
- func Initialise(ctx context.Context, cached bool)
- func IsInitialised() bool
- func PreLoad(ctx context.Context) error
- func Worker(j jobs.Job, db *database.DB)
- type TemplateStore
- func Add(ctx context.Context, sq string) (TemplateStore, error)
- func Create(ctx context.Context, userName, uid, realName, email, gid string) (TemplateStore, error)
- func GetAll() ([]TemplateStore, error)
- func GetAllWhere(field entities.Field, value any) ([]TemplateStore, error)
- func GetBy(field entities.Field, value any) (TemplateStore, error)
- func GetById(id int) (TemplateStore, error)
- func GetByKey(key string) (TemplateStore, error)
- func Login(ctx context.Context, sq string) (TemplateStore, error)
- func New() TemplateStore
- func (record *TemplateStore) Clone(ctx context.Context) (TemplateStore, error)
- func (record *TemplateStore) Create(ctx context.Context, note string) error
- func (record *TemplateStore) ExportRecordAsCSV(name string) error
- func (record *TemplateStore) ExportRecordAsJSON(name string)
- func (u *TemplateStore) SetName(name string) error
- func (record *TemplateStore) Spew()
- func (record *TemplateStore) Update(ctx context.Context, note string) error
- func (record *TemplateStore) UpdateWithAction(ctx context.Context, auditAction audit.Action, note string) error
- func (record *TemplateStore) Validate() error
Constants ¶
This section is empty.
Variables ¶
var Fields = fieldNames{
ID: "ID",
Key: "Key",
Raw: "Raw",
Audit: "Audit",
UID: "UID",
GID: "GID",
RealName: "RealName",
UserName: "UserName",
UserCode: "UserCode",
Email: "Email",
Notes: "Notes",
Active: "Active",
ExampleInt: "ExampleInt",
ExampleFloat: "ExampleFloat",
ExampleBool: "ExampleBool",
ExampleDate: "ExampleDate",
ExampleString: "ExampleString",
LastLogin: "LastLogin",
LastHost: "LastHost",
}
Fields provides strongly-typed field names for use with GetBy/GetAllWhere/etc.
Example: GetBy(Fields.Key, "abc")
Note: the values are the struct field names as stored in Storm.
var TableName = entities.Table("TemplateStore")
TableName is the canonical DAO table identifier for this package.
Functions ¶
func CacheHydrator ¶
CacheHydrator returns the cache hydrator function for this table.
func CacheSpew ¶
func CacheSpew()
CacheSpew writes the current cache state for this table to the logs.
func CacheSynchroniser ¶
CacheSynchroniser returns the cache synchroniser function for this table.
func Close ¶
func Close()
Close flushes the cache (if enabled) and closes the active database connection.
func CountWhere ¶
CountWhere returns the number of records matching a field/value filter.
func DeleteByKey ¶
DeleteByKey is deprecated; prefer DeleteBy(ctx, Fields.Key, key, note).
func ExportAllAsCSV ¶
ExportAllAsCSV exports all TemplateStore records as a CSV file.
func ExportAllAsJSON ¶
func ExportAllAsJSON(message string)
ExportAllAsJSON exports all TemplateStore records as JSON files.
func FlushCache ¶
func FlushCache() error
FlushCache synchronises cached records back to the underlying database.
func GetDatabaseConnections ¶
GetDatabaseConnections returns a function that supplies the database connections used by this DAO.
func GetDefaultLookup ¶
GetDefaultLookup returns the default lookup for this table.
func ImportAllFromCSV ¶
func ImportAllFromCSV() error
ImportAllFromCSV imports records for this table from a CSV file.
func Initialise ¶
Initialise opens the database connection for TemplateStoreV2 and optionally enables caching.
func IsInitialised ¶
func IsInitialised() bool
IsInitialised reports whether the DAO has an active database connection.
Types ¶
type TemplateStore ¶
type TemplateStore struct {
// The primary key field(s), managed by the framework, DO NOT MODIFY
ID int `storm:"id,increment=100"`
Key string `storm:"index,unique"`
Raw string `storm:"index,unique"`
// Audit information, managed by the framework, DO NOT MODIFY
Audit audit.Audit `csv:"-"`
// Domain specific fields
UID string `validate:"required"`
GID string `storm:"index" validate:"required"`
RealName string `validate:"required,min=5"`
UserName string `validate:"required,min=5"`
UserCode string `storm:"index" validate:"required,min=5"`
Email string
Notes string `validate:"max=75"`
Active entities.Bool
ExampleInt entities.Int
ExampleFloat entities.Float
ExampleBool entities.Bool
ExampleDate time.Time
ExampleString string
LastLogin time.Time
LastHost string `storm:"index"`
}
TemplateStore represents a sample entity for demonstrating reduced DAO boilerplate. Replace this struct and Fields as needed for your real entity.
func Add ¶
func Add(ctx context.Context, sq string) (TemplateStore, error)
Add creates and persists a new user record based on the current OS user.
func Create ¶
func Create(ctx context.Context, userName, uid, realName, email, gid string) (TemplateStore, error)
Create constructs and inserts a new TemplateStore record.
func GetAllWhere ¶
func GetAllWhere(field entities.Field, value any) ([]TemplateStore, error)
GetAllWhere returns all records matching a field/value filter.
func GetBy ¶
func GetBy(field entities.Field, value any) (TemplateStore, error)
GetBy returns a single record matching the given field/value.
func GetById ¶
func GetById(id int) (TemplateStore, error)
GetById is deprecated; prefer GetBy(Fields.ID, id).
func GetByKey ¶
func GetByKey(key string) (TemplateStore, error)
GetByKey is deprecated; prefer GetBy(Fields.Key, key).
func Login ¶
func Login(ctx context.Context, sq string) (TemplateStore, error)
Login logs a user in (creating a record if needed) and updates last login metadata.
func (*TemplateStore) Clone ¶
func (record *TemplateStore) Clone(ctx context.Context) (TemplateStore, error)
Clone returns a copy of the record using templateClone.
func (*TemplateStore) Create ¶
func (record *TemplateStore) Create(ctx context.Context, note string) error
Create inserts a new record.
func (*TemplateStore) ExportRecordAsCSV ¶
func (record *TemplateStore) ExportRecordAsCSV(name string) error
ExportRecordAsCSV exports the TemplateStore record as a CSV file.
func (*TemplateStore) ExportRecordAsJSON ¶
func (record *TemplateStore) ExportRecordAsJSON(name string)
ExportRecordAsJSON exports the TemplateStore record as a JSON file.
func (*TemplateStore) SetName ¶
func (u *TemplateStore) SetName(name string) error
SetName validates and sets the record's RealName.
func (*TemplateStore) Spew ¶
func (record *TemplateStore) Spew()
Spew outputs the contents of the TemplateStore record to the Trace log.
func (*TemplateStore) Update ¶
func (record *TemplateStore) Update(ctx context.Context, note string) error
Update persists changes to an existing record.
func (*TemplateStore) UpdateWithAction ¶
func (record *TemplateStore) UpdateWithAction(ctx context.Context, auditAction audit.Action, note string) error
UpdateWithAction persists changes using the provided audit action.
func (*TemplateStore) Validate ¶
func (record *TemplateStore) Validate() error
Validate runs record validation and returns an error if invalid.