INNER CODE UNIT · Rust

ensure_client_tx

zly2006/zhihu-plus-plus · aigc-vote-server/src/lib.rs:1009

async fn ensure_client_tx(
    tx: &mut Transaction<'_, Postgres>,
    client_id: &str,
) -> Result<(), ServiceError> {
    let now = now_epoch_seconds();
    sqlx::query(
        r#"
        INSERT INTO clients (id, credit, progress, created_at, last_seen_at)
        VALUES ($1, $2, 0, $3, $3)
        ON CONFLICT(id) DO UPDATE SET last_seen_at = EXCLUDED.last_seen_at
        "#,
    )
    .bind(client_id)
    .bind(INITIAL_CREDIT)
    .bind(now)
    .execute(&mut **tx)
    .await?;
    Ok(())

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…