sqlite

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InsertTenantSQL = `
INSERT INTO tenants(id, name, created_at)
VALUES (?, ?, ?)
`

	TenantExistsSQL = `
SELECT EXISTS(SELECT 1 FROM tenants WHERE id = ?)
`

	CountTenantsSQL = `
SELECT COUNT(1) FROM tenants
`

	CountTenantMemoriesSQL = `
SELECT COUNT(1) FROM memories WHERE tenant_id = ?
`

	ListTenantMemoryCountsSQL = `
SELECT tenant_id, COUNT(1) AS memory_count
FROM memories
WHERE tenant_id IN (%s)
GROUP BY tenant_id
`

	ListTenantsSQL = `
SELECT id, name, created_at
FROM tenants
ORDER BY created_at DESC
LIMIT ?
`

	CountMemoriesSQL = `
SELECT COUNT(1) FROM memories
`

	InsertMemorySQL = `` /* 366-byte string literal not displayed */

	DeleteMemorySQL = `
DELETE FROM memories
WHERE tenant_id = ? AND id = ?
`

	SearchMemoriesSQL = `` /* 510-byte string literal not displayed */

	ListMemoriesRecentSQL = `` /* 347-byte string literal not displayed */

	InsertMemoryFTSSQL = `
INSERT INTO memory_fts(content, tenant_id, memory_id)
VALUES (?, ?, ?)
`

	DeleteMemoryFTSSQL = `
DELETE FROM memory_fts
WHERE tenant_id = ? AND memory_id = ?
`

	GetMemoriesByIDsBaseSQL = `` /* 314-byte string literal not displayed */

	FindMemoryByCanonicalKeySQL = `` /* 346-byte string literal not displayed */

	ListMemoriesBySourceTurnHashSQL = `` /* 487-byte string literal not displayed */

	InsertEntityFactSQL = `` /* 900-byte string literal not displayed */

	ListEntityFactsByEntityRelationSQL = `` /* 250-byte string literal not displayed */

	InvalidateEntityFactsByRelationSQL = `` /* 222-byte string literal not displayed */

	UpsertMemoryIndexJobSQL = `` /* 487-byte string literal not displayed */

	UpdateMemoryIndexJobStateSQL = `` /* 204-byte string literal not displayed */

	UpsertMemoryPostprocessJobSQL = `` /* 538-byte string literal not displayed */

	GetMemoryPostprocessJobIDSQL = `
SELECT id
FROM memory_postprocess_jobs
WHERE tenant_id = ?
  AND memory_id = ?
  AND job_type = ?
LIMIT 1
`

	GetMemoryPostprocessJobByIDSQL = `` /* 213-byte string literal not displayed */

	ListMemoryPostprocessJobsBaseSQL = `` /* 192-byte string literal not displayed */

	ListMemoryPostprocessJobIDsForClaimSQL = `` /* 198-byte string literal not displayed */

	MarkMemoryPostprocessJobClaimedSQL = `
UPDATE memory_postprocess_jobs
SET status = 'running',
	lease_owner = ?,
	leased_until = ?,
	updated_at = ?
WHERE id = ?
`

	MarkMemoryPostprocessJobSucceededSQL = `` /* 144-byte string literal not displayed */

	MarkMemoryPostprocessJobFailedSQL = `` /* 167-byte string literal not displayed */

)

Variables

This section is empty.

Functions

func Open

func Open(ctx context.Context, dsn string) (*sql.DB, error)

func RunMigrations

func RunMigrations(ctx context.Context, db *sql.DB) error

Types

type EntityFactRepository

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

func NewEntityFactRepository

func NewEntityFactRepository(db *sql.DB) *EntityFactRepository

func (*EntityFactRepository) InvalidateEntityRelation

func (r *EntityFactRepository) InvalidateEntityRelation(
	ctx context.Context,
	tenantID, entity, relation, activeValue, invalidatedByFactID string,
	validTo time.Time,
) error

func (*EntityFactRepository) ListByEntityRelation

func (r *EntityFactRepository) ListByEntityRelation(
	ctx context.Context,
	tenantID, entity, relation string,
	limit int,
) ([]domain.EntityFact, error)

func (*EntityFactRepository) Store

func (*EntityFactRepository) StoreBatch

func (r *EntityFactRepository) StoreBatch(ctx context.Context, facts []domain.EntityFact) ([]domain.EntityFact, error)

type MemoryRepository

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

func NewMemoryRepository

func NewMemoryRepository(db *sql.DB) *MemoryRepository

func (*MemoryRepository) ClaimPostprocessJobs

func (*MemoryRepository) Count

func (r *MemoryRepository) Count(ctx context.Context) (int64, error)

func (*MemoryRepository) Delete

func (r *MemoryRepository) Delete(ctx context.Context, tenantID, memoryID string) error

func (*MemoryRepository) EnqueuePostprocessJobs

func (r *MemoryRepository) EnqueuePostprocessJobs(
	ctx context.Context,
	jobs []domain.MemoryPostprocessJobEnqueue,
	defaultMaxAttempts int,
) ([]domain.MemoryPostprocessJob, error)

func (*MemoryRepository) FindByCanonicalKey

func (r *MemoryRepository) FindByCanonicalKey(
	ctx context.Context,
	tenantID, canonicalKey string,
) (*domain.Memory, error)

func (*MemoryRepository) GetByIDs

func (r *MemoryRepository) GetByIDs(ctx context.Context, tenantID string, ids []string) ([]domain.Memory, error)

func (*MemoryRepository) GetPostprocessJob

func (r *MemoryRepository) GetPostprocessJob(ctx context.Context, jobID string) (*domain.MemoryPostprocessJob, error)

func (*MemoryRepository) ListBySourceTurnHash

func (r *MemoryRepository) ListBySourceTurnHash(
	ctx context.Context,
	tenantID, sourceTurnHash string,
	limit int,
) ([]domain.Memory, error)

func (*MemoryRepository) ListPostprocessJobs

func (*MemoryRepository) MarkIndexState

func (r *MemoryRepository) MarkIndexState(
	ctx context.Context,
	tenantID string,
	memoryIDs []string,
	op domain.MemoryIndexOperation,
	state domain.MemoryIndexState,
	lastError string,
) error

func (*MemoryRepository) MarkPostprocessJobFailed

func (r *MemoryRepository) MarkPostprocessJobFailed(
	ctx context.Context,
	jobID string,
	now time.Time,
	nextAvailable time.Time,
	attempts int,
	status domain.PostprocessJobStatus,
	lastError string,
) error

func (*MemoryRepository) MarkPostprocessJobSucceeded

func (r *MemoryRepository) MarkPostprocessJobSucceeded(ctx context.Context, jobID string, now time.Time) error

func (*MemoryRepository) Search

func (r *MemoryRepository) Search(ctx context.Context, tenantID, query string, topK int) ([]domain.Memory, error)

func (*MemoryRepository) SearchWithFilters

func (r *MemoryRepository) SearchWithFilters(
	ctx context.Context,
	tenantID, query string,
	topK int,
	filters domain.MemorySearchFilters,
) ([]domain.Memory, error)

func (*MemoryRepository) Store

func (*MemoryRepository) StoreBatch

func (r *MemoryRepository) StoreBatch(ctx context.Context, memories []domain.Memory) ([]domain.Memory, error)

func (*MemoryRepository) StoreBatchAsyncIngest

func (r *MemoryRepository) StoreBatchAsyncIngest(
	ctx context.Context,
	items []domain.MemoryAsyncIngestItem,
	maxAttempts int,
) (domain.MemoryIngestReceipt, error)

func (*MemoryRepository) Touch

func (r *MemoryRepository) Touch(ctx context.Context, tenantID string, ids []string) error

type TenantRepository

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

func NewTenantRepository

func NewTenantRepository(db *sql.DB) *TenantRepository

func (*TenantRepository) Count

func (r *TenantRepository) Count(ctx context.Context) (int64, error)

func (*TenantRepository) Create

func (*TenantRepository) Exists

func (r *TenantRepository) Exists(ctx context.Context, tenantID string) (bool, error)

func (*TenantRepository) List

func (r *TenantRepository) List(ctx context.Context, limit int) ([]domain.Tenant, error)

func (*TenantRepository) ListMemoryCounts

func (r *TenantRepository) ListMemoryCounts(ctx context.Context, tenantIDs []string) (map[string]int64, error)

func (*TenantRepository) MemoryCount

func (r *TenantRepository) MemoryCount(ctx context.Context, tenantID string) (int64, error)

Jump to

Keyboard shortcuts

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