// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.30.0 // source: notification_preferences.sql package db import ( "context" "github.com/jackc/pgx/v5/pgtype" ) const deleteNotificationPreferences = `-- name: DeleteNotificationPreferences :exec DELETE FROM notification_preference WHERE workspace_id = $1 AND user_id = $2 ` type DeleteNotificationPreferencesParams struct { WorkspaceID pgtype.UUID `json:"workspace_id"` UserID pgtype.UUID `json:"user_id"` } func (q *Queries) DeleteNotificationPreferences(ctx context.Context, arg DeleteNotificationPreferencesParams) error { _, err := q.db.Exec(ctx, deleteNotificationPreferences, arg.WorkspaceID, arg.UserID) return err } const getDisabledNotificationTypes = `-- name: GetDisabledNotificationTypes :many SELECT notification_type FROM notification_preference WHERE workspace_id = $1 AND user_id = $2 AND enabled = false ` type GetDisabledNotificationTypesParams struct { WorkspaceID pgtype.UUID `json:"workspace_id"` UserID pgtype.UUID `json:"user_id"` } func (q *Queries) GetDisabledNotificationTypes(ctx context.Context, arg GetDisabledNotificationTypesParams) ([]string, error) { rows, err := q.db.Query(ctx, getDisabledNotificationTypes, arg.WorkspaceID, arg.UserID) if err != nil { return nil, err } defer rows.Close() items := []string{} for rows.Next() { var notification_type string if err := rows.Scan(¬ification_type); err != nil { return nil, err } items = append(items, notification_type) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const listNotificationPreferences = `-- name: ListNotificationPreferences :many SELECT id, workspace_id, user_id, notification_type, enabled, created_at, updated_at FROM notification_preference WHERE workspace_id = $1 AND user_id = $2 ORDER BY notification_type ` type ListNotificationPreferencesParams struct { WorkspaceID pgtype.UUID `json:"workspace_id"` UserID pgtype.UUID `json:"user_id"` } func (q *Queries) ListNotificationPreferences(ctx context.Context, arg ListNotificationPreferencesParams) ([]NotificationPreference, error) { rows, err := q.db.Query(ctx, listNotificationPreferences, arg.WorkspaceID, arg.UserID) if err != nil { return nil, err } defer rows.Close() items := []NotificationPreference{} for rows.Next() { var i NotificationPreference if err := rows.Scan( &i.ID, &i.WorkspaceID, &i.UserID, &i.NotificationType, &i.Enabled, &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 listNotificationPreferencesByType = `-- name: ListNotificationPreferencesByType :many SELECT user_id, enabled FROM notification_preference WHERE workspace_id = $1 AND notification_type = $2 ` type ListNotificationPreferencesByTypeParams struct { WorkspaceID pgtype.UUID `json:"workspace_id"` NotificationType string `json:"notification_type"` } type ListNotificationPreferencesByTypeRow struct { UserID pgtype.UUID `json:"user_id"` Enabled bool `json:"enabled"` } func (q *Queries) ListNotificationPreferencesByType(ctx context.Context, arg ListNotificationPreferencesByTypeParams) ([]ListNotificationPreferencesByTypeRow, error) { rows, err := q.db.Query(ctx, listNotificationPreferencesByType, arg.WorkspaceID, arg.NotificationType) if err != nil { return nil, err } defer rows.Close() items := []ListNotificationPreferencesByTypeRow{} for rows.Next() { var i ListNotificationPreferencesByTypeRow if err := rows.Scan(&i.UserID, &i.Enabled); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const upsertNotificationPreference = `-- name: UpsertNotificationPreference :one INSERT INTO notification_preference (workspace_id, user_id, notification_type, enabled) VALUES ($1, $2, $3, $4) ON CONFLICT (workspace_id, user_id, notification_type) DO UPDATE SET enabled = $4, updated_at = now() RETURNING id, workspace_id, user_id, notification_type, enabled, created_at, updated_at ` type UpsertNotificationPreferenceParams struct { WorkspaceID pgtype.UUID `json:"workspace_id"` UserID pgtype.UUID `json:"user_id"` NotificationType string `json:"notification_type"` Enabled bool `json:"enabled"` } func (q *Queries) UpsertNotificationPreference(ctx context.Context, arg UpsertNotificationPreferenceParams) (NotificationPreference, error) { row := q.db.QueryRow(ctx, upsertNotificationPreference, arg.WorkspaceID, arg.UserID, arg.NotificationType, arg.Enabled, ) var i NotificationPreference err := row.Scan( &i.ID, &i.WorkspaceID, &i.UserID, &i.NotificationType, &i.Enabled, &i.CreatedAt, &i.UpdatedAt, ) return i, err }