sqlite

package
v1.2.10 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const BridgeName = "bridge" // prefix with name "bridge" is special because it's not periodically updated

Variables

View Source
var ErrCIDRConflict = prefix.ErrCIDRConflict // alias to simplify usage in this package

Functions

func Expirable added in v1.1.2

func Expirable(ctx context.Context) bool

Expirable - Returns from context if sqlite record is expirable

func TableNameForModel added in v1.2.2

func TableNameForModel(db *gorm.DB, model any) string

TableNameForModel infers the table name for a given model

func WithExpirable added in v1.1.2

func WithExpirable(parent context.Context) context.Context

WithExpirable - Stores in context whether the sqlite record must be expirable

func WithUpdateDamping added in v1.2.2

func WithUpdateDamping(ctx context.Context, threshold time.Duration) context.Context

WithUpdateDamping - Returns a new context that signals a request for damped updating

Types

type Prefix

type Prefix struct {
	Id        string `gorm:"primaryKey"`
	Name      string `gorm:"index"`                          // supposedly indexing could improve query performance
	Cidr      string `gorm:"uniqueIndex:idx_parent_id_cidr"` // composite uniqueIndex should be helpful in resolving race conditions in concurrent allocation attempts considering the hierarchical allocation logic of prefix.Allocate
	ParentID  string `gorm:"index;uniqueIndex:idx_parent_id_cidr"`
	Parent    *Prefix
	UpdatedAt time.Time `gorm:"index"`               // supposedly indexing could improve query performance
	Expirable *bool     `gorm:"index;default:false"` // indicates whether prefix can expire and thus be subject to garbage collection
}

type SQLiteIPAMStorage

type SQLiteIPAMStorage struct {
	DB *gorm.DB
	// contains filtered or unexported fields
}

func New

func New(datastore string) (*SQLiteIPAMStorage, error)

func NewForTest added in v1.2.2

func NewForTest(db *gorm.DB) (*SQLiteIPAMStorage, error)

NewForTest is a constructor for testing purposes. It accepts an already opened *gorm.DB instance. It DOES NOT perform AutoMigrate or run init() automatically. This gives tests explicit control over schema setup and migration steps.

func (*SQLiteIPAMStorage) Add

func (sqlis *SQLiteIPAMStorage) Add(ctx context.Context, prefix types.Prefix) error

Add adds prefix to database. Also sets the expirable field based on the context.

func (*SQLiteIPAMStorage) Delete

func (sqlis *SQLiteIPAMStorage) Delete(ctx context.Context, prefix types.Prefix) error

func (*SQLiteIPAMStorage) Get

func (sqlis *SQLiteIPAMStorage) Get(ctx context.Context, name string, parent types.Prefix) (types.Prefix, error)

Get finds and returns the first database record matching the given prefix. Note: default or unset fields are ignored by the GORM query

func (*SQLiteIPAMStorage) GetChilds

func (sqlis *SQLiteIPAMStorage) GetChilds(ctx context.Context, prefix types.Prefix) ([]types.Prefix, error)

func (*SQLiteIPAMStorage) GetTableNameForTest added in v1.2.2

func (sqlis *SQLiteIPAMStorage) GetTableNameForTest() string

func (*SQLiteIPAMStorage) InitForTest added in v1.2.2

func (sqlis *SQLiteIPAMStorage) InitForTest() error

InitForTest is an exported helper for testing the internal init() logic. It performs AutoMigrate of the current Prefix model and runs the migrate function.

func (*SQLiteIPAMStorage) MigrateForTest added in v1.2.2

func (sqlis *SQLiteIPAMStorage) MigrateForTest(ctx context.Context) error

MigrateForTest is an exported helper for testing the internal migrate() logic. It provides direct access to the migration function.

func (*SQLiteIPAMStorage) RunGarbageCollectorOnceForTest added in v1.2.2

func (sqlis *SQLiteIPAMStorage) RunGarbageCollectorOnceForTest(ctx context.Context, threshold time.Duration) error

RunGarbageCollectorOnceForTest is an exported helper for testing internal garbageCollector() logic.

func (*SQLiteIPAMStorage) StartGarbageCollector added in v1.1.2

func (sqlis *SQLiteIPAMStorage) StartGarbageCollector(ctx context.Context, interval time.Duration, threshold time.Duration)

StartGarbageCollector - StartGarbageCollector periodically runs a garbage collector to clean up outdated expirable records with valid updatedAt values (where threshold determines what is considered outdated).

func (*SQLiteIPAMStorage) Update added in v1.1.2

func (sqlis *SQLiteIPAMStorage) Update(ctx context.Context, prefix types.Prefix) error

Update - Updates or adds the database entry. Currently, the whole purpose of this function is to update the UpdatedAt field in the database that is used by garbage collector logic to clean up unused entries that haven't been updated for a long time. And to keep the expirable field set for records that can expire based on the context. (GORM Save() considers unset entries as well to update the record, thus expirable field must be set to either false or true.)

Jump to

Keyboard shortcuts

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