// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.31.1 // source: composio.sql package db import ( "context" "github.com/jackc/pgx/v5/pgtype" ) const getUserComposioConnection = `-- name: GetUserComposioConnection :one SELECT id, user_id, toolkit_slug, auth_config_id, connected_account_id, composio_user_id, status, connected_at, last_used_at, created_at, updated_at FROM user_composio_connection WHERE id = $1 AND user_id = $2 ` type GetUserComposioConnectionParams struct { ID pgtype.UUID `json:"id"` UserID pgtype.UUID `json:"user_id"` } // Owner-scoped lookup: a connection can only be read by the user who owns it, // so one user cannot disconnect another's account by guessing the UUID. func (q *Queries) GetUserComposioConnection(ctx context.Context, arg GetUserComposioConnectionParams) (UserComposioConnection, error) { row := q.db.QueryRow(ctx, getUserComposioConnection, arg.ID, arg.UserID) var i UserComposioConnection err := row.Scan( &i.ID, &i.UserID, &i.ToolkitSlug, &i.AuthConfigID, &i.ConnectedAccountID, &i.ComposioUserID, &i.Status, &i.ConnectedAt, &i.LastUsedAt, &i.CreatedAt, &i.UpdatedAt, ) return i, err } const listActiveUserComposioConnections = `-- name: ListActiveUserComposioConnections :many SELECT id, user_id, toolkit_slug, auth_config_id, connected_account_id, composio_user_id, status, connected_at, last_used_at, created_at, updated_at FROM user_composio_connection WHERE user_id = $1 AND status = 'active' ORDER BY connected_at DESC ` func (q *Queries) ListActiveUserComposioConnections(ctx context.Context, userID pgtype.UUID) ([]UserComposioConnection, error) { rows, err := q.db.Query(ctx, listActiveUserComposioConnections, userID) if err != nil { return nil, err } defer rows.Close() items := []UserComposioConnection{} for rows.Next() { var i UserComposioConnection if err := rows.Scan( &i.ID, &i.UserID, &i.ToolkitSlug, &i.AuthConfigID, &i.ConnectedAccountID, &i.ComposioUserID, &i.Status, &i.ConnectedAt, &i.LastUsedAt, &i.CreatedAt, &i.UpdatedAt, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const markUserComposioConnectionRevoked = `-- name: MarkUserComposioConnectionRevoked :exec UPDATE user_composio_connection SET status = 'revoked', updated_at = now() WHERE id = $1 AND user_id = $2 ` type MarkUserComposioConnectionRevokedParams struct { ID pgtype.UUID `json:"id"` UserID pgtype.UUID `json:"user_id"` } // Idempotent: re-running on an already-revoked row is a no-op write. Scoped to // the owner for defense-in-depth. func (q *Queries) MarkUserComposioConnectionRevoked(ctx context.Context, arg MarkUserComposioConnectionRevokedParams) error { _, err := q.db.Exec(ctx, markUserComposioConnectionRevoked, arg.ID, arg.UserID) return err } const upsertUserComposioConnection = `-- name: UpsertUserComposioConnection :one INSERT INTO user_composio_connection ( user_id, toolkit_slug, auth_config_id, connected_account_id, composio_user_id, status ) VALUES ( $1, $2, $3, $4, $5, 'active' ) ON CONFLICT (user_id, connected_account_id) DO UPDATE SET toolkit_slug = EXCLUDED.toolkit_slug, auth_config_id = EXCLUDED.auth_config_id, composio_user_id = EXCLUDED.composio_user_id, status = 'active', updated_at = now() RETURNING id, user_id, toolkit_slug, auth_config_id, connected_account_id, composio_user_id, status, connected_at, last_used_at, created_at, updated_at ` type UpsertUserComposioConnectionParams struct { UserID pgtype.UUID `json:"user_id"` ToolkitSlug string `json:"toolkit_slug"` AuthConfigID string `json:"auth_config_id"` ConnectedAccountID string `json:"connected_account_id"` ComposioUserID string `json:"composio_user_id"` } // ===================== // User Composio Connection // ===================== // Idempotent on (user_id, connected_account_id): a duplicate callback for the // same connected account re-activates the row instead of inserting a second // one. connected_at is preserved on conflict (first-connect time); updated_at // moves so the reactivation is observable. func (q *Queries) UpsertUserComposioConnection(ctx context.Context, arg UpsertUserComposioConnectionParams) (UserComposioConnection, error) { row := q.db.QueryRow(ctx, upsertUserComposioConnection, arg.UserID, arg.ToolkitSlug, arg.AuthConfigID, arg.ConnectedAccountID, arg.ComposioUserID, ) var i UserComposioConnection err := row.Scan( &i.ID, &i.UserID, &i.ToolkitSlug, &i.AuthConfigID, &i.ConnectedAccountID, &i.ComposioUserID, &i.Status, &i.ConnectedAt, &i.LastUsedAt, &i.CreatedAt, &i.UpdatedAt, ) return i, err }