Documentation
¶
Overview ¶
Package sqlite provides SQLite-based persistence using modernc.org/sqlite (pure Go, no CGO).
Index ¶
- type CausalRepo
- func (r *CausalRepo) AddEdge(ctx context.Context, edge *causal.Edge) error
- func (r *CausalRepo) AddNode(ctx context.Context, node *causal.Node) error
- func (r *CausalRepo) GetChain(ctx context.Context, query string, maxDepth int) (*causal.Chain, error)
- func (r *CausalRepo) Stats(ctx context.Context) (*causal.CausalStats, error)
- type CrystalRepo
- func (r *CrystalRepo) Delete(ctx context.Context, path string) error
- func (r *CrystalRepo) Get(ctx context.Context, path string) (*crystal.Crystal, error)
- func (r *CrystalRepo) List(ctx context.Context, pattern string, limit int) ([]*crystal.Crystal, error)
- func (r *CrystalRepo) Search(ctx context.Context, query string, limit int) ([]*crystal.Crystal, error)
- func (r *CrystalRepo) Stats(ctx context.Context) (*crystal.CrystalStats, error)
- func (r *CrystalRepo) Upsert(ctx context.Context, c *crystal.Crystal) error
- type DB
- type FactRepo
- func (r *FactRepo) Add(ctx context.Context, fact *memory.Fact) error
- func (r *FactRepo) CompressFacts(ctx context.Context, ids []string, summary string) (string, error)
- func (r *FactRepo) Delete(ctx context.Context, id string) error
- func (r *FactRepo) Get(ctx context.Context, id string) (*memory.Fact, error)
- func (r *FactRepo) GetColdFacts(ctx context.Context, limit int) ([]*memory.Fact, error)
- func (r *FactRepo) GetExpired(ctx context.Context) ([]*memory.Fact, error)
- func (r *FactRepo) GetStale(ctx context.Context, includeArchived bool) ([]*memory.Fact, error)
- func (r *FactRepo) ListByDomain(ctx context.Context, domain string, includeStale bool) ([]*memory.Fact, error)
- func (r *FactRepo) ListByLevel(ctx context.Context, level memory.HierLevel) ([]*memory.Fact, error)
- func (r *FactRepo) ListDomains(ctx context.Context) ([]string, error)
- func (r *FactRepo) ListGenes(ctx context.Context) ([]*memory.Fact, error)
- func (r *FactRepo) RefreshTTL(ctx context.Context, id string) error
- func (r *FactRepo) Search(ctx context.Context, query string, limit int) ([]*memory.Fact, error)
- func (r *FactRepo) Stats(ctx context.Context) (*memory.FactStoreStats, error)
- func (r *FactRepo) TouchFact(ctx context.Context, id string) error
- func (r *FactRepo) Update(ctx context.Context, fact *memory.Fact) error
- type InteractionEntry
- type InteractionLogRepo
- func (r *InteractionLogRepo) Count(ctx context.Context) (total int, unprocessed int, err error)
- func (r *InteractionLogRepo) GetUnprocessed(ctx context.Context) ([]InteractionEntry, error)
- func (r *InteractionLogRepo) MarkProcessed(ctx context.Context, ids []int64) error
- func (r *InteractionLogRepo) Prune(ctx context.Context, olderThan time.Duration) (int64, error)
- func (r *InteractionLogRepo) Record(ctx context.Context, toolName string, args map[string]interface{}) error
- type PeerRepo
- type SOCRepo
- func (r *SOCRepo) CountEvents(tenantID string) (int, error)
- func (r *SOCRepo) CountEventsSince(tenantID string, since time.Time) (int, error)
- func (r *SOCRepo) CountOpenIncidents(tenantID string) (int, error)
- func (r *SOCRepo) CountSensorsByStatus(tenantID string) (map[soc.SensorStatus]int, error)
- func (r *SOCRepo) EventExistsByHash(contentHash string) (bool, error)
- func (r *SOCRepo) GetEvent(id string) (*soc.SOCEvent, error)
- func (r *SOCRepo) GetIncident(id string) (*soc.Incident, error)
- func (r *SOCRepo) GetSensor(id string) (*soc.Sensor, error)
- func (r *SOCRepo) InsertEvent(e soc.SOCEvent) error
- func (r *SOCRepo) InsertIncident(inc soc.Incident) error
- func (r *SOCRepo) ListEvents(tenantID string, limit int) ([]soc.SOCEvent, error)
- func (r *SOCRepo) ListEventsByCategory(tenantID string, category string, limit int) ([]soc.SOCEvent, error)
- func (r *SOCRepo) ListIncidents(tenantID string, status string, limit int) ([]soc.Incident, error)
- func (r *SOCRepo) ListSensors(tenantID string) ([]soc.Sensor, error)
- func (r *SOCRepo) PurgeExpiredEvents(retentionDays int) (int64, error)
- func (r *SOCRepo) PurgeExpiredIncidents(retentionDays int) (int64, error)
- func (r *SOCRepo) UpdateIncident(inc *soc.Incident) error
- func (r *SOCRepo) UpdateIncidentStatus(id string, status soc.IncidentStatus) error
- func (r *SOCRepo) UpsertSensor(s soc.Sensor) error
- type StateRepo
- func (r *StateRepo) DeleteSession(ctx context.Context, sessionID string) (int, error)
- func (r *StateRepo) GetAuditLog(ctx context.Context, sessionID string, limit int) ([]session.AuditEntry, error)
- func (r *StateRepo) ListSessions(ctx context.Context) ([]session.SessionInfo, error)
- func (r *StateRepo) Load(ctx context.Context, sessionID string, version *int) (*session.CognitiveStateVector, string, error)
- func (r *StateRepo) Save(ctx context.Context, state *session.CognitiveStateVector, checksum string) error
- type SynapseRepo
- func (r *SynapseRepo) Accept(ctx context.Context, id int64) error
- func (r *SynapseRepo) Count(ctx context.Context) (pending, verified, rejected int, err error)
- func (r *SynapseRepo) Create(ctx context.Context, factIDA, factIDB string, confidence float64) (int64, error)
- func (r *SynapseRepo) Exists(ctx context.Context, factIDA, factIDB string) (bool, error)
- func (r *SynapseRepo) ListPending(ctx context.Context, limit int) ([]*synapse.Synapse, error)
- func (r *SynapseRepo) ListVerified(ctx context.Context) ([]*synapse.Synapse, error)
- func (r *SynapseRepo) Reject(ctx context.Context, id int64) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CausalRepo ¶
type CausalRepo struct {
// contains filtered or unexported fields
}
CausalRepo implements causal.CausalStore using SQLite. Compatible with causal_chains.db schema.
func NewCausalRepo ¶
func NewCausalRepo(db *DB) (*CausalRepo, error)
NewCausalRepo creates a CausalRepo and ensures the schema exists.
func (*CausalRepo) GetChain ¶
func (r *CausalRepo) GetChain(ctx context.Context, query string, maxDepth int) (*causal.Chain, error)
GetChain builds a causal chain around a decision node matching the query.
func (*CausalRepo) Stats ¶
func (r *CausalRepo) Stats(ctx context.Context) (*causal.CausalStats, error)
Stats returns aggregate statistics about the causal store.
type CrystalRepo ¶
type CrystalRepo struct {
// contains filtered or unexported fields
}
CrystalRepo implements crystal.CrystalStore using SQLite. Compatible with crystals.db schema.
func NewCrystalRepo ¶
func NewCrystalRepo(db *DB) (*CrystalRepo, error)
NewCrystalRepo creates a CrystalRepo and ensures the schema exists.
func (*CrystalRepo) Delete ¶
func (r *CrystalRepo) Delete(ctx context.Context, path string) error
Delete removes a crystal by path.
func (*CrystalRepo) List ¶
func (r *CrystalRepo) List(ctx context.Context, pattern string, limit int) ([]*crystal.Crystal, error)
List returns crystals matching a path pattern. Empty pattern returns all.
func (*CrystalRepo) Search ¶
func (r *CrystalRepo) Search(ctx context.Context, query string, limit int) ([]*crystal.Crystal, error)
Search searches crystal primitives by name/value containing query.
func (*CrystalRepo) Stats ¶
func (r *CrystalRepo) Stats(ctx context.Context) (*crystal.CrystalStats, error)
Stats returns aggregate statistics.
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB wraps a *sql.DB with SQLite-specific configuration.
func Open ¶
Open opens or creates an SQLite database at the given path. It applies WAL mode and recommended pragmas for performance.
func OpenMemory ¶
OpenMemory opens an in-memory SQLite database (for testing).
type FactRepo ¶
type FactRepo struct {
// contains filtered or unexported fields
}
FactRepo implements memory.FactStore using SQLite. Compatible with memory_bridge_v2.db schema v2.0.0.
func NewFactRepo ¶
NewFactRepo creates a FactRepo and ensures the schema exists.
func (*FactRepo) CompressFacts ¶
CompressFacts archives originals and creates a summary fact. Genes (source='genome') are silently skipped.
func (*FactRepo) GetColdFacts ¶
GetColdFacts returns facts with hit_count=0, created >30 days ago. Genes (source='genome') and archived facts are excluded.
func (*FactRepo) GetExpired ¶
GetExpired returns facts whose TTL has expired.
func (*FactRepo) ListByDomain ¶
func (r *FactRepo) ListByDomain(ctx context.Context, domain string, includeStale bool) ([]*memory.Fact, error)
ListByDomain returns facts in a domain, optionally including stale ones.
func (*FactRepo) ListByLevel ¶
ListByLevel returns all facts at a given hierarchy level.
func (*FactRepo) ListDomains ¶
ListDomains returns distinct domain names.
func (*FactRepo) RefreshTTL ¶
RefreshTTL resets the created_at timestamp for a fact (effectively refreshing its TTL).
type InteractionEntry ¶
type InteractionEntry struct {
ID int64 `json:"id"`
ToolName string `json:"tool_name"`
ArgsJSON string `json:"args_json,omitempty"`
Timestamp time.Time `json:"timestamp"`
Processed bool `json:"processed"`
}
InteractionEntry represents a single tool call record in the interaction log.
type InteractionLogRepo ¶
type InteractionLogRepo struct {
// contains filtered or unexported fields
}
InteractionLogRepo provides crash-safe tool call recording in SQLite. Every tool call is INSERT-ed immediately; WAL mode ensures durability even on kill -9 / terminal close.
func NewInteractionLogRepo ¶
func NewInteractionLogRepo(db *DB) (*InteractionLogRepo, error)
NewInteractionLogRepo creates the interaction_log table if needed and returns the repo.
func (*InteractionLogRepo) GetUnprocessed ¶
func (r *InteractionLogRepo) GetUnprocessed(ctx context.Context) ([]InteractionEntry, error)
GetUnprocessed returns all entries not yet processed, ordered oldest first.
func (*InteractionLogRepo) MarkProcessed ¶
func (r *InteractionLogRepo) MarkProcessed(ctx context.Context, ids []int64) error
MarkProcessed marks entries as processed by their IDs.
type PeerRepo ¶
type PeerRepo struct {
// contains filtered or unexported fields
}
PeerRepo implements peer.PeerStore using SQLite.
func NewPeerRepo ¶
NewPeerRepo creates a PeerRepo and ensures the peers table exists.
func (*PeerRepo) DeleteExpired ¶
DeleteExpired removes peers not seen within the given duration.
type SOCRepo ¶
type SOCRepo struct {
// contains filtered or unexported fields
}
SOCRepo provides SQLite persistence for SOC events, incidents, and sensors.
func NewSOCRepo ¶
NewSOCRepo creates and initializes SOC tables.
func (*SOCRepo) CountEvents ¶
CountEvents returns total event count.
func (*SOCRepo) CountEventsSince ¶
CountEventsSince returns events in the given time window.
func (*SOCRepo) CountOpenIncidents ¶
CountOpenIncidents returns count of non-resolved incidents.
func (*SOCRepo) CountSensorsByStatus ¶
CountSensorsByStatus returns sensor count grouped by status.
func (*SOCRepo) EventExistsByHash ¶
EventExistsByHash checks if an event with the given content hash already exists (§5.2 dedup).
func (*SOCRepo) GetIncident ¶
GetIncident retrieves an incident by ID with full case management data.
func (*SOCRepo) InsertEvent ¶
InsertEvent persists a SOC event.
func (*SOCRepo) InsertIncident ¶
InsertIncident persists a new incident.
func (*SOCRepo) ListEvents ¶
ListEvents returns events ordered by timestamp (newest first), with limit.
func (*SOCRepo) ListEventsByCategory ¶
func (r *SOCRepo) ListEventsByCategory(tenantID string, category string, limit int) ([]soc.SOCEvent, error)
ListEventsByCategory returns events filtered by category.
func (*SOCRepo) ListIncidents ¶
ListIncidents returns incidents, optionally filtered by status.
func (*SOCRepo) ListSensors ¶
ListSensors returns all registered sensors.
func (*SOCRepo) PurgeExpiredEvents ¶
PurgeExpiredEvents deletes events older than the retention period. Returns the number of deleted events.
func (*SOCRepo) PurgeExpiredIncidents ¶
PurgeExpiredIncidents deletes resolved incidents older than the retention period. Only resolved incidents are purged; open/investigating incidents are preserved. Returns the number of deleted incidents.
func (*SOCRepo) UpdateIncident ¶
UpdateIncident persists the full incident state including case management data.
func (*SOCRepo) UpdateIncidentStatus ¶
func (r *SOCRepo) UpdateIncidentStatus(id string, status soc.IncidentStatus) error
UpdateIncidentStatus updates status (and optionally resolved_at).
type StateRepo ¶
type StateRepo struct {
// contains filtered or unexported fields
}
StateRepo implements session.StateStore using SQLite. Compatible with memory_bridge.db schema (states + audit_log). NOTE: The Python version uses AES-256-GCM encryption on the data blob. This Go implementation stores plaintext JSON for now — encryption can be layered on top via a decorator if needed.
func NewStateRepo ¶
NewStateRepo creates a StateRepo and ensures the schema exists.
func (*StateRepo) DeleteSession ¶
DeleteSession removes all versions of a session. Returns the number of deleted rows.
func (*StateRepo) GetAuditLog ¶
func (r *StateRepo) GetAuditLog(ctx context.Context, sessionID string, limit int) ([]session.AuditEntry, error)
GetAuditLog returns the audit log for a session.
func (*StateRepo) ListSessions ¶
ListSessions returns metadata about all persisted sessions.
type SynapseRepo ¶
type SynapseRepo struct {
// contains filtered or unexported fields
}
SynapseRepo implements synapse.SynapseStore using SQLite.
func NewSynapseRepo ¶
func NewSynapseRepo(db *DB) *SynapseRepo
NewSynapseRepo creates a SynapseRepo (table created by FactRepo migration v3.3).
func (*SynapseRepo) Accept ¶
func (r *SynapseRepo) Accept(ctx context.Context, id int64) error
Accept transitions a synapse to VERIFIED.
func (*SynapseRepo) Count ¶
func (r *SynapseRepo) Count(ctx context.Context) (pending, verified, rejected int, err error)
Count returns synapse counts by status.
func (*SynapseRepo) Create ¶
func (r *SynapseRepo) Create(ctx context.Context, factIDA, factIDB string, confidence float64) (int64, error)
Create inserts a new PENDING synapse.
func (*SynapseRepo) Exists ¶
Exists checks if a synapse exists between two facts (either direction).
func (*SynapseRepo) ListPending ¶
ListPending returns synapses with status PENDING.
func (*SynapseRepo) ListVerified ¶
ListVerified returns all VERIFIED synapses.