storage

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("storage: not found")

Functions

This section is empty.

Types

type Chunk

type Chunk struct {
	ID       int64
	SourceID *int64
	NoteID   *int64
	Content  string
	Position int
	Tokens   int
}
type Link struct {
	ID           int64
	FromNoteID   *int64
	FromSourceID *int64
	ToNoteID     *int64
	ToSourceID   *int64
	Kind         LinkKind
	Context      string
}

type LinkKind

type LinkKind string
const (
	LinkWikilink    LinkKind = "wikilink"
	LinkCitation    LinkKind = "citation"
	LinkSeeAlso     LinkKind = "see-also"
	LinkDerivedFrom LinkKind = "derived-from"
)

type Note

type Note struct {
	ID        int64
	Slug      string
	Title     string
	Kind      string
	Content   string
	Summary   string
	Keywords  []string
	CreatedAt time.Time
	UpdatedAt time.Time
	Version   int
}

type Operation

type Operation struct {
	ID      int64
	Kind    string
	At      time.Time
	Actor   string
	Summary string
	Details json.RawMessage
}

type SearchHit

type SearchHit struct {
	EntityRef string
	Title     string
	Snippet   string
	Score     float64
	Kind      string
}

type Source

type Source struct {
	ID         int64
	URI        string
	Kind       string
	Title      string
	Content    string
	Hash       string
	IngestedAt time.Time
	Metadata   json.RawMessage
}

type Store

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

func Open

func Open(path string) (*Store, error)

func (*Store) Close

func (s *Store) Close() error

func (*Store) CreateChunk

func (s *Store) CreateChunk(ctx context.Context, c *Chunk) error
func (s *Store) CreateLink(ctx context.Context, l *Link) error

func (*Store) CreateNote

func (s *Store) CreateNote(ctx context.Context, n *Note) error

func (*Store) CreateSource

func (s *Store) CreateSource(ctx context.Context, src *Source) error

func (*Store) DB

func (s *Store) DB() *sql.DB

func (*Store) GetChunk

func (s *Store) GetChunk(ctx context.Context, id int64) (*Chunk, error)

func (*Store) GetNote

func (s *Store) GetNote(ctx context.Context, id int64) (*Note, error)

func (*Store) GetNoteBySlug

func (s *Store) GetNoteBySlug(ctx context.Context, slug string) (*Note, error)

func (*Store) GetSource

func (s *Store) GetSource(ctx context.Context, id int64) (*Source, error)

func (*Store) GetSourceByHash

func (s *Store) GetSourceByHash(ctx context.Context, hash string) (*Source, error)

func (*Store) IndexChunk

func (s *Store) IndexChunk(ctx context.Context, c *Chunk, title string) error

func (*Store) IndexNote

func (s *Store) IndexNote(ctx context.Context, n *Note) error

func (*Store) LinksFromNote

func (s *Store) LinksFromNote(ctx context.Context, noteID int64) ([]*Link, error)

func (*Store) LinksToNote

func (s *Store) LinksToNote(ctx context.Context, noteID int64) ([]*Link, error)

func (*Store) ListNotes

func (s *Store) ListNotes(ctx context.Context, kind string, limit, offset int) ([]*Note, error)

func (*Store) LogOperation

func (s *Store) LogOperation(ctx context.Context, op *Operation) error

func (*Store) Search

func (s *Store) Search(ctx context.Context, query string, limit int) ([]SearchHit, error)

Search runs a BM25 query. Higher score = more relevant (we return -rank so callers can sort descending).

func (*Store) UpdateNote

func (s *Store) UpdateNote(ctx context.Context, n *Note, reason string) error

UpdateNote runs the archive+update under a dedicated transaction so the two writes stay atomic when called outside of an outer tx.

func (*Store) WithTx

func (s *Store) WithTx(ctx context.Context, fn func(*Tx) error) error

WithTx runs fn inside a SQLite transaction. If fn returns an error, the transaction is rolled back and that error is returned; otherwise the transaction is committed.

type Tx

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

Tx is a transactional handle that exposes the same CRUD surface as Store but batches writes under a single SQLite transaction.

func (*Tx) CreateChunk

func (t *Tx) CreateChunk(ctx context.Context, c *Chunk) error
func (t *Tx) CreateLink(ctx context.Context, l *Link) error

func (*Tx) CreateNote

func (t *Tx) CreateNote(ctx context.Context, n *Note) error

func (*Tx) CreateSource

func (t *Tx) CreateSource(ctx context.Context, src *Source) error

func (*Tx) GetChunk

func (t *Tx) GetChunk(ctx context.Context, id int64) (*Chunk, error)

func (*Tx) GetNote

func (t *Tx) GetNote(ctx context.Context, id int64) (*Note, error)

func (*Tx) GetNoteBySlug

func (t *Tx) GetNoteBySlug(ctx context.Context, slug string) (*Note, error)

func (*Tx) GetSource

func (t *Tx) GetSource(ctx context.Context, id int64) (*Source, error)

func (*Tx) GetSourceByHash

func (t *Tx) GetSourceByHash(ctx context.Context, hash string) (*Source, error)

func (*Tx) IndexChunk

func (t *Tx) IndexChunk(ctx context.Context, c *Chunk, title string) error

func (*Tx) IndexNote

func (t *Tx) IndexNote(ctx context.Context, n *Note) error

func (*Tx) LinksFromNote

func (t *Tx) LinksFromNote(ctx context.Context, noteID int64) ([]*Link, error)

func (*Tx) LinksToNote

func (t *Tx) LinksToNote(ctx context.Context, noteID int64) ([]*Link, error)

func (*Tx) ListNotes

func (t *Tx) ListNotes(ctx context.Context, kind string, limit, offset int) ([]*Note, error)

func (*Tx) LogOperation

func (t *Tx) LogOperation(ctx context.Context, op *Operation) error

func (*Tx) UpdateNote

func (t *Tx) UpdateNote(ctx context.Context, n *Note, reason string) error

UpdateNote on *Tx trusts the caller's outer transaction and doesn't open a nested one.

Jump to

Keyboard shortcuts

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