Documentation ¶
Index ¶
- func ByteToString(b []byte) string
- func Close()
- func CloseAll() *[]error
- func CloseDB(name string) error
- func CreateTempFile(name string) (string, *os.File, error)
- func DisableDebugMessages()
- func DoesExist(dest string) bool
- func DoesNotExist(dest string) bool
- func KeynameValidator(keyname *string) (bool, error)
- func OpenSGobDB(label string, loc string, opts *SGobOptions) error
- func OpenSJsonDB(label string, loc string, opts *SJsonOptions) error
- func SGobOptionBackupsToKeep(num uint32) func(opts *SGobOptions) error
- func SGobOptionCacheAfterGet() func(opts *SGobOptions) error
- func SGobOptionInMemoryOnly() func(opts *SGobOptions) error
- func SGobOptionStoreModePerItem() func(opts *SGobOptions) error
- func SGobOptionStoreModePerTable() func(opts *SGobOptions) error
- func SGobOptionStoreModeSingleFile() func(opts *SGobOptions) error
- func SGobOptionSyncAfterWrite() func(opts *SGobOptions) error
- func SGobOptionUncacheAfterSave() func(opts *SGobOptions) error
- func SJsonOptionBackupsToKeep(num uint32) func(opts *SJsonOptions) error
- func SJsonOptionCacheAfterGet() func(opts *SJsonOptions) error
- func SJsonOptionInMemoryOnly() func(opts *SJsonOptions) error
- func SJsonOptionStoreModePerItem() func(opts *SJsonOptions) error
- func SJsonOptionStoreModePerTable() func(opts *SJsonOptions) error
- func SJsonOptionStoreModeSingleFile() func(opts *SGobOptions) error
- func SJsonOptionSyncAfterWrite() func(opts *SJsonOptions) error
- func SJsonOptionUncacheAfterSave() func(opts *SJsonOptions) error
- func SaveDB(name string) error
- func SetActiveWorkersLimit(limit int64)
- func Wait()
- type DBQuery
- func (f *DBQuery) Count() (int64, error)
- func (f *DBQuery) DB(db_name string) *DBQuery
- func (f *DBQuery) Delete(key string) error
- func (f *DBQuery) Get(key string, v any) error
- func (f *DBQuery) GetKeys() (*[]string, error)
- func (f *DBQuery) GetModificationTime(key string) (int64, error)
- func (f DBQuery) GetSGobDBInstance() *SGobDatabase
- func (f DBQuery) GetSJsonDBInstance() *SJsonDatabase
- func (f DBQuery) ResolveKeyname(key *string) *string
- func (f *DBQuery) Table(table_name string) *DBQuery
- func (f *DBQuery) TransactionEnd(rotate bool) error
- func (f *DBQuery) TransactionStart() error
- func (f *DBQuery) Update(key string, v any) error
- type SGobDatabase
- func (d *SGobDatabase) AllKeys() (*[]string, error)
- func (d *SGobDatabase) AllTables() (*[]string, error)
- func (d *SGobDatabase) Close() error
- func (d *SGobDatabase) Count() (int64, error)
- func (d *SGobDatabase) Delete(Key *string) error
- func (d *SGobDatabase) FilterKeys(prefix string) (*[]string, error)
- func (d *SGobDatabase) Get(Key *string, v any) error
- func (d *SGobDatabase) GetModificationTime(Key *string) (int64, error)
- func (d *SGobDatabase) LoadFromDisk() error
- func (d *SGobDatabase) SaveToDisk(rotate bool) error
- func (d *SGobDatabase) TransactionEnd(rotate bool) error
- func (d *SGobDatabase) TransactionStart() error
- func (d *SGobDatabase) Update(Key *string, Data any) error
- type SGobIndex
- type SGobItem
- type SGobOptions
- type SJsonDatabase
- func (d *SJsonDatabase) AllKeys() (*[]string, error)
- func (d *SJsonDatabase) AllTables() (*[]string, error)
- func (d *SJsonDatabase) Close() error
- func (d *SJsonDatabase) Count() (int64, error)
- func (d *SJsonDatabase) Delete(Key *string) error
- func (d *SJsonDatabase) FilterKeys(prefix string) (*[]string, error)
- func (d *SJsonDatabase) Get(Key *string, v any) error
- func (d *SJsonDatabase) GetModificationTime(Key *string) (int64, error)
- func (d *SJsonDatabase) LoadFromDisk() error
- func (d *SJsonDatabase) SaveToDisk(rotate bool) error
- func (d *SJsonDatabase) TransactionEnd(rotate bool) error
- func (d *SJsonDatabase) TransactionStart() error
- func (d *SJsonDatabase) Update(Key *string, Data any) error
- type SJsonIndex
- type SJsonItem
- type SJsonOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ByteToString ¶ added in v1.1.4
Converts a byte slice to string with zero allocation.
func DisableDebugMessages ¶ added in v1.0.8
func DisableDebugMessages()
This will disable all debug messages for security (information will not be leaked.) Due to its secure nature, debug messages cannot be re-enabled unless the application is restarted and this function is not called.
func KeynameValidator ¶ added in v1.1.4
Returns true if the keyname is valid and false if it is not. Because tablenames are just key prefixes, this can also be used to validate tablenames.
func OpenSGobDB ¶ added in v1.0.9
func OpenSGobDB(label string, loc string, opts *SGobOptions) error
Opens a database with the Super Gob backend. label : Nickname for the database, only used for queries. loc : Filepath where database will be stored. opts : Use NewSGobOptions() to set available options for this backend type. The database is only rotated on close or when calling SaveDB directly to prevent excessive IO.
func OpenSJsonDB ¶ added in v1.1.4
func OpenSJsonDB(label string, loc string, opts *SJsonOptions) error
Opens a database with the Super Gob backend. label : Nickname for the database, only used for queries. loc : Filepath where database will be stored. opts : Use NewSJsonOptions() to set available options for this backend type. The database is only rotated on close or when calling SaveDB directly to prevent excessive IO.
func SGobOptionBackupsToKeep ¶ added in v1.1.4
func SGobOptionBackupsToKeep(num uint32) func(opts *SGobOptions) error
Sets how many backups to keep. Default is five. Set to zero to disable.
func SGobOptionCacheAfterGet ¶ added in v1.1.4
func SGobOptionCacheAfterGet() func(opts *SGobOptions) error
Will save values in cache after they are fetched from disk. Don't use this if you have a database that is too large to fit in memory.
func SGobOptionInMemoryOnly ¶ added in v1.1.4
func SGobOptionInMemoryOnly() func(opts *SGobOptions) error
Will not persist to disk even if location is set. Keeps all values cached in memory.
func SGobOptionStoreModePerItem ¶ added in v1.1.4
func SGobOptionStoreModePerItem() func(opts *SGobOptions) error
Database stores invididual items as their own "files".
func SGobOptionStoreModePerTable ¶ added in v1.1.4
func SGobOptionStoreModePerTable() func(opts *SGobOptions) error
Database stores tables as their own "files".
func SGobOptionStoreModeSingleFile ¶ added in v1.1.4
func SGobOptionStoreModeSingleFile() func(opts *SGobOptions) error
Database stores itself as a single file. Currently not supported.
func SGobOptionSyncAfterWrite ¶ added in v1.1.4
func SGobOptionSyncAfterWrite() func(opts *SGobOptions) error
Will trigger a save to disk after every Update or Delete.
func SGobOptionUncacheAfterSave ¶ added in v1.1.4
func SGobOptionUncacheAfterSave() func(opts *SGobOptions) error
Will remove values from cache after they are persisted to disk so they must be fetched from disk again.
func SJsonOptionBackupsToKeep ¶ added in v1.1.4
func SJsonOptionBackupsToKeep(num uint32) func(opts *SJsonOptions) error
Sets how many backups to keep. Default is five. Set to zero to disable.
func SJsonOptionCacheAfterGet ¶ added in v1.1.4
func SJsonOptionCacheAfterGet() func(opts *SJsonOptions) error
Will save values in cache after they are fetched from disk. Don't use this if you have a database that is too large to fit in memory.
func SJsonOptionInMemoryOnly ¶ added in v1.1.4
func SJsonOptionInMemoryOnly() func(opts *SJsonOptions) error
Will not persist to disk even if location is set. Keeps all values cached in memory.
func SJsonOptionStoreModePerItem ¶ added in v1.1.4
func SJsonOptionStoreModePerItem() func(opts *SJsonOptions) error
Database stores invididual items as their own "files".
func SJsonOptionStoreModePerTable ¶ added in v1.1.4
func SJsonOptionStoreModePerTable() func(opts *SJsonOptions) error
Database stores tables as their own "files".
func SJsonOptionStoreModeSingleFile ¶ added in v1.1.4
func SJsonOptionStoreModeSingleFile() func(opts *SGobOptions) error
Database stores itself as a single file. Currently not supported.
func SJsonOptionSyncAfterWrite ¶ added in v1.1.4
func SJsonOptionSyncAfterWrite() func(opts *SJsonOptions) error
Will trigger a save to disk after every Update or Delete.
func SJsonOptionUncacheAfterSave ¶ added in v1.1.4
func SJsonOptionUncacheAfterSave() func(opts *SJsonOptions) error
Will remove values from cache after they are persisted to disk so they must be fetched from disk again.
func SetActiveWorkersLimit ¶ added in v1.1.4
func SetActiveWorkersLimit(limit int64)
Limits the number of goroutines used by IO calls for all databases. Default is 2000. Set this to whatever your system, filesystem, or disk can handle smoothly.
Types ¶
type DBQuery ¶ added in v1.0.8
type DBQuery struct { GetDBName *string GetTableName *string // contains filtered or unexported fields }
A database query.
func (*DBQuery) Get ¶ added in v1.0.8
Fetches a value for the key. v is a pointer to the object the value will be set to. v will be nil if the value cannot be found or is nil. v will be decoded internally from a byte slice.
func (*DBQuery) GetKeys ¶ added in v1.0.8
Fetches a list of keys from the database. If a table is provided in the query, only keys for the table will be returned. The resulting keys will have the tablename stripped.
func (*DBQuery) GetModificationTime ¶ added in v1.1.4
Returns modification time of the item in microseconds.
func (DBQuery) GetSGobDBInstance ¶ added in v1.0.9
func (f DBQuery) GetSGobDBInstance() *SGobDatabase
Fetches an SGobDatabase instance from its label if there is one currently open. Returns nil if the database is closed or no such database exists.
func (DBQuery) GetSJsonDBInstance ¶ added in v1.1.4
func (f DBQuery) GetSJsonDBInstance() *SJsonDatabase
Fetches an SJsonDatabase instance from its label if there is one currently open. Returns nil if the database is closed or no such database exists.
func (DBQuery) ResolveKeyname ¶ added in v1.0.8
Resolves a query to a fullname key.
func (*DBQuery) TransactionEnd ¶ added in v1.1.4
rotate: Specifies whether to rotate backups (true) or not (false). For SGob databases, resumes syncing writes after TransactionStart was called. Will cause a save to disk operation.
func (*DBQuery) TransactionStart ¶ added in v1.1.4
For SGob databases, pauses syncing writes until TransactionEnd is called. TransactionEnd will cause a save to disk operation.
type SGobDatabase ¶ added in v1.0.9
type SGobDatabase struct { Label string Location string DBName string LastSaved int64 Mem *map[string]*SGobItem MutexMem *map[string]*sync.RWMutex MutexAllocGuard *sync.RWMutex KeyCount *atomic.Int64 // ActiveOperations *atomic.Int64 Closing *atomic.Bool Opening *atomic.Bool Saving *atomic.Bool SyncWritePaused *atomic.Bool Options *SGobOptions }
A database with the SGob backend.
func GetSGobDBInstance ¶ added in v1.0.9
func GetSGobDBInstance(label string) *SGobDatabase
Fetches an SGobDatabase instance from its label if there is one currently open. Returns nil if the database is closed or no such database exists.
func (*SGobDatabase) AllKeys ¶ added in v1.1.4
func (d *SGobDatabase) AllKeys() (*[]string, error)
Fetches a list of all keys for the database. Will include table prefixes.
func (*SGobDatabase) AllTables ¶ added in v1.1.4
func (d *SGobDatabase) AllTables() (*[]string, error)
Fetches a list of all table key prefixes for the database. Will not include specific fully named keys.
func (*SGobDatabase) Close ¶ added in v1.0.9
func (d *SGobDatabase) Close() error
Closes the database.
func (*SGobDatabase) Count ¶ added in v1.0.9
func (d *SGobDatabase) Count() (int64, error)
func (*SGobDatabase) Delete ¶ added in v1.0.9
func (d *SGobDatabase) Delete(Key *string) error
func (*SGobDatabase) FilterKeys ¶ added in v1.1.4
func (d *SGobDatabase) FilterKeys(prefix string) (*[]string, error)
Fetches a list of keys for the database. Will not include table prefix in key for filter matches.
func (*SGobDatabase) GetModificationTime ¶ added in v1.1.4
func (d *SGobDatabase) GetModificationTime(Key *string) (int64, error)
Returns modification time of the item in microseconds.
func (*SGobDatabase) LoadFromDisk ¶ added in v1.0.9
func (d *SGobDatabase) LoadFromDisk() error
Loads the database from its disk location.
func (*SGobDatabase) SaveToDisk ¶ added in v1.0.9
func (d *SGobDatabase) SaveToDisk(rotate bool) error
Saves the database to disk.
func (*SGobDatabase) TransactionEnd ¶ added in v1.1.4
func (d *SGobDatabase) TransactionEnd(rotate bool) error
rotate: Specifies whether to rotate previous database backups (true) or not (false). Re-enables disk persistence and triggers a save to disk operation. Useful for batch operations.
func (*SGobDatabase) TransactionStart ¶ added in v1.1.4
func (d *SGobDatabase) TransactionStart() error
Disables disk persistence temporarily. Useful for batch operations.
type SGobIndex ¶ added in v1.0.9
type SGobIndex struct {
Keys []string
}
An index of keys for the SGob backend.
type SGobOptions ¶ added in v1.1.4
type SGobOptions struct { InMemoryOnly bool SyncAfterWrite bool UncacheAfterSave bool CacheAfterGet bool StoreModePerItem bool StoreModeSingleFile bool StoreModePerTable bool BackupsToKeep uint32 }
A struct with options for an SGob database.
func NewSGobOptions ¶ added in v1.1.4
func NewSGobOptions(options ...func(*SGobOptions) error) *SGobOptions
Creates a new SGobOptions struct. Chain .Option methods to set options. Will panic if an option has somehow been misconfigured.
type SJsonDatabase ¶ added in v1.1.4
type SJsonDatabase struct { Label string Location string DBName string LastSaved int64 Mem *map[string]*SJsonItem MutexMem *map[string]*sync.RWMutex MutexAllocGuard *sync.RWMutex KeyCount *atomic.Int64 // ActiveOperations *atomic.Int64 Closing *atomic.Bool Opening *atomic.Bool Saving *atomic.Bool SyncWritePaused *atomic.Bool Options *SJsonOptions }
A database with the SJson backend.
func GetSJsonDBInstance ¶ added in v1.1.4
func GetSJsonDBInstance(label string) *SJsonDatabase
Fetches an SJsonDatabase instance from its label if there is one currently open. Returns nil if the database is closed or no such database exists.
func (*SJsonDatabase) AllKeys ¶ added in v1.1.4
func (d *SJsonDatabase) AllKeys() (*[]string, error)
Fetches a list of all keys for the database. Will include table prefixes.
func (*SJsonDatabase) AllTables ¶ added in v1.1.4
func (d *SJsonDatabase) AllTables() (*[]string, error)
Fetches a list of all table key prefixes for the database. Will not include specific fully named keys.
func (*SJsonDatabase) Close ¶ added in v1.1.4
func (d *SJsonDatabase) Close() error
Closes the database.
func (*SJsonDatabase) Count ¶ added in v1.1.4
func (d *SJsonDatabase) Count() (int64, error)
func (*SJsonDatabase) Delete ¶ added in v1.1.4
func (d *SJsonDatabase) Delete(Key *string) error
func (*SJsonDatabase) FilterKeys ¶ added in v1.1.4
func (d *SJsonDatabase) FilterKeys(prefix string) (*[]string, error)
Fetches a list of keys for the database. Will not include table prefix in key for filter matches.
func (*SJsonDatabase) GetModificationTime ¶ added in v1.1.4
func (d *SJsonDatabase) GetModificationTime(Key *string) (int64, error)
Returns modification time of the item in microseconds.
func (*SJsonDatabase) LoadFromDisk ¶ added in v1.1.4
func (d *SJsonDatabase) LoadFromDisk() error
Loads the database from its disk location.
func (*SJsonDatabase) SaveToDisk ¶ added in v1.1.4
func (d *SJsonDatabase) SaveToDisk(rotate bool) error
Saves the database to disk.
func (*SJsonDatabase) TransactionEnd ¶ added in v1.1.4
func (d *SJsonDatabase) TransactionEnd(rotate bool) error
rotate: Specifies whether to rotate previous database backups (true) or not (false). Re-enables disk persistence and triggers a save to disk operation. Useful for batch operations.
func (*SJsonDatabase) TransactionStart ¶ added in v1.1.4
func (d *SJsonDatabase) TransactionStart() error
Disables disk persistence temporarily. Useful for batch operations.
type SJsonIndex ¶ added in v1.1.4
type SJsonIndex struct {
Keys []string
}
An index of keys for the SJson backend.
type SJsonOptions ¶ added in v1.1.4
type SJsonOptions struct { InMemoryOnly bool SyncAfterWrite bool UncacheAfterSave bool CacheAfterGet bool StoreModePerItem bool StoreModeSingleFile bool StoreModePerTable bool BackupsToKeep uint32 }
A struct with options for an SJson database.
func NewSJsonOptions ¶ added in v1.1.4
func NewSJsonOptions(options ...func(*SJsonOptions) error) *SJsonOptions
Creates a new SJsonOptions struct. Chain .Option methods to set options. Will panic if an option has somehow been misconfigured.