Files
2026-09-09 13:48:51 +10:00

34 lines
1.1 KiB
TypeScript

import type { QueryKey } from '@tanstack/react-query'
import type { RoleImpersonationState } from '@/lib/role-impersonation'
type ResultQueryIdentity = {
sql?: string
roleImpersonationState?: RoleImpersonationState
}
type ResultRowIdentity = Omit<ResultQueryIdentity, 'sql'> & {
table: { schema: string; name: string }
identifiers: Record<string, unknown>
}
export const sqlKeys = {
query: (projectRef: string | undefined, queryKey: QueryKey) =>
['projects', projectRef, 'query', ...queryKey] as const,
// Encrypted connection strings can rotate on project refresh without changing the database.
editableResult: (
projectRef: string | undefined,
{ sql, roleImpersonationState }: ResultQueryIdentity
) => ['projects', projectRef, 'query-result-editing', { sql, roleImpersonationState }] as const,
resultRow: (
projectRef: string | undefined,
{ table, identifiers, roleImpersonationState }: ResultRowIdentity
) =>
[
'projects',
projectRef,
'query-result-row',
{ table, identifiers, roleImpersonationState },
] as const,
}