• 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

1.67
/src/schema-builder/table/TableColumn.ts
1
import { TableColumnOptions } from "../options/TableColumnOptions"
2

3
/**
4
 * Table's columns in the database represented in this class.
5
 */
6
export class TableColumn {
1✔
UNCOV
7
    readonly "@instanceof" = Symbol.for("TableColumn")
×
8

9
    // -------------------------------------------------------------------------
10
    // Public Properties
11
    // -------------------------------------------------------------------------
12

13
    /**
14
     * Column name.
15
     */
16
    name: string
17

18
    /**
19
     * Column type.
20
     */
21
    type: string
22

23
    /**
24
     * Column's default value.
25
     */
26
    default?: any
27

28
    /**
29
     * ON UPDATE trigger. Works only for MySQL.
30
     */
31
    onUpdate?: string
32

33
    /**
34
     * Indicates if column is NULL, or is NOT NULL in the database.
35
     */
UNCOV
36
    isNullable: boolean = false
×
37

38
    /**
39
     * Indicates if column is auto-generated sequence.
40
     */
UNCOV
41
    isGenerated: boolean = false
×
42

43
    /**
44
     * Specifies generation strategy if this column will use auto increment.
45
     * `rowid` option supported only in CockroachDB.
46
     */
47
    generationStrategy?: "uuid" | "increment" | "rowid" | "identity"
48

49
    /**
50
     * Indicates if column is a primary key.
51
     */
UNCOV
52
    isPrimary: boolean = false
×
53

54
    /**
55
     * Indicates if column has unique value.
56
     */
UNCOV
57
    isUnique: boolean = false
×
58

59
    /**
60
     * Indicates if column stores array.
61
     */
UNCOV
62
    isArray: boolean = false
×
63

64
    /**
65
     * Column's comment.
66
     */
67
    comment?: string
68

69
    /**
70
     * Column type's length. Used only on some column types.
71
     * For example type = "string" and length = "100" means that ORM will create a column with type varchar(100).
72
     */
UNCOV
73
    length: string = ""
×
74

75
    /**
76
     * Column type's display width. Used only on some column types in MySQL.
77
     * For example, INT(4) specifies an INT with a display width of four digits.
78
     */
79
    width?: number
80

81
    /**
82
     * Defines column character set.
83
     */
84
    charset?: string
85

86
    /**
87
     * Defines column collation.
88
     */
89
    collation?: string
90

91
    /**
92
     * The precision for a decimal (exact numeric) column (applies only for decimal column), which is the maximum
93
     * number of digits that are stored for the values.
94
     */
95
    precision?: number | null
96

97
    /**
98
     * The scale for a decimal (exact numeric) column (applies only for decimal column), which represents the number
99
     * of digits to the right of the decimal point and must not be greater than precision.
100
     */
101
    scale?: number
102

103
    /**
104
     * Puts ZEROFILL attribute on to numeric column. Works only for MySQL.
105
     * If you specify ZEROFILL for a numeric column, MySQL automatically adds the UNSIGNED attribute to the column
106
     */
UNCOV
107
    zerofill: boolean = false
×
108

109
    /**
110
     * Puts UNSIGNED attribute on to numeric column. Works only for MySQL.
111
     */
UNCOV
112
    unsigned: boolean = false
×
113

114
    /**
115
     * Array of possible enumerated values.
116
     */
117
    enum?: string[]
118

119
    /**
120
     * Exact name of enum
121
     */
122
    enumName?: string
123

124
    /**
125
     * Name of the primary key constraint for primary column.
126
     */
127
    primaryKeyConstraintName?: string
128

129
    /**
130
     * Generated column expression.
131
     */
132
    asExpression?: string
133

134
    /**
135
     * Generated column type.
136
     */
137
    generatedType?: "VIRTUAL" | "STORED"
138

139
    /**
140
     * Identity column type. Supports only in Postgres 10+.
141
     */
142
    generatedIdentity?: "ALWAYS" | "BY DEFAULT"
143

144
    /**
145
     * Spatial Feature Type (Geometry, Point, Polygon, etc.)
146
     */
147
    spatialFeatureType?: string
148

149
    /**
150
     * SRID (Spatial Reference ID (EPSG code))
151
     */
152
    srid?: number
153

154
    // -------------------------------------------------------------------------
155
    // Constructor
156
    // -------------------------------------------------------------------------
157

158
    constructor(options?: TableColumnOptions) {
UNCOV
159
        if (options) {
×
UNCOV
160
            this.name = options.name
×
UNCOV
161
            this.type = options.type || ""
×
UNCOV
162
            this.length = options.length || ""
×
UNCOV
163
            this.width = options.width
×
UNCOV
164
            this.charset = options.charset
×
UNCOV
165
            this.collation = options.collation
×
UNCOV
166
            this.precision = options.precision
×
UNCOV
167
            this.scale = options.scale
×
UNCOV
168
            this.zerofill = options.zerofill || false
×
UNCOV
169
            this.unsigned = this.zerofill ? true : options.unsigned || false
×
UNCOV
170
            this.default = options.default
×
UNCOV
171
            this.onUpdate = options.onUpdate
×
UNCOV
172
            this.isNullable = options.isNullable || false
×
UNCOV
173
            this.isGenerated = options.isGenerated || false
×
UNCOV
174
            this.generationStrategy = options.generationStrategy
×
UNCOV
175
            this.generatedIdentity = options.generatedIdentity
×
UNCOV
176
            this.isPrimary = options.isPrimary || false
×
UNCOV
177
            this.isUnique = options.isUnique || false
×
UNCOV
178
            this.isArray = options.isArray || false
×
UNCOV
179
            this.comment = options.comment
×
UNCOV
180
            this.enum = options.enum
×
UNCOV
181
            this.enumName = options.enumName
×
UNCOV
182
            this.primaryKeyConstraintName = options.primaryKeyConstraintName
×
UNCOV
183
            this.asExpression = options.asExpression
×
UNCOV
184
            this.generatedType = options.generatedType
×
UNCOV
185
            this.spatialFeatureType = options.spatialFeatureType
×
UNCOV
186
            this.srid = options.srid
×
187
        }
188
    }
189

190
    // -------------------------------------------------------------------------
191
    // Public Methods
192
    // -------------------------------------------------------------------------
193

194
    /**
195
     * Clones this column to a new column with exact same properties as this column has.
196
     */
197
    clone(): TableColumn {
UNCOV
198
        return new TableColumn(<TableColumnOptions>{
×
199
            name: this.name,
200
            type: this.type,
201
            length: this.length,
202
            width: this.width,
203
            charset: this.charset,
204
            collation: this.collation,
205
            precision: this.precision,
206
            scale: this.scale,
207
            zerofill: this.zerofill,
208
            unsigned: this.unsigned,
209
            enum: this.enum,
210
            enumName: this.enumName,
211
            primaryKeyConstraintName: this.primaryKeyConstraintName,
212
            asExpression: this.asExpression,
213
            generatedType: this.generatedType,
214
            default: this.default,
215
            onUpdate: this.onUpdate,
216
            isNullable: this.isNullable,
217
            isGenerated: this.isGenerated,
218
            generationStrategy: this.generationStrategy,
219
            generatedIdentity: this.generatedIdentity,
220
            isPrimary: this.isPrimary,
221
            isUnique: this.isUnique,
222
            isArray: this.isArray,
223
            comment: this.comment,
224
            spatialFeatureType: this.spatialFeatureType,
225
            srid: this.srid,
226
        })
227
    }
228
}
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