Changeset 0.28.0.8 (#180)
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.gobha.me/xcaliber/chat-switchboard/models"
|
||||
"git.gobha.me/xcaliber/chat-switchboard/store"
|
||||
@@ -42,6 +41,16 @@ func (s *MemoryStore) Upsert(ctx context.Context, m *models.Memory) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *MemoryStore) Update(ctx context.Context, m *models.Memory) error {
|
||||
_, err := DB.ExecContext(ctx, `
|
||||
UPDATE memories
|
||||
SET key = $1, value = $2, confidence = $3, status = $4,
|
||||
source_channel_id = $5, updated_at = now()
|
||||
WHERE id = $6
|
||||
`, m.Key, m.Value, m.Confidence, m.Status, m.SourceChannelID, m.ID)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *MemoryStore) GetByID(ctx context.Context, id string) (*models.Memory, error) {
|
||||
m := &models.Memory{}
|
||||
err := DB.QueryRowContext(ctx, `
|
||||
@@ -220,6 +229,25 @@ func (s *MemoryStore) CountByOwner(ctx context.Context, scope, ownerID string) (
|
||||
return count, err
|
||||
}
|
||||
|
||||
func (s *MemoryStore) ListByStatus(ctx context.Context, status string, limit int) ([]models.Memory, error) {
|
||||
if limit <= 0 || limit > 500 {
|
||||
limit = 100
|
||||
}
|
||||
rows, err := DB.QueryContext(ctx, `
|
||||
SELECT id, scope, owner_id, user_id, key, value,
|
||||
source_channel_id, confidence, status, created_at, updated_at
|
||||
FROM memories
|
||||
WHERE status = $1
|
||||
ORDER BY created_at DESC
|
||||
LIMIT $2
|
||||
`, status, limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
return scanMemories(rows)
|
||||
}
|
||||
|
||||
// ── Helpers ─────────────────────────────────
|
||||
|
||||
func scanMemories(rows *sql.Rows) ([]models.Memory, error) {
|
||||
@@ -240,30 +268,5 @@ func scanMemories(rows *sql.Rows) ([]models.Memory, error) {
|
||||
return memories, rows.Err()
|
||||
}
|
||||
|
||||
// scanMemory scans a single memory row — unused currently but available
|
||||
// for future single-row queries.
|
||||
func scanMemory(row *sql.Row) (*models.Memory, error) {
|
||||
m := &models.Memory{}
|
||||
err := row.Scan(
|
||||
&m.ID, &m.Scope, &m.OwnerID, &m.UserID, &m.Key, &m.Value,
|
||||
&m.SourceChannelID, &m.Confidence, &m.Status, &m.CreatedAt, &m.UpdatedAt,
|
||||
)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
}
|
||||
return m, err
|
||||
}
|
||||
|
||||
// ensure compile-time interface satisfaction
|
||||
var _ interface {
|
||||
Upsert(ctx context.Context, m *models.Memory) error
|
||||
GetByID(ctx context.Context, id string) (*models.Memory, error)
|
||||
List(ctx context.Context, f models.MemoryFilter) ([]models.Memory, error)
|
||||
Delete(ctx context.Context, id string) error
|
||||
Archive(ctx context.Context, id string) error
|
||||
Recall(ctx context.Context, userID string, personaID *string, query string, limit int) ([]models.Memory, error)
|
||||
CountByOwner(ctx context.Context, scope, ownerID string) (int, error)
|
||||
} = (*MemoryStore)(nil)
|
||||
|
||||
// ensure unused imports don't cause errors
|
||||
var _ = time.Now
|
||||
var _ store.MemoryStore = (*MemoryStore)(nil)
|
||||
|
||||
@@ -2,7 +2,6 @@ package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@@ -130,6 +129,3 @@ func mergeResults(semantic, keyword []models.Memory, limit int) []models.Memory
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// ensure unused
|
||||
var _ = sql.ErrNoRows
|
||||
|
||||
Reference in New Issue
Block a user