Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

641 B
Raw Blame
//! Insert a new chat row.

use model_owner::Owner;
use sqlx::{Postgres, Transaction};

/// Insert a new chat and return the generated chat ID.
#[tracing::instrument(err, skip(tx))]
pub(crate) async fn insert_chat(
    tx: &mut Transaction<'_, Postgres>,
    owner: &Owner,
    name: &str,
    project_id: Option<&str>,
) -> anyhow::Result<String> {
    let row = sqlx::query_scalar!(
        r#"
        INSERT INTO "Chat" ("userId", name, "projectId")
        VALUES ($1, $2, $3)
        RETURNING id
        "#,
        owner.principal_id(),
        name,
        project_id,
    )
    .fetch_one(tx.as_mut())
    .await?;

    Ok(row)
}