sync

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package sync provides SQLite-based offline caching for Aha Studio.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultDBPath

func DefaultDBPath() string

DefaultDBPath returns the default database path.

Types

type DB

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

DB wraps a SQLite database connection for Aha data caching.

func Open

func Open(dbPath string) (*DB, error)

Open opens or creates a SQLite database at the given path.

func (*DB) Close

func (d *DB) Close() error

Close closes the database connection.

func (*DB) CreateFilter

func (d *DB) CreateFilter(f *SavedFilter) error

CreateFilter creates a new saved filter.

func (*DB) DeleteFilter

func (d *DB) DeleteFilter(id string) error

DeleteFilter deletes a saved filter by ID.

func (*DB) FullTextSearch

func (d *DB) FullTextSearch(query string, entityTypes []string, limit int) ([]map[string]any, error)

FullTextSearch searches across all FTS5 tables.

func (*DB) GetFeatureIDs

func (d *DB) GetFeatureIDs(product string) ([]string, error)

GetFeatureIDs returns all feature IDs for a product.

func (*DB) GetFilter

func (d *DB) GetFilter(id string) (*SavedFilter, error)

GetFilter returns a saved filter by ID.

func (*DB) GetFilterByName

func (d *DB) GetFilterByName(name string) (*SavedFilter, error)

GetFilterByName returns a saved filter by name.

func (*DB) GetLastSync

func (d *DB) GetLastSync(entity, product string) (time.Time, error)

GetLastSync returns the last sync time for an entity/product combination.

func (*DB) GetRelationships

func (d *DB) GetRelationships(entityType, entityID string) ([]map[string]any, error)

GetRelationships returns relationships for an entity.

func (*DB) GetSyncStatus

func (d *DB) GetSyncStatus(product string) (map[string]SyncStatus, error)

GetSyncStatus returns the sync status for all entities.

func (*DB) ListFilters

func (d *DB) ListFilters() ([]SavedFilter, error)

ListFilters returns all saved filters.

func (*DB) QueryOffline

func (d *DB) QueryOffline(plan *planner.Plan) (*result.Result, error)

QueryOffline executes a query against the local SQLite database.

func (*DB) SetLastSync

func (d *DB) SetLastSync(entity, product string, t time.Time, count int) error

SetLastSync updates the last sync time for an entity/product combination.

func (*DB) SetProduct

func (d *DB) SetProduct(product string)

SetProduct sets the current product context.

func (*DB) UpdateFilter

func (d *DB) UpdateFilter(f *SavedFilter) error

UpdateFilter updates an existing saved filter.

func (*DB) UpsertComment

func (d *DB) UpsertComment(product string, data map[string]any) error

UpsertComment inserts or updates a comment record.

func (*DB) UpsertEpic

func (d *DB) UpsertEpic(product string, data map[string]any) error

UpsertEpic inserts or updates an epic record.

func (*DB) UpsertFeature

func (d *DB) UpsertFeature(product string, data map[string]any) error

UpsertFeature inserts or updates a feature record.

func (*DB) UpsertGoal

func (d *DB) UpsertGoal(product string, data map[string]any) error

UpsertGoal inserts or updates a goal record.

func (*DB) UpsertIdea

func (d *DB) UpsertIdea(product string, data map[string]any) error

UpsertIdea inserts or updates an idea record.

func (*DB) UpsertInitiative

func (d *DB) UpsertInitiative(product string, data map[string]any) error

UpsertInitiative inserts or updates an initiative record.

func (*DB) UpsertProduct

func (d *DB) UpsertProduct(data map[string]any) error

UpsertProduct inserts or updates a product record.

func (*DB) UpsertRelationship

func (d *DB) UpsertRelationship(fromType, fromID, relType, toType, toID, product string) error

UpsertRelationship inserts or updates a relationship record.

func (*DB) UpsertRelease

func (d *DB) UpsertRelease(product string, data map[string]any) error

UpsertRelease inserts or updates a release record.

func (*DB) UpsertRequirement

func (d *DB) UpsertRequirement(product string, data map[string]any) error

UpsertRequirement inserts or updates a requirement record.

func (*DB) UpsertUser

func (d *DB) UpsertUser(data map[string]any) error

UpsertUser inserts or updates a user record.

type SavedFilter

type SavedFilter struct {
	ID          string    `json:"id"`
	Name        string    `json:"name"`
	AQL         string    `json:"aql"`
	Product     string    `json:"product,omitempty"`
	Description string    `json:"description,omitempty"`
	IsFavorite  bool      `json:"is_favorite"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

SavedFilter represents a saved AQL query.

type Scheduler

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

Scheduler manages background sync operations.

func NewScheduler

func NewScheduler(syncer *Syncer, cfg SchedulerConfig) *Scheduler

NewScheduler creates a new sync scheduler.

func (*Scheduler) IsRunning

func (s *Scheduler) IsRunning() bool

IsRunning returns true if the scheduler is running.

func (*Scheduler) LastError

func (s *Scheduler) LastError() error

LastError returns the last sync error, if any.

func (*Scheduler) LastSync

func (s *Scheduler) LastSync() time.Time

LastSync returns the time of the last successful sync.

func (*Scheduler) Start

func (s *Scheduler) Start(ctx context.Context) error

Start begins background sync. Non-blocking.

func (*Scheduler) Status

func (s *Scheduler) Status() SchedulerStatus

Status returns the current scheduler status.

func (*Scheduler) Stop

func (s *Scheduler) Stop()

Stop stops the background sync gracefully.

func (*Scheduler) SyncNow

func (s *Scheduler) SyncNow(ctx context.Context) ([]SyncResult, error)

SyncNow triggers an immediate sync, regardless of schedule.

type SchedulerConfig

type SchedulerConfig struct {
	// Interval between sync runs. Default: 15 minutes.
	Interval time.Duration

	// Product ID to sync.
	Product string

	// Logger for sync events. Default: slog.Default().
	Logger *slog.Logger

	// Entities to sync. Default: all entities.
	Entities []string
}

SchedulerConfig configures the sync scheduler.

func DefaultSchedulerConfig

func DefaultSchedulerConfig() SchedulerConfig

DefaultSchedulerConfig returns default scheduler configuration.

type SchedulerStatus

type SchedulerStatus struct {
	Running  bool
	Interval time.Duration
	Product  string
	LastSync time.Time
	LastErr  error
}

SchedulerStatus contains scheduler status information.

type SyncOptions

type SyncOptions struct {
	Product     string    // Product ID to sync
	Incremental bool      // Only sync changes since last sync
	Since       time.Time // Custom since time (overrides incremental lookup)
	Entities    []string  // Specific entities to sync (nil = all)
}

SyncOptions configures a sync operation.

type SyncResult

type SyncResult struct {
	Entity      string
	RecordCount int
	Duration    time.Duration
	Error       error
}

SyncResult contains the result of a sync operation.

type SyncStatus

type SyncStatus struct {
	LastSync    string
	RecordCount int
}

SyncStatus contains sync status for an entity.

type Syncer

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

Syncer synchronizes Aha data to a local SQLite database.

func NewSyncer

func NewSyncer(db *DB, client *aha.Client) *Syncer

NewSyncer creates a new Syncer with the given database and Aha client.

func (*Syncer) SyncAll

func (s *Syncer) SyncAll(ctx context.Context, opts SyncOptions) ([]SyncResult, error)

SyncAll syncs all entities for a product.

Jump to

Keyboard shortcuts

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