database

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DB_PERMS                = os.FileMode(0755)
	SQL_DRIVER              = "sqlite3"
	MAX_OPEN_CONNECTIONS    = 1
	MAX_IDLE_CONNECTIONS    = 1
	MAX_CONNECTION_LIFETIME = 0 // Infinite
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

func NewDBWithLogger

func NewDBWithLogger(dbPath string, logger *slog.Logger) (*DB, error)

NewDBWithLogger creates a new database connection with a logger

func (*DB) AddObservations

func (db *DB) AddObservations(ctx context.Context, observations []ObservationAdditionInput) ([]ObservationAdditionResult, error)

func (*DB) Close

func (db *DB) Close() error

func (*DB) CreateEntities

func (db *DB) CreateEntities(ctx context.Context, entities []EntityWithObservations) ([]EntityWithObservations, error)

func (*DB) CreateRelations

func (db *DB) CreateRelations(ctx context.Context, relations []RelationDTO) ([]RelationDTO, error)

func (*DB) DeleteEntities

func (db *DB) DeleteEntities(ctx context.Context, entityNames []string) error

func (*DB) DeleteObservations

func (db *DB) DeleteObservations(ctx context.Context, deletions []ObservationDeletionInput) error

func (*DB) DeleteRelations

func (db *DB) DeleteRelations(ctx context.Context, relations []RelationDTO) error

func (*DB) IsFTSEnabled

func (db *DB) IsFTSEnabled() bool

IsFTSEnabled returns whether FTS5 is available

func (*DB) OpenNodes

func (db *DB) OpenNodes(ctx context.Context, names []string) (*KnowledgeGraph, error)

func (*DB) ReadGraph

func (db *DB) ReadGraph(ctx context.Context) (*KnowledgeGraph, error)

func (*DB) RebuildFTSIndex

func (db *DB) RebuildFTSIndex(ctx context.Context) error

RebuildFTSIndex rebuilds the FTS index (useful after bulk imports)

func (*DB) SearchNodes

func (db *DB) SearchNodes(ctx context.Context, query string) (*KnowledgeGraph, error)

func (*DB) SearchNodesFTS

func (db *DB) SearchNodesFTS(ctx context.Context, query string) (*KnowledgeGraph, error)

SearchNodesFTS performs full-text search using FTS5 tables for better performance

func (*DB) SearchNodesRanked

func (db *DB) SearchNodesRanked(ctx context.Context, query string) (*KnowledgeGraph, error)

SearchNodesRanked performs FTS5 search with relevance ranking

type Entity

type Entity struct {
	ID         int64     `json:"id" db:"id"`
	Name       string    `json:"name" db:"name"`
	EntityType string    `json:"entityType" db:"entity_type"`
	CreatedAt  time.Time `json:"createdAt" db:"created_at"`
	UpdatedAt  time.Time `json:"updatedAt" db:"updated_at"`
}

type EntityWithObservations

type EntityWithObservations struct {
	Name         string   `json:"name"`
	EntityType   string   `json:"entityType"`
	Observations []string `json:"observations"`
}

type KnowledgeGraph

type KnowledgeGraph struct {
	Entities  []EntityWithObservations `json:"entities"`
	Relations []RelationDTO            `json:"relations"`
}

type Observation

type Observation struct {
	ID        int64     `json:"id" db:"id"`
	EntityID  int64     `json:"entityId" db:"entity_id"`
	Content   string    `json:"content" db:"content"`
	CreatedAt time.Time `json:"createdAt" db:"created_at"`
}

type ObservationAdditionInput

type ObservationAdditionInput struct {
	EntityName string   `json:"entityName"`
	Contents   []string `json:"contents"`
}

Named types to replace anonymous structs in DB APIs for ergonomics

type ObservationAdditionResult

type ObservationAdditionResult struct {
	EntityName        string   `json:"entityName"`
	AddedObservations []string `json:"addedObservations"`
}

type ObservationDeletionInput

type ObservationDeletionInput struct {
	EntityName   string   `json:"entityName"`
	Observations []string `json:"observations"`
}

type Relation

type Relation struct {
	ID           int64     `json:"id" db:"id"`
	FromEntityID int64     `json:"fromEntityId" db:"from_entity_id"`
	ToEntityID   int64     `json:"toEntityId" db:"to_entity_id"`
	RelationType string    `json:"relationType" db:"relation_type"`
	CreatedAt    time.Time `json:"createdAt" db:"created_at"`
}

type RelationDTO

type RelationDTO struct {
	From         string `json:"from"`
	To           string `json:"to"`
	RelationType string `json:"relationType"`
}

Jump to

Keyboard shortcuts

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