Documentation
¶
Overview ¶
Package sqlite provides some basic functionality for interacting with a SQLite database.
Index ¶
- Constants
- Variables
- func AddFlag(flag models.ClientData) error
- func AddFlagWithContext(ctx context.Context, flag models.ClientData) error
- func AddFlags(flags []models.ClientData) error
- func AddFlagsWithContext(ctx context.Context, flags []models.ClientData) error
- func BindParams(stmt *sqlite.Stmt, args ...any) (*sqlite.Stmt, error)
- func Close() error
- func DeleteFlag(ctx context.Context, flag string) error
- func DeleteTTLFlag(ctx context.Context, ttl uint64) (int64, error)
- func FlagsNumber(ctx context.Context) (int, error)
- func GetAllFlagCodeList() ([]string, error)
- func GetAllFlags() ([]models.ClientData, error)
- func GetFirstNFlagCodeList(limit uint) ([]string, error)
- func GetFirstNFlags(limit uint) ([]models.ClientData, error)
- func GetPagedFlagCodeList(limit, offset uint) ([]string, error)
- func GetPagedFlags(limit, offset uint) ([]models.ClientData, error)
- func GetUnsubmittedFlagCodeList(limit uint) ([]string, error)
- func GetUnsubmittedFlags(limit uint) ([]models.ClientData, error)
- func InitDB() error
- func New() *sqlitex.Pool
- func UpdateFlagsStatus(responses []protocols.ResponseProtocol) error
- type CollectorStats
- type FlagCollector
- func (fc *FlagCollector) AddFlag(flag models.ClientData) error
- func (fc *FlagCollector) Flush() error
- func (fc *FlagCollector) FlushWithContext(ctx context.Context) error
- func (fc *FlagCollector) GetBufferSize() int
- func (fc *FlagCollector) GetStats() CollectorStats
- func (fc *FlagCollector) IsRunning() bool
- func (fc *FlagCollector) Start()
- func (fc *FlagCollector) Stop() error
Constants ¶
const PoolSize = 20
Variables ¶
var (
DBPool *sqlitex.Pool
)
Functions ¶
func AddFlag ¶
func AddFlag(flag models.ClientData) error
AddFlag adds a single flag to the database. It calls the AddFlags function to add the flag as a batch of size 1.
func AddFlagWithContext ¶
func AddFlagWithContext(ctx context.Context, flag models.ClientData) error
AddFlagWithContext adds a single flag to the database with a custom context.
func AddFlags ¶
func AddFlags(flags []models.ClientData) error
AddFlags adds a batch of flags to the database with a default timeout. It calls AddFlagsWithContext with a timeout context.
func AddFlagsWithContext ¶
func AddFlagsWithContext(ctx context.Context, flags []models.ClientData) error
AddFlagsWithContext adds a batch of flags to the database with a custom context. It divides the flags into batches to insert in chunks, helping avoid hitting query parameter limits.
func BindParams ¶ added in v1.2.1
BindParams binds parameters to a prepared SQLite statement.
func Close ¶
func Close() error
Close closes the database connection. It disconnects from the database and logs the disconnection message.
func FlagsNumber ¶
FlagsNumber returns the number of flags in the database. It queries the database to count the flags and returns the total number.
func GetAllFlagCodeList ¶
GetAllFlagCodeList retrieves all flag codes from the database.
func GetAllFlags ¶
func GetAllFlags() ([]models.ClientData, error)
GetAllFlags retrieves all flags from the database.
func GetFirstNFlagCodeList ¶
GetFirstNFlagCodeList retrieves the first n flag codes from the database.
func GetFirstNFlags ¶
func GetFirstNFlags(limit uint) ([]models.ClientData, error)
GetFirstNFlags retrieves the first n flags from the database.
func GetPagedFlagCodeList ¶
GetPagedFlagCodeList retrieves the flag codes from the database starting at the given offset.
func GetPagedFlags ¶
func GetPagedFlags(limit, offset uint) ([]models.ClientData, error)
GetPagedFlags retrieves the flags from the database starting at the given offset.
func GetUnsubmittedFlagCodeList ¶
GetUnsubmittedFlagCodeList retrieves the first n unsubmitted flag codes from the database.
func GetUnsubmittedFlags ¶
func GetUnsubmittedFlags(limit uint) ([]models.ClientData, error)
GetUnsubmittedFlags retrieves the first n unsubmitted flags from the database.
func InitDB ¶
func InitDB() error
InitDB initializes the database schema using the SQL schema embedded in the code. It runs the SQL schema to set up tables and structures in the database.
func New ¶
New initializes the database connection and schema. It opens a connection to the SQLite database and initializes the schema by calling InitDB. Returns the database connection object.
func UpdateFlagsStatus ¶
func UpdateFlagsStatus(responses []protocols.ResponseProtocol) error
UpdateFlagsStatus aggiorna lo status e il messaggio delle flag in batch
Types ¶
type CollectorStats ¶
type CollectorStats struct { TotalFlagsReceived int TotalFlushes int SuccessfulFlushes int FailedFlushes int LastFlushTime time.Time LastSuccessfulFlush time.Time TotalFlagsFlushed int LastError error }
CollectorStats holds statistics about the flag collector
type FlagCollector ¶
type FlagCollector struct {
// contains filtered or unexported fields
}
FlagCollector manages the collection and flushing of flags to the database
func GetCollector ¶
func GetCollector() *FlagCollector
GetCollector return the instance of FlagCollector singleton
func (*FlagCollector) AddFlag ¶
func (fc *FlagCollector) AddFlag(flag models.ClientData) error
AddFlag adds a flag to the collector's buffer
func (*FlagCollector) Flush ¶
func (fc *FlagCollector) Flush() error
Flush sends all accumulated flags to the database
func (*FlagCollector) FlushWithContext ¶
func (fc *FlagCollector) FlushWithContext(ctx context.Context) error
FlushWithContext sends all accumulated flags to the database using the provided context
func (*FlagCollector) GetBufferSize ¶
func (fc *FlagCollector) GetBufferSize() int
GetBufferSize returns the current size of the buffer
func (*FlagCollector) GetStats ¶
func (fc *FlagCollector) GetStats() CollectorStats
GetStats returns the current statistics of the collector
func (*FlagCollector) IsRunning ¶
func (fc *FlagCollector) IsRunning() bool
IsRunning checks if the collector is currently running
func (*FlagCollector) Start ¶
func (fc *FlagCollector) Start()
Start the collector to begin collecting flags
func (*FlagCollector) Stop ¶
func (fc *FlagCollector) Stop() error
Stop the collector and flush any remaining flags