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

typeorm / typeorm / 15219332477

23 May 2025 09:13PM UTC coverage: 17.216% (-59.1%) from 76.346%
15219332477

Pull #11332

github

naorpeled
cr comments - move if block
Pull Request #11332: feat: add new undefined and null behavior flags

1603 of 12759 branches covered (12.56%)

Branch coverage included in aggregate %.

0 of 31 new or added lines in 3 files covered. (0.0%)

14132 existing lines in 166 files now uncovered.

4731 of 24033 relevant lines covered (19.69%)

60.22 hits per line

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

88.89
/src/util/SqlTagUtils.ts
1
import { Driver } from "../driver/Driver"
2
import dedent from "dedent"
1✔
3

4
interface BuildSqlTagParams {
5
    driver: Driver
6
    strings: TemplateStringsArray
7
    expressions: unknown[]
8
}
9

10
export function buildSqlTag({
1✔
11
    driver,
12
    strings,
13
    expressions,
14
}: BuildSqlTagParams): { query: string; parameters: unknown[] } {
15
    let query = ""
11✔
16
    const parameters: unknown[] = []
11✔
17
    let idx = 0
11✔
18

19
    for (const [expressionIdx, expression] of expressions.entries()) {
11✔
20
        query += strings[expressionIdx]
17✔
21

22
        if (expression === null) {
17!
UNCOV
23
            query += "NULL"
×
UNCOV
24
            continue
×
25
        }
26

27
        if (typeof expression === "function") {
17✔
28
            const value = expression()
7✔
29

30
            if (typeof value === "string") {
7✔
31
                query += value
1✔
32
                continue
1✔
33
            }
34

35
            if (Array.isArray(value)) {
6✔
36
                if (value.length === 0) {
5✔
37
                    throw new Error(
1✔
38
                        `Expression ${expressionIdx} in this sql tagged template is a function which returned an empty array. Empty arrays cannot safely be expanded into parameter lists.`,
39
                    )
40
                }
41

42
                const arrayParams = value.map(() => {
4✔
43
                    return driver.createParameter(`param_${idx + 1}`, idx++)
8✔
44
                })
45

46
                query += arrayParams.join(", ")
4✔
47
                parameters.push(...value)
4✔
48

49
                continue
4✔
50
            }
51

52
            throw new Error(
1✔
53
                `Expression ${expressionIdx} in this sql tagged template is a function which returned a value of type "${
54
                    value === null ? "null" : typeof value
1!
55
                }". Only array and string types are supported as function return values in sql tagged template expressions.`,
56
            )
57
        }
58

59
        query += driver.createParameter(`param_${idx + 1}`, idx++)
10✔
60

61
        parameters.push(expression)
10✔
62
    }
63

64
    query += strings[strings.length - 1]
9✔
65

66
    query = dedent(query)
9✔
67

68
    return { query, parameters }
9✔
69
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc