minimal working version of backend and cli
This commit is contained in:
@@ -86,3 +86,29 @@ func (r *Repo) LatestParent(ctx context.Context, childID int64) (models.Node, bo
|
||||
}
|
||||
return n, true, nil
|
||||
}
|
||||
|
||||
func (r *Repo) DeleteBranch(ctx context.Context, convID int64, name string) error {
|
||||
_, err := r.db.ExecContext(ctx, `DELETE FROM branches WHERE conversation_id=? AND name=?`, convID, name)
|
||||
return err
|
||||
}
|
||||
|
||||
// ListBranches returns all branches for a conversation, newest first.
|
||||
func (r *Repo) ListBranches(ctx context.Context, convID int64) ([]models.Branch, error) {
|
||||
rows, err := r.db.QueryContext(ctx, `
|
||||
SELECT id, conversation_id, name, head_node_id
|
||||
FROM branches
|
||||
WHERE conversation_id=?
|
||||
ORDER BY id DESC`, convID)
|
||||
if err != nil { return nil, err }
|
||||
defer rows.Close()
|
||||
|
||||
var out []models.Branch
|
||||
for rows.Next() {
|
||||
var b models.Branch
|
||||
if err := rows.Scan(&b.ID, &b.ConversationID, &b.Name, &b.HeadNodeID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, b)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user