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

typeorm / typeorm / 15089093306

17 May 2025 09:03PM UTC coverage: 50.109% (-26.2%) from 76.346%
15089093306

Pull #11437

github

naorpeled
add comment about vector <#>
Pull Request #11437: feat(postgres): support vector data type

5836 of 12767 branches covered (45.71%)

Branch coverage included in aggregate %.

16 of 17 new or added lines in 4 files covered. (94.12%)

6283 existing lines in 64 files now uncovered.

12600 of 24025 relevant lines covered (52.45%)

28708.0 hits per line

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

87.18
/src/naming-strategy/DefaultNamingStrategy.ts
1
import { NamingStrategyInterface } from "./NamingStrategyInterface"
2
import { RandomGenerator } from "../util/RandomGenerator"
6✔
3
import { camelCase, snakeCase, titleCase } from "../util/StringUtils"
6✔
4
import { Table } from "../schema-builder/table/Table"
5

6
/**
7
 * Naming strategy that is used by default.
8
 */
9
export class DefaultNamingStrategy implements NamingStrategyInterface {
6✔
10
    protected getTableName(tableOrName: Table | string): string {
11
        if (typeof tableOrName !== "string") {
17,030✔
12
            tableOrName = tableOrName.name
6,770✔
13
        }
14

15
        return tableOrName.split(".").pop()!
17,030✔
16
    }
17
    /**
18
     * Normalizes table name.
19
     *
20
     * @param targetName Name of the target entity that can be used to generate a table name.
21
     * @param userSpecifiedName For example if user specified a table name in a decorator, e.g. @Entity("name")
22
     */
23
    tableName(
24
        targetName: string,
25
        userSpecifiedName: string | undefined,
26
    ): string {
27
        return userSpecifiedName ? userSpecifiedName : snakeCase(targetName)
7,406✔
28
    }
29

30
    /**
31
     * Creates a table name for a junction table of a closure table.
32
     *
33
     * @param originalClosureTableName Name of the closure table which owns this junction table.
34
     */
35
    closureJunctionTableName(originalClosureTableName: string): string {
36
        return originalClosureTableName + "_closure"
114✔
37
    }
38

39
    columnName(
40
        propertyName: string,
41
        customName: string,
42
        embeddedPrefixes: string[],
43
    ): string {
44
        const name = customName || propertyName
89,110✔
45

46
        if (embeddedPrefixes.length)
89,110✔
47
            return camelCase(embeddedPrefixes.join("_")) + titleCase(name)
2,752✔
48

49
        return name
86,358✔
50
    }
51

52
    relationName(propertyName: string): string {
53
        return propertyName
×
54
    }
55

56
    primaryKeyName(tableOrName: Table | string, columnNames: string[]): string {
57
        // sort incoming column names to avoid issue when ["id", "name"] and ["name", "id"] arrays
58
        const clonedColumnNames = [...columnNames]
6,210✔
59
        clonedColumnNames.sort()
6,210✔
60
        const tableName = this.getTableName(tableOrName)
6,210✔
61
        const replacedTableName = tableName.replace(".", "_")
6,210✔
62
        const key = `${replacedTableName}_${clonedColumnNames.join("_")}`
6,210✔
63
        return "PK_" + RandomGenerator.sha1(key).substr(0, 27)
6,210✔
64
    }
65

66
    uniqueConstraintName(
67
        tableOrName: Table | string,
68
        columnNames: string[],
69
    ): string {
70
        // sort incoming column names to avoid issue when ["id", "name"] and ["name", "id"] arrays
71
        const clonedColumnNames = [...columnNames]
987✔
72
        clonedColumnNames.sort()
987✔
73
        const tableName = this.getTableName(tableOrName)
987✔
74
        const replacedTableName = tableName.replace(".", "_")
987✔
75
        const key = `${replacedTableName}_${clonedColumnNames.join("_")}`
987✔
76
        return "UQ_" + RandomGenerator.sha1(key).substr(0, 27)
987✔
77
    }
78

79
    relationConstraintName(
80
        tableOrName: Table | string,
81
        columnNames: string[],
82
        where?: string,
83
    ): string {
84
        // sort incoming column names to avoid issue when ["id", "name"] and ["name", "id"] arrays
85
        const clonedColumnNames = [...columnNames]
496✔
86
        clonedColumnNames.sort()
496✔
87
        const tableName = this.getTableName(tableOrName)
496✔
88
        const replacedTableName = tableName.replace(".", "_")
496✔
89
        let key = `${replacedTableName}_${clonedColumnNames.join("_")}`
496✔
90
        if (where) key += `_${where}`
496!
91

92
        return "REL_" + RandomGenerator.sha1(key).substr(0, 26)
496✔
93
    }
94

95
    defaultConstraintName(
96
        tableOrName: Table | string,
97
        columnName: string,
98
    ): string {
UNCOV
99
        const tableName = this.getTableName(tableOrName)
×
UNCOV
100
        const replacedTableName = tableName.replace(".", "_")
×
UNCOV
101
        const key = `${replacedTableName}_${columnName}`
×
UNCOV
102
        return "DF_" + RandomGenerator.sha1(key).substr(0, 27)
×
103
    }
104

105
    foreignKeyName(
106
        tableOrName: Table | string,
107
        columnNames: string[],
108
        _referencedTablePath?: string,
109
        _referencedColumnNames?: string[],
110
    ): string {
111
        // sort incoming column names to avoid issue when ["id", "name"] and ["name", "id"] arrays
112
        const clonedColumnNames = [...columnNames]
6,498✔
113
        clonedColumnNames.sort()
6,498✔
114
        const tableName = this.getTableName(tableOrName)
6,498✔
115
        const replacedTableName = tableName.replace(".", "_")
6,498✔
116
        const key = `${replacedTableName}_${clonedColumnNames.join("_")}`
6,498✔
117
        return "FK_" + RandomGenerator.sha1(key).substr(0, 27)
6,498✔
118
    }
119

120
    indexName(
121
        tableOrName: Table | string,
122
        columnNames: string[],
123
        where?: string,
124
    ): string {
125
        // sort incoming column names to avoid issue when ["id", "name"] and ["name", "id"] arrays
126
        const clonedColumnNames = [...columnNames]
2,569✔
127
        clonedColumnNames.sort()
2,569✔
128
        const tableName = this.getTableName(tableOrName)
2,569✔
129
        const replacedTableName = tableName.replace(".", "_")
2,569✔
130
        let key = `${replacedTableName}_${clonedColumnNames.join("_")}`
2,569✔
131
        if (where) key += `_${where}`
2,569✔
132

133
        return "IDX_" + RandomGenerator.sha1(key).substr(0, 26)
2,569✔
134
    }
135

136
    checkConstraintName(
137
        tableOrName: Table | string,
138
        expression: string,
139
        isEnum?: boolean,
140
    ): string {
141
        const tableName = this.getTableName(tableOrName)
233✔
142
        const replacedTableName = tableName.replace(".", "_")
233✔
143
        const key = `${replacedTableName}_${expression}`
233✔
144
        const name = "CHK_" + RandomGenerator.sha1(key).substr(0, 26)
233✔
145
        return isEnum ? `${name}_ENUM` : name
233!
146
    }
147

148
    exclusionConstraintName(
149
        tableOrName: Table | string,
150
        expression: string,
151
    ): string {
152
        const tableName = this.getTableName(tableOrName)
37✔
153
        const replacedTableName = tableName.replace(".", "_")
37✔
154
        const key = `${replacedTableName}_${expression}`
37✔
155
        return "XCL_" + RandomGenerator.sha1(key).substr(0, 26)
37✔
156
    }
157

158
    joinColumnName(relationName: string, referencedColumnName: string): string {
159
        return camelCase(relationName + "_" + referencedColumnName)
2,111✔
160
    }
161

162
    joinTableName(
163
        firstTableName: string,
164
        secondTableName: string,
165
        firstPropertyName: string,
166
        secondPropertyName: string,
167
    ): string {
168
        return snakeCase(
580✔
169
            firstTableName +
170
                "_" +
171
                firstPropertyName.replace(/\./gi, "_") +
172
                "_" +
173
                secondTableName,
174
        )
175
    }
176

177
    joinTableColumnDuplicationPrefix(
178
        columnName: string,
179
        index: number,
180
    ): string {
UNCOV
181
        return columnName + "_" + index
×
182
    }
183

184
    joinTableColumnName(
185
        tableName: string,
186
        propertyName: string,
187
        columnName?: string,
188
    ): string {
189
        return camelCase(
1,388✔
190
            tableName + "_" + (columnName ? columnName : propertyName),
1,388!
191
        )
192
    }
193

194
    joinTableInverseColumnName(
195
        tableName: string,
196
        propertyName: string,
197
        columnName?: string,
198
    ): string {
199
        return this.joinTableColumnName(tableName, propertyName, columnName)
685✔
200
    }
201

202
    /**
203
     * Adds globally set prefix to the table name.
204
     * This method is executed no matter if prefix was set or not.
205
     * Table name is either user's given table name, either name generated from entity target.
206
     * Note that table name comes here already normalized by #tableName method.
207
     */
208
    prefixTableName(prefix: string, tableName: string): string {
209
        return prefix + tableName
×
210
    }
211

212
    nestedSetColumnNames = { left: "nsleft", right: "nsright" }
2,996✔
213
    materializedPathColumnName = "mpath"
2,996✔
214
}
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