Changeset 0.29.0 (#195)
This commit is contained in:
143
server/store/sqlite/channel_helpers.go
Normal file
143
server/store/sqlite/channel_helpers.go
Normal file
@@ -0,0 +1,143 @@
|
||||
package sqlite
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
// ── Single-field helpers (v0.29.0) ──────────────────────────────────────
|
||||
|
||||
func (s *ChannelStore) GetAIMode(ctx context.Context, channelID string) (string, error) {
|
||||
var aiMode string
|
||||
err := DB.QueryRowContext(ctx, `
|
||||
SELECT COALESCE(ai_mode, 'auto') FROM channels WHERE id = ?
|
||||
`, channelID).Scan(&aiMode)
|
||||
if err != nil {
|
||||
return "auto", err
|
||||
}
|
||||
return aiMode, nil
|
||||
}
|
||||
|
||||
func (s *ChannelStore) GetTypeAndTeamID(ctx context.Context, channelID string) (string, *string, error) {
|
||||
var channelType string
|
||||
var teamID *string
|
||||
err := DB.QueryRowContext(ctx, `
|
||||
SELECT COALESCE(type, 'direct'), team_id FROM channels WHERE id = ?
|
||||
`, channelID).Scan(&channelType, &teamID)
|
||||
return channelType, teamID, err
|
||||
}
|
||||
|
||||
func (s *ChannelStore) GetSystemPrompt(ctx context.Context, channelID string) (*string, error) {
|
||||
var prompt *string
|
||||
err := DB.QueryRowContext(ctx, `
|
||||
SELECT system_prompt FROM channels WHERE id = ?
|
||||
`, channelID).Scan(&prompt)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
}
|
||||
return prompt, err
|
||||
}
|
||||
|
||||
func (s *ChannelStore) GetDefaultModel(ctx context.Context, channelID string) (*string, error) {
|
||||
var model *string
|
||||
err := DB.QueryRowContext(ctx, `
|
||||
SELECT model FROM channels WHERE id = ?
|
||||
`, channelID).Scan(&model)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
}
|
||||
return model, err
|
||||
}
|
||||
|
||||
func (s *ChannelStore) TouchUpdatedAt(ctx context.Context, channelID string) error {
|
||||
_, err := DB.ExecContext(ctx, `UPDATE channels SET updated_at = datetime('now') WHERE id = ?`, channelID)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *ChannelStore) ListUserParticipantIDs(ctx context.Context, channelID, excludeUserID string) ([]string, error) {
|
||||
rows, err := DB.QueryContext(ctx, `
|
||||
SELECT participant_id FROM channel_participants
|
||||
WHERE channel_id = ? AND participant_type = 'user' AND participant_id != ?
|
||||
`, channelID, excludeUserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var ids []string
|
||||
for rows.Next() {
|
||||
var id string
|
||||
if err := rows.Scan(&id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ids = append(ids, id)
|
||||
}
|
||||
if ids == nil {
|
||||
ids = []string{}
|
||||
}
|
||||
return ids, rows.Err()
|
||||
}
|
||||
|
||||
func (s *ChannelStore) ListPersonaParticipantIDs(ctx context.Context, channelID string) ([]string, error) {
|
||||
rows, err := DB.QueryContext(ctx, `
|
||||
SELECT participant_id FROM channel_participants
|
||||
WHERE channel_id = ? AND participant_type = 'persona'
|
||||
ORDER BY created_at
|
||||
`, channelID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var ids []string
|
||||
for rows.Next() {
|
||||
var id string
|
||||
if err := rows.Scan(&id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ids = append(ids, id)
|
||||
}
|
||||
if ids == nil {
|
||||
ids = []string{}
|
||||
}
|
||||
return ids, rows.Err()
|
||||
}
|
||||
|
||||
func (s *ChannelStore) GetLeaderPersonaID(ctx context.Context, channelID string) (string, error) {
|
||||
var leaderID string
|
||||
err := DB.QueryRowContext(ctx, `
|
||||
SELECT cp.participant_id
|
||||
FROM channel_participants cp
|
||||
JOIN persona_group_members pgm ON pgm.persona_id = cp.participant_id
|
||||
WHERE cp.channel_id = ?
|
||||
AND cp.participant_type = 'persona'
|
||||
AND pgm.is_leader = 1
|
||||
LIMIT 1
|
||||
`, channelID).Scan(&leaderID)
|
||||
if err == nil && leaderID != "" {
|
||||
return leaderID, nil
|
||||
}
|
||||
|
||||
err = DB.QueryRowContext(ctx, `
|
||||
SELECT participant_id FROM channel_participants
|
||||
WHERE channel_id = ? AND participant_type = 'persona'
|
||||
ORDER BY created_at LIMIT 1
|
||||
`, channelID).Scan(&leaderID)
|
||||
if err == sql.ErrNoRows {
|
||||
return "", nil
|
||||
}
|
||||
return leaderID, err
|
||||
}
|
||||
|
||||
func (s *ChannelStore) GetWorkflowInfo(ctx context.Context, channelID string) (*string, int, error) {
|
||||
var workflowID *string
|
||||
var currentStage int
|
||||
err := DB.QueryRowContext(ctx, `
|
||||
SELECT workflow_id, COALESCE(current_stage, 0)
|
||||
FROM channels WHERE id = ? AND type = 'workflow'
|
||||
`, channelID).Scan(&workflowID, ¤tStage)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, 0, nil
|
||||
}
|
||||
return workflowID, currentStage, err
|
||||
}
|
||||
Reference in New Issue
Block a user