database

package
v0.22.3 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadRuntimeConfig added in v0.13.0

func LoadRuntimeConfig(fileConfig *config.Config, store *ConfigStore) (*config.RuntimeConfig, error)

LoadRuntimeConfig is a convenience function that loads runtime config using a ConfigStore

Types

type CacheMode added in v0.4.0

type CacheMode string

CacheMode represents the available cache modes for SQLite

const (
	CacheShared  CacheMode = "shared"
	CachePrivate CacheMode = "private"
)

type ConfigAdapter added in v0.13.0

type ConfigAdapter struct {
	// contains filtered or unexported fields
}

ConfigAdapter adapts ConfigStore to the ConfigStoreInterface for runtime config

func NewConfigAdapter added in v0.13.0

func NewConfigAdapter(store *ConfigStore) *ConfigAdapter

NewConfigAdapter creates a new config adapter

func (*ConfigAdapter) GetAvailability added in v0.13.0

func (a *ConfigAdapter) GetAvailability(parent string) ([]string, error)

GetAvailability implements ConfigStoreInterface

func (*ConfigAdapter) GetParents added in v0.13.0

func (a *ConfigAdapter) GetParents() (parentA, parentB string, err error)

GetParents implements ConfigStoreInterface

func (*ConfigAdapter) GetSchedule added in v0.13.0

func (a *ConfigAdapter) GetSchedule() (updateFrequency string, lookAheadDays, pastEventThresholdDays int, statsOrder constants.StatsOrder, err error)

GetSchedule implements ConfigStoreInterface

type ConfigParents added in v0.13.0

type ConfigParents struct {
	ID        int64
	ParentA   string
	ParentB   string
	CreatedAt time.Time
	UpdatedAt time.Time
}

ConfigParents represents parent configuration

type ConfigSchedule added in v0.13.0

type ConfigSchedule struct {
	ID                     int64
	UpdateFrequency        string
	LookAheadDays          int
	PastEventThresholdDays int
	StatsOrder             constants.StatsOrder
	CreatedAt              time.Time
	UpdatedAt              time.Time
}

ConfigSchedule represents schedule configuration

type ConfigSeeder added in v0.13.0

type ConfigSeeder struct {
	// contains filtered or unexported fields
}

ConfigSeeder handles seeding configuration from TOML to database

func NewConfigSeeder added in v0.13.0

func NewConfigSeeder(store *ConfigStore) *ConfigSeeder

NewConfigSeeder creates a new config seeder

func (*ConfigSeeder) SeedFromConfig added in v0.13.0

func (s *ConfigSeeder) SeedFromConfig(cfg *config.Config) error

SeedFromConfig seeds the database with configuration from TOML file This is called on every startup and handles both initial setup and migration: - On initial setup: Seeds all config from TOML - On upgrade: Migrates existing TOML config to new DB tables - On normal startup: Skips if DB config already exists

type ConfigStore added in v0.13.0

type ConfigStore struct {
	// contains filtered or unexported fields
}

ConfigStore handles configuration storage in SQLite

func NewConfigStore added in v0.13.0

func NewConfigStore(db *DB) (*ConfigStore, error)

NewConfigStore creates a new config store

func (*ConfigStore) GetAvailability added in v0.13.0

func (s *ConfigStore) GetAvailability(parent string) ([]string, error)

GetAvailability retrieves unavailable days for a parent

func (*ConfigStore) GetParents added in v0.13.0

func (s *ConfigStore) GetParents() (parentA, parentB string, err error)

GetParents retrieves parent configuration

func (*ConfigStore) GetParentsFull added in v0.13.0

func (s *ConfigStore) GetParentsFull() (*ConfigParents, error)

GetParentsFull retrieves full parent configuration with metadata

func (*ConfigStore) GetSchedule added in v0.13.0

func (s *ConfigStore) GetSchedule() (updateFrequency string, lookAheadDays, pastEventThresholdDays int, statsOrder constants.StatsOrder, err error)

GetSchedule retrieves schedule configuration

func (*ConfigStore) GetScheduleFull added in v0.13.0

func (s *ConfigStore) GetScheduleFull() (*ConfigSchedule, error)

GetScheduleFull retrieves full schedule configuration with metadata

func (*ConfigStore) HasConfiguration added in v0.13.0

func (s *ConfigStore) HasConfiguration() (bool, error)

HasConfiguration checks if any configuration exists in the database

func (*ConfigStore) SaveAvailability added in v0.13.0

func (s *ConfigStore) SaveAvailability(parent string, unavailableDays []string) error

SaveAvailability saves unavailable days for a parent

func (*ConfigStore) SaveParents added in v0.13.0

func (s *ConfigStore) SaveParents(parentA, parentB string) error

SaveParents saves or updates parent configuration

func (*ConfigStore) SaveSchedule added in v0.13.0

func (s *ConfigStore) SaveSchedule(updateFrequency string, lookAheadDays, pastEventThresholdDays int, statsOrder constants.StatsOrder) error

SaveSchedule saves or updates schedule configuration

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB manages the database connection

func New

func New(opts SQLiteOptions) (*DB, error)

New creates a new database connection using the provided options. It configures the connection using both DSN parameters (for supported options like mode, cache, immutable) and explicit PRAGMA commands executed after the connection is established for other settings.

func (*DB) Close

func (db *DB) Close() error

Close closes the database connection

func (*DB) Conn

func (db *DB) Conn() *sql.DB

Conn returns the underlying database connection

func (*DB) MigrateDatabase

func (db *DB) MigrateDatabase() error

MigrateDatabase performs database migrations

func (*DB) WithTransaction added in v0.10.0

func (db *DB) WithTransaction(ctx context.Context, fn func(*sql.Tx) error) error

WithTransaction executes a function within a database transaction If the function returns an error, the transaction is rolled back Otherwise, the transaction is committed

type JournalMode added in v0.4.0

type JournalMode string

JournalMode represents the available journal modes for SQLite

const (
	JournalDelete   JournalMode = "DELETE"
	JournalTruncate JournalMode = "TRUNCATE"
	JournalPersist  JournalMode = "PERSIST"
	JournalMemory   JournalMode = "MEMORY"
	JournalWAL      JournalMode = "WAL"
	JournalOff      JournalMode = "OFF"
)

type LockingMode added in v0.4.0

type LockingMode string

LockingMode represents the available locking modes for SQLite

const (
	LockingNormal    LockingMode = "NORMAL"
	LockingExclusive LockingMode = "EXCLUSIVE"
)

type NotificationChannel

type NotificationChannel struct {
	ID         string
	ResourceID string
	CalendarID string
	Expiration time.Time
	CreatedAt  time.Time
	UpdatedAt  time.Time
}

NotificationChannel represents a Google Calendar notification channel

type SQLiteOptions added in v0.4.0

type SQLiteOptions struct {
	// Path to the SQLite database file
	Path string

	// Core Options
	Mode        string          // ro, rw, rwc, memory
	Journal     JournalMode     // _journal_mode: DELETE, TRUNCATE, PERSIST, MEMORY, WAL, OFF
	ForeignKeys bool            // _foreign_keys=true
	BusyTimeout int             // _busy_timeout (milliseconds)
	CacheSize   int             // _cache_size (in KB, negative for number of pages)
	Synchronous SynchronousMode // _synchronous: OFF, NORMAL, FULL, EXTRA
	Cache       CacheMode       // shared, private
	Immutable   bool            // immutable=true/false

	// Transaction & Locking
	LockingMode  LockingMode // _locking_mode: NORMAL, EXCLUSIVE
	TxLock       string      // _txlock: immediate, deferred, exclusive
	MutexLocking string      // _mutex: no, full

	// Advanced Options
	AutoVacuum             string // _auto_vacuum: none, full, incremental
	CaseSensitiveLike      bool   // _case_sensitive_like
	DeferForeignKeys       bool   // _defer_foreign_keys
	IgnoreCheckConstraints bool   // _ignore_check_constraints
	QueryOnly              bool   // _query_only
	RecursiveTriggers      bool   // _recursive_triggers
	SecureDelete           string // _secure_delete: boolean or "FAST"
	WritableSchema         bool   // _writable_schema

	// Authentication
	Auth      bool   // _auth
	AuthUser  string // _auth_user
	AuthPass  string // _auth_pass
	AuthCrypt string // _auth_crypt: SHA1, SSHA1, SHA256, etc.
	AuthSalt  string // _auth_salt
}

SQLiteOptions contains configuration options for SQLite connection

func NewDefaultOptions added in v0.4.0

func NewDefaultOptions(path string) SQLiteOptions

NewDefaultOptions creates SQLiteOptions with recommended defaults

type SynchronousMode added in v0.4.0

type SynchronousMode string

SynchronousMode represents the available synchronous settings for SQLite

const (
	SynchronousOff    SynchronousMode = "OFF"
	SynchronousNormal SynchronousMode = "NORMAL"
	SynchronousFull   SynchronousMode = "FULL"
	SynchronousExtra  SynchronousMode = "EXTRA"
)

type TokenStore

type TokenStore struct {
	// contains filtered or unexported fields
}

TokenStore handles OAuth token storage in SQLite

func NewTokenStore

func NewTokenStore(db *DB) (*TokenStore, error)

NewTokenStore creates a new token store

func (*TokenStore) ClearToken

func (s *TokenStore) ClearToken() error

ClearToken removes the saved OAuth token

func (*TokenStore) DeleteExpiredNotificationChannels

func (s *TokenStore) DeleteExpiredNotificationChannels() error

DeleteExpiredNotificationChannels deletes all expired notification channels

func (*TokenStore) DeleteNotificationChannel

func (s *TokenStore) DeleteNotificationChannel(id string) error

DeleteNotificationChannel deletes a notification channel by its ID

func (*TokenStore) GetActiveNotificationChannels

func (s *TokenStore) GetActiveNotificationChannels() ([]*NotificationChannel, error)

GetActiveNotificationChannels retrieves all active notification channels

func (*TokenStore) GetNotificationChannelByID

func (s *TokenStore) GetNotificationChannelByID(id string) (*NotificationChannel, error)

GetNotificationChannelByID retrieves a notification channel by its ID

func (*TokenStore) GetSelectedCalendar

func (s *TokenStore) GetSelectedCalendar() (string, error)

GetSelectedCalendar retrieves the saved calendar ID

func (*TokenStore) GetSelectedCalendarWithName added in v0.16.0

func (s *TokenStore) GetSelectedCalendarWithName() (calendarID string, calendarName string, err error)

GetSelectedCalendarWithName retrieves the saved calendar ID and name

func (*TokenStore) GetToken

func (s *TokenStore) GetToken() (*oauth2.Token, error)

GetToken retrieves the saved OAuth token

func (*TokenStore) SaveNotificationChannel

func (s *TokenStore) SaveNotificationChannel(channel *NotificationChannel) error

SaveNotificationChannel saves a notification channel

func (*TokenStore) SaveSelectedCalendar

func (s *TokenStore) SaveSelectedCalendar(calendarID string) error

SaveSelectedCalendar saves the selected calendar ID with empty calendar name This method delegates to SaveSelectedCalendarWithName for consistency

func (*TokenStore) SaveSelectedCalendarWithName added in v0.16.0

func (s *TokenStore) SaveSelectedCalendarWithName(calendarID string, calendarName string) error

SaveSelectedCalendarWithName saves the selected calendar ID and name

func (*TokenStore) SaveToken

func (s *TokenStore) SaveToken(token *oauth2.Token) error

SaveToken implements the TokenSaver interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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