sqlite

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package sqlite provides a SQLite-backed session store for the agent package.

This package implements the session.Store interface using SQLite for durable session persistence. It automatically creates the required tables on initialization.

Installation

This is a separate Go module to avoid adding database dependencies to the core library:

go get github.com/joakimcarlsson/ai/memory/sqlite

Basic Usage

The package accepts an existing *sql.DB connection, allowing the caller to choose their preferred SQLite driver and configure connection settings:

import "github.com/joakimcarlsson/ai/memory/sqlite"

store, err := sqlite.SessionStore(ctx, db)
if err != nil {
    log.Fatal(err)
}

myAgent := agent.New(llmClient,
    agent.WithSession("user-123", store),
)

Table Prefix

Use WithTablePrefix to namespace tables and avoid conflicts with existing schemas:

store, err := sqlite.SessionStore(ctx, db,
    sqlite.WithTablePrefix("chat_"),
)

This creates "chat_sessions" and "chat_messages" tables instead of the default "sessions" and "messages".

Database Schema

The package creates two tables:

  • sessions: Stores session metadata (id, created_at)
  • messages: Stores messages with foreign key to sessions (id, session_id, role, parts, model, created_at)

Messages are stored as JSON text for flexible content part serialization.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SessionStore

func SessionStore(
	ctx context.Context,
	db *sql.DB,
	opts ...Option,
) (session.Store, error)

SessionStore creates a new SQLite-backed session store using the provided database connection. It automatically creates the required tables if they don't exist.

Types

type Option

type Option func(*storeOptions)

Option configures a sqlite store.

func WithTablePrefix

func WithTablePrefix(prefix string) Option

WithTablePrefix sets a prefix for all table names created by the store. For example, WithTablePrefix("chat_") creates "chat_sessions" and "chat_messages" instead of "sessions" and "messages".

Jump to

Keyboard shortcuts

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