sqlite

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Expirable added in v1.1.2

func Expirable(ctx context.Context) bool

Expirable - Returns from context if sqlite record is expirable

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

Types

type Prefix

type Prefix struct {
	Id        string `gorm:"primaryKey"`
	Name      string `gorm:"index"` // supposedly indexing could improve query performance
	Cidr      string
	ParentID  string `gorm:"index"`
	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 (*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) 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 add 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