• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / storage / 31193672639

07 Aug 2026 03:38PM UTC coverage: 80.689% (+0.09%) from 80.602%
31193672639

Pull #1309

github

web-flow
Merge fda2cc23a into 6b6903971
Pull Request #1309: fix: extract postgres commons for watt

5676 of 7564 branches covered (75.04%)

Branch coverage included in aggregate %.

104 of 111 new or added lines in 9 files covered. (93.69%)

10716 of 12751 relevant lines covered (84.04%)

512.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.0
/src/internal/database/postgres/sql.ts
1
import type { DatabaseStatement, TransactionOptions } from '../connection'
2

3
const POSTGRES_IDENTIFIER_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/
134✔
4

5
export function quoteIdentifier(identifier: string): string {
6
  if (!POSTGRES_IDENTIFIER_PATTERN.test(identifier)) {
20,484✔
7
    throw new Error(`Invalid PostgreSQL identifier: ${identifier}`)
3✔
8
  }
9

10
  return `"${identifier}"`
20,481✔
11
}
12

13
export function quoteQualifiedIdentifier(tableName: string): string {
14
  const [schema, name, ...rest] = tableName.split('.')
24✔
15

16
  if (!schema || !name || rest.length > 0) {
24✔
17
    throw new Error(`Invalid PostgreSQL table name: ${tableName}`)
2✔
18
  }
19

20
  return `${quoteIdentifier(schema)}.${quoteIdentifier(name)}`
22✔
21
}
22

23
export function normalizeStatement(
24
  statement: string | DatabaseStatement,
25
  values?: unknown[]
26
): DatabaseStatement {
27
  if (typeof statement === 'string') {
19,386✔
28
    return { text: statement, values }
8,216✔
29
  }
30

31
  return statement
11,170✔
32
}
33

34
export function buildBeginStatement(options?: TransactionOptions): string {
35
  const modes: string[] = []
3,717✔
36
  const isolationLevel = normalizeIsolationLevel(options?.isolation)
3,717✔
37

38
  if (isolationLevel) {
3,717✔
39
    modes.push(`ISOLATION LEVEL ${isolationLevel}`)
2✔
40
  }
41

42
  if (options?.readOnly) {
3,717✔
43
    modes.push('READ ONLY')
2✔
44
  }
45

46
  return modes.length === 0 ? 'BEGIN' : `BEGIN ${modes.join(', ')}`
3,717✔
47
}
48

49
export function normalizeIsolationLevel(isolation?: string): string | undefined {
50
  switch (isolation?.toLowerCase()) {
3,718!
51
    case 'read committed':
NEW
52
      return 'READ COMMITTED'
×
53
    case 'repeatable read':
54
      return 'REPEATABLE READ'
2✔
55
    case 'serializable':
56
      return 'SERIALIZABLE'
1✔
57
    default:
58
      return undefined
3,715✔
59
  }
60
}
61

62
export function normalizeStatementTimeoutMs(timeoutMs: number | undefined): number | undefined {
63
  if (timeoutMs === undefined || !Number.isFinite(timeoutMs) || timeoutMs <= 0) {
3,903✔
64
    return undefined
717✔
65
  }
66

67
  return timeoutMs
3,186✔
68
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc