sqlite

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2025 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package sqlite provides some basic functionality for interacting with a SQLite database.

Index

Constants

View Source
const PoolSize = 20

Variables

View Source
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

func BindParams(stmt *sqlite.Stmt, args ...any) (*sqlite.Stmt, error)

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 DeleteFlag

func DeleteFlag(ctx context.Context, flag string) error

func DeleteTTLFlag

func DeleteTTLFlag(ctx context.Context, ttl uint64) (int64, error)

func FlagsNumber

func FlagsNumber(ctx context.Context) (int, error)

FlagsNumber returns the number of flags in the database. It queries the database to count the flags and returns the total number.

func GetAllFlagCodeList

func GetAllFlagCodeList() ([]string, error)

GetAllFlagCodeList retrieves all flag codes from the database.

func GetAllFlags

func GetAllFlags() ([]models.ClientData, error)

GetAllFlags retrieves all flags from the database.

func GetFirstNFlagCodeList

func GetFirstNFlagCodeList(limit uint) ([]string, error)

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

func GetPagedFlagCodeList(limit, offset uint) ([]string, error)

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

func GetUnsubmittedFlagCodeList(limit uint) ([]string, error)

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

func New() *sqlitex.Pool

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

Jump to

Keyboard shortcuts

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