This repository has been archived on 2026-04-03. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
core/server/store/sqlite/persona_mention.go
Jeffrey Smith 11fd8c1e57 step 1: rename module chat-switchboard → switchboard-core
- go.mod module name
- All 714 import references across 289 Go files
- VERSION: 0.1.0
- CI DB names: switchboard_core_{ci,dev,test}
- Docker image: gobha/switchboard-core
- Test fixtures: JWT issuer, repo names
- .env.example, docker-compose container name
- Compiles clean (go build exit 0)
2026-03-25 19:48:04 -04:00

81 lines
2.1 KiB
Go

package sqlite
import (
"context"
"database/sql"
"switchboard-core/store"
)
// ── Mention resolution + display info (v0.29.0) ────────────────────────
func (s *PersonaStore) FindActiveByHandle(ctx context.Context, handle string) (string, error) {
var id string
err := DB.QueryRowContext(ctx, `
SELECT id FROM personas
WHERE LOWER(handle) = LOWER(?) AND is_active = 1
LIMIT 1
`, handle).Scan(&id)
if err == sql.ErrNoRows {
return "", nil
}
return id, err
}
func (s *PersonaStore) FindActiveByHandlePrefix(ctx context.Context, prefix string) (string, int, error) {
var count int
err := DB.QueryRowContext(ctx, `
SELECT COUNT(*) FROM personas WHERE LOWER(handle) LIKE LOWER(?) AND is_active = 1
`, prefix+"%").Scan(&count)
if err != nil {
return "", 0, err
}
if count != 1 {
return "", count, nil
}
var id string
err = DB.QueryRowContext(ctx, `
SELECT id FROM personas WHERE LOWER(handle) LIKE LOWER(?) AND is_active = 1
`, prefix+"%").Scan(&id)
return id, 1, err
}
func (s *PersonaStore) GetNameByID(ctx context.Context, id string) (string, error) {
var name string
err := DB.QueryRowContext(ctx, `SELECT name FROM personas WHERE id = ?`, id).Scan(&name)
if err == sql.ErrNoRows {
return "", nil
}
return name, err
}
func (s *PersonaStore) GetNamesByIDs(ctx context.Context, ids []string) (map[string]string, error) {
result := make(map[string]string)
for _, id := range ids {
var name string
err := DB.QueryRowContext(ctx, `SELECT name FROM personas WHERE id = ?`, id).Scan(&name)
if err == nil && name != "" {
result[id] = name
}
}
return result, nil
}
func (s *PersonaStore) GetDisplayInfoByIDs(ctx context.Context, ids []string) (map[string]store.UserDisplayInfo, error) {
result := make(map[string]store.UserDisplayInfo)
for _, id := range ids {
var name, avatar sql.NullString
_ = DB.QueryRowContext(ctx, `
SELECT name, avatar FROM personas WHERE id = ?
`, id).Scan(&name, &avatar)
if name.Valid {
info := store.UserDisplayInfo{Name: name.String}
if avatar.Valid {
info.Avatar = avatar.String
}
result[id] = info
}
}
return result, nil
}