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

ngageoint / geopackage-js / 4078143969

pending completion
4078143969

push

github

Christopher Caldwell
bump version

3593 of 8015 branches covered (44.83%)

Branch coverage included in aggregate %.

15102 of 20471 relevant lines covered (73.77%)

1564.55 hits per line

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

63.97
/lib/user/userColumn.ts
1
import { GeoPackageDataType } from '../db/geoPackageDataType';
1✔
2
import { Constraint } from '../db/table/constraint';
3
import { RawConstraint } from '../db/table/rawConstraint';
1✔
4
import { ColumnConstraints } from '../db/table/columnConstraints';
5
import { ConstraintType } from '../db/table/constraintType';
1✔
6
import { Constraints } from '../db/table/constraints';
1✔
7
import { TableColumn } from '../db/table/tableColumn';
1✔
8
import { UserTable } from './userTable';
1✔
9
import { GeoPackageException } from '../geoPackageException';
1✔
10
import { Comparable } from '@ngageoint/simple-features-js';
11
import { ConstraintParser } from '../db/table/constraintParser';
1✔
12

13
/**
14
 * A `UserColumn` is meta-data about a single column from a {@link UserTable}.
15
 * @class
16
 */
17
export abstract class UserColumn implements Comparable<UserColumn> {
1✔
18
  /**
19
   * User Column index value
20
   */
21
  static readonly NO_INDEX = -1;
1✔
22
  /**
23
   * Not Null Constraint Order
24
   */
25
  static readonly NOT_NULL_CONSTRAINT_ORDER = 1;
1✔
26

27
  /**
28
   * Default Value Constraint Order
29
   */
30
  static readonly DEFAULT_VALUE_CONSTRAINT_ORDER = 2;
1✔
31

32
  /**
33
   * Primary Key Constraint Order
34
   */
35
  static readonly PRIMARY_KEY_CONSTRAINT_ORDER = 3;
1✔
36

37
  /**
38
   * Autoincrement Constraint Order
39
   */
40
  static readonly AUTOINCREMENT_CONSTRAINT_ORDER = 4;
1✔
41

42
  /**
43
   * Unique Constraint Order
44
   */
45
  static readonly UNIQUE_CONSTRAINT_ORDER = 5;
1✔
46

47
  /**
48
   * Column index
49
   */
50
  private index: number;
51

52
  /**
53
   * Column name
54
   */
55
  private name: string;
56

57
  /**
58
   * Max size
59
   */
60
  private max: number;
61

62
  /**
63
   * True if a not null column
64
   */
65
  private notNull: boolean;
66

67
  /**
68
   * Default column value
69
   */
70
  private defaultValue: any;
71

72
  /**
73
   * True if a primary key column
74
   */
75
  private primaryKey: boolean;
76

77
  /**
78
   * True if primary key is autoincrement
79
   */
80
  private autoincrement: boolean;
81

82
  /**
83
   * True if unique column
84
   */
85
  private unique: boolean;
86

87
  /**
88
   * Type
89
   */
90
  private type: string;
91

92
  /**
93
   * Data type
94
   */
95
  private dataType: GeoPackageDataType;
96

97
  /**
98
   * List of column constraints
99
   */
100
  private readonly constraints: Constraints;
101

102
  /**
103
   * Constructor
104
   * @param index column index
105
   * @param name column name
106
   * @param dataType data type
107
   * @param max  max value
108
   * @param notNull not null flag
109
   * @param defaultValue default value
110
   * @param primaryKey primary key flag
111
   * @param autoincrement autoincrement flag
112
   */
113
  protected constructor(
114
    index: number,
115
    name: string,
116
    dataType: GeoPackageDataType,
117
    max: number,
118
    notNull: boolean,
119
    defaultValue: any,
120
    primaryKey: boolean,
121
    autoincrement: boolean,
122
  );
123

124
  /**
125
   * Constructor
126
   * @param index column index
127
   * @param name column name
128
   * @param type string type
129
   * @param dataType data type
130
   * @param max max value
131
   * @param notNull not null flag
132
   * @param defaultValue default value
133
   * @param primaryKey primary key flag
134
   * @param autoincrement autoincrement flag
135
   */
136
  protected constructor(
137
    index: number,
138
    name: string,
139
    type: string,
140
    dataType: GeoPackageDataType,
141
    max: number,
142
    notNull: boolean,
143
    defaultValue: any,
144
    primaryKey: boolean,
145
    autoincrement: boolean,
146
  );
147

148
  /**
149
   * Constructor
150
   *
151
   * @param tableColumn
152
   *            table column
153
   */
154
  protected constructor(tableColumn: TableColumn);
155
  protected constructor(userColumn: UserColumn);
156

157
  /**
158
   * Constructor
159
   * @param args
160
   */
161
  protected constructor(...args) {
137,464✔
162
    if (args.length === 1) {
25,897✔
163
      if (args[0] instanceof TableColumn) {
17,358!
164
        const tableColumn = args[0];
17,358✔
165
        this.index = tableColumn.index != null ? tableColumn.index : UserColumn.NO_INDEX;
17,358!
166
        this.name = tableColumn.name;
17,358✔
167
        this.max = tableColumn.max;
17,358✔
168
        this.notNull = tableColumn.isNotNull() || tableColumn.isPrimaryKey();
17,358✔
169
        this.defaultValue = tableColumn.defaultValue;
17,358✔
170
        this.primaryKey = tableColumn.primaryKey;
17,358✔
171
        this.autoincrement = tableColumn.isPrimaryKey() && UserTable.DEFAULT_AUTOINCREMENT;
17,358✔
172
        this.type = tableColumn.type;
17,358✔
173
        this.dataType = tableColumn.dataType;
17,358✔
174
        this.constraints = new Constraints();
17,358✔
175
        UserColumn.validateDataType(this.name, this.dataType);
17,358✔
176
        this.validateMax();
17,358✔
177
        this.addDefaultConstraints();
17,358✔
178
      } else if (args[0] instanceof UserColumn) {
×
179
        const userColumn = args[0];
×
180
        this.index = userColumn.index != null ? userColumn.index : UserColumn.NO_INDEX;
×
181
        this.name = userColumn.name;
×
182
        this.max = userColumn.max;
×
183
        this.notNull = userColumn.notNull;
×
184
        this.defaultValue = userColumn.defaultValue;
×
185
        this.primaryKey = userColumn.primaryKey;
×
186
        this.autoincrement = userColumn.autoincrement;
×
187
        this.type = userColumn.type;
×
188
        this.dataType = userColumn.dataType;
×
189
        this.constraints = userColumn.constraints.copy();
×
190
      }
191
    } else if (args.length === 8) {
8,539!
192
      this.index = args[0] != null ? args[0] : UserColumn.NO_INDEX;
8,539!
193
      this.name = args[1];
8,539✔
194
      this.type = UserColumn.getTypeName(args[1], args[2]);
8,539✔
195
      this.dataType = args[2];
8,539✔
196
      this.max = args[3];
8,539✔
197
      this.notNull = args[4];
8,539✔
198
      this.defaultValue = args[5];
8,539✔
199
      this.primaryKey = args[6];
8,539✔
200
      this.autoincrement = args[7];
8,539✔
201
      this.constraints = new Constraints();
8,539✔
202
      UserColumn.validateDataType(this.name, this.dataType);
8,539✔
203
      this.validateMax();
8,539✔
204
      this.addDefaultConstraints();
8,539✔
205
    } else if (args.length === 9) {
×
206
      this.index = args[0] != null ? args[0] : UserColumn.NO_INDEX;
×
207
      this.name = args[1];
×
208
      this.type = args[2];
×
209
      this.dataType = args[3];
×
210
      this.max = args[4];
×
211
      this.notNull = args[5];
×
212
      this.defaultValue = args[6];
×
213
      this.primaryKey = args[7];
×
214
      this.autoincrement = args[8];
×
215
      this.constraints = new Constraints();
×
216
      UserColumn.validateDataType(this.name, this.dataType);
×
217
      this.validateMax();
×
218
      this.addDefaultConstraints();
×
219
    }
220
  }
221

222
  /**
223
   * Get the type name from the data type
224
   *
225
   * @param name
226
   *            column name
227
   * @param dataType
228
   *            data type
229
   * @return type name
230

231
   */
232
  protected static getTypeName(name: string, dataType: GeoPackageDataType): string {
1✔
233
    UserColumn.validateDataType(name, dataType);
10,601✔
234
    return GeoPackageDataType.nameFromType(dataType);
10,601✔
235
  }
236

237
  /**
238
   * Validate the data type
239
   *
240
   * @param name
241
   *            column name
242
   *
243
   * @param dataType
244
   *            data type
245
   */
246
  protected static validateDataType(name: string, dataType: GeoPackageDataType): void {
1✔
247
    if (dataType == null) {
36,498!
248
      console.error('Column is missing a data type: ' + name);
×
249
    }
250
  }
251

252
  /**
253
   * Copy the column
254
   *
255
   * @return copied column
256
   */
257
  public abstract copy(): UserColumn;
258

259
  /**
260
   * Check if the column has a valid index
261
   *
262
   * @return true if has a valid index
263
   */
264
  public hasIndex(): boolean {
1✔
265
    return this.index > UserColumn.NO_INDEX;
33,704✔
266
  }
267

268
  /**
269
   * Set the column index. Only allowed when {@link #hasIndex()} is false (
270
   * {@link #getIndex()} is {@link #NO_INDEX}). Setting a valid index to an
271
   * existing valid index does nothing.
272
   *
273
   * @param index
274
   *            column index
275
   */
276
  public setIndex(index: number): void {
1✔
277
    if (this.hasIndex()) {
3,877✔
278
      if (index != this.index) {
2!
279
        throw new GeoPackageException(
×
280
          'User Column with a valid index may not be changed. Column Name: ' +
281
            this.name +
282
            ', Index: ' +
283
            this.index +
284
            ', Attempted Index: ' +
285
            index,
286
        );
287
      }
288
    } else {
289
      this.index = index;
3,875✔
290
    }
291
  }
292

293
  /**
294
   * Reset the column index
295
   */
296
  public resetIndex(): void {
1✔
297
    this.index = UserColumn.NO_INDEX;
42✔
298
  }
299

300
  /**
301
   * Get the index
302
   *
303
   * @return index
304
   */
305
  public getIndex(): number {
1✔
306
    return this.index;
123,906✔
307
  }
308

309
  /**
310
   * Set the name
311
   *
312
   * @param name
313
   *            column name
314
   */
315
  public setName(name: string): void {
1✔
316
    this.name = name;
4✔
317
  }
318

319
  /**
320
   * Get the name
321
   *
322
   * @return name
323
   */
324
  public getName(): string {
1✔
325
    return this.name;
122,793✔
326
  }
327

328
  /**
329
   * Determine if this column is named the provided name
330
   *
331
   * @param name
332
   *            column name
333
   * @return true if named the provided name
334
   */
335
  public isNamed(name: string): boolean {
1✔
336
    return this.name === name;
2✔
337
  }
338

339
  /**
340
   * Determine if the column has a max value
341
   *
342
   * @return true if has max value
343
   */
344
  public hasMax(): boolean {
1✔
345
    return this.max != null;
1,772✔
346
  }
347

348
  /**
349
   * Set the max
350
   *
351
   * @param max
352
   *            max
353

354
   */
355
  public setMax(max: number): void {
1✔
356
    this.max = max;
×
357
  }
358

359
  /**
360
   * Get the max
361
   *
362
   * @return max
363
   */
364
  public getMax(): number {
1✔
365
    return this.max;
2,774✔
366
  }
367

368
  /**
369
   * Set the not null flag
370
   *
371
   * @param notNull
372
   *            not null flag
373

374
   */
375
  public setNotNull(notNull: boolean): void {
1✔
376
    if (this.notNull != notNull) {
×
377
      if (notNull) {
×
378
        this.addNotNullConstraint();
×
379
      } else {
380
        this.removeNotNullConstraint();
×
381
      }
382
    }
383
    this.notNull = notNull;
×
384
  }
385

386
  /**
387
   * Get the is not null flag
388
   *
389
   * @return not null flag
390
   */
391
  public isNotNull(): boolean {
1✔
392
    return this.notNull;
27,408✔
393
  }
394

395
  /**
396
   * Determine if the column has a default value
397
   *
398
   * @return true if has default value
399
   */
400
  public hasDefaultValue(): boolean {
1✔
401
    return this.defaultValue != null;
25,897✔
402
  }
403

404
  /**
405
   * Set the default value
406
   *
407
   * @param defaultValue
408
   *            default value
409
   */
410
  public setDefaultValue(defaultValue: any): void {
1✔
411
    this.removeDefaultValueConstraint();
2✔
412
    if (defaultValue != null) {
2!
413
      this.addDefaultValueConstraint(defaultValue);
2✔
414
    }
415
    this.defaultValue = defaultValue;
2✔
416
  }
417

418
  /**
419
   * Get the default value
420
   *
421
   * @return default value
422
   */
423
  public getDefaultValue(): any {
1✔
424
    return this.defaultValue;
7,471✔
425
  }
426

427
  /**
428
   * Set the primary key flag
429
   *
430
   * @param primaryKey
431
   *            primary key flag
432
   */
433
  public setPrimaryKey(primaryKey: boolean): void {
1✔
434
    if (this.primaryKey != primaryKey) {
×
435
      if (primaryKey) {
×
436
        this.addPrimaryKeyConstraint();
×
437
      } else {
438
        this.removeAutoincrementConstraint();
×
439
        this.removePrimaryKeyConstraint();
×
440
      }
441
    }
442
    this.primaryKey = primaryKey;
×
443
  }
444

445
  /**
446
   * Get the primary key flag
447
   *
448
   * @return primary key flag
449
   */
450
  public isPrimaryKey(): boolean {
1✔
451
    return this.primaryKey;
74,944✔
452
  }
453

454
  /**
455
   * Set the autoincrement flag
456
   *
457
   * @param autoincrement
458
   *            autoincrement flag
459
   */
460
  public setAutoincrement(autoincrement: boolean): void {
1✔
461
    if (this.autoincrement != autoincrement) {
×
462
      if (autoincrement) {
×
463
        this.addAutoincrementConstraint();
×
464
      } else {
465
        this.removeAutoincrementConstraint();
×
466
      }
467
    }
468
    this.autoincrement = autoincrement;
×
469
  }
470

471
  /**
472
   * Get the autoincrement flag
473
   *
474
   * @return autoincrement flag
475
   */
476
  public isAutoincrement(): boolean {
1✔
477
    return this.autoincrement;
25,899✔
478
  }
479

480
  /**
481
   * Set the unique flag
482
   *
483
   * @param unique
484
   *            unique flag
485
   */
486
  public setUnique(unique: boolean): void {
1✔
487
    if (this.unique != unique) {
×
488
      if (unique) {
×
489
        this.addUniqueConstraint();
×
490
      } else {
491
        this.removeUniqueConstraint();
×
492
      }
493
    }
494
    this.unique = unique;
×
495
  }
496

497
  /**
498
   * Get the unique flag
499
   *
500
   * @return unique flag
501
   */
502
  public isUnique(): boolean {
1✔
503
    return this.unique;
×
504
  }
505

506
  /**
507
   * Set the data type
508
   *
509
   * @param dataType
510
   *            data type
511
   */
512
  public setDataType(dataType: GeoPackageDataType): void {
1✔
513
    this.dataType = dataType;
×
514
  }
515

516
  /**
517
   * Get the data type
518
   *
519
   * @return data type
520
   */
521
  public getDataType(): GeoPackageDataType {
1✔
522
    return this.dataType;
65,065✔
523
  }
524

525
  /**
526
   * Set the database type
527
   *
528
   * @param type
529
   *            database type
530
   */
531
  public setType(type: string): void {
1✔
532
    this.type = type;
2,448✔
533
  }
534

535
  /**
536
   * Get the database type
537
   *
538
   * @return type
539
   */
540
  public getType(): string {
1✔
541
    return this.type;
1,814✔
542
  }
543

544
  /**
545
   * Check if has constraints
546
   *
547
   * @return true if has constraints
548
   */
549
  public hasConstraints(): boolean {
1✔
550
    return this.constraints.has();
3✔
551
  }
552

553
  /**
554
   * Check if has constraints of the provided type
555
   *
556
   * @param type
557
   *            constraint type
558
   * @return true if has constraints
559
   */
560
  public hasConstraintsForType(type: ConstraintType): boolean {
1✔
561
    return this.constraints.hasType(type);
×
562
  }
563

564
  /**
565
   * Get the constraints
566
   *
567
   * @return constraints
568
   */
569
  public getConstraints(): Constraints {
1✔
570
    return this.constraints;
1,772✔
571
  }
572

573
  /**
574
   * Get the constraints of the provided type
575
   *
576
   * @param type
577
   *            constraint type
578
   * @return constraints
579

580
   */
581
  public getConstraintsForType(type: ConstraintType): Constraint[] {
1✔
582
    return this.constraints.getConstraintsByType(type);
×
583
  }
584

585
  /**
586
   * Clear the constraints
587
   *
588
   * @param reset true to reset constraint settings
589
   * @return cleared constraints
590
   */
591
  public clearConstraints(reset = true): Constraint[] {
208!
592
    if (reset) {
104!
593
      this.primaryKey = false;
104✔
594
      this.unique = false;
104✔
595
      this.notNull = false;
104✔
596
      this.defaultValue = null;
104✔
597
      this.autoincrement = false;
104✔
598
    }
599

600
    return this.constraints.clear();
104✔
601
  }
602

603
  /**
604
   * Clear the constraints of the provided type
605
   *
606
   * @param type
607
   *            constraint type
608
   * @return cleared constraints
609
   */
610
  public clearConstraintsForType(type: ConstraintType): Constraint[] {
1✔
611
    switch (type) {
2✔
612
      case ConstraintType.PRIMARY_KEY:
2!
613
        this.primaryKey = false;
×
614
        break;
×
615
      case ConstraintType.UNIQUE:
616
        this.unique = false;
×
617
        break;
×
618
      case ConstraintType.NOT_NULL:
619
        this.notNull = false;
×
620
        break;
×
621
      case ConstraintType.DEFAULT:
622
        this.defaultValue = null;
2✔
623
        break;
2✔
624
      case ConstraintType.AUTOINCREMENT:
625
        this.autoincrement = false;
×
626
        break;
×
627
      default:
628
    }
629

630
    return this.constraints.clearConstraintsByType(type);
2✔
631
  }
632

633
  /**
634
   * Add the default constraints that are enabled (not null, default value,
635
   * primary key) from the column properties
636
   */
637
  public addDefaultConstraints(): void {
1✔
638
    if (this.isNotNull()) {
25,897✔
639
      this.addNotNullConstraint();
13,525✔
640
    }
641
    if (this.hasDefaultValue()) {
25,897✔
642
      this.addDefaultValueConstraint(this.getDefaultValue());
1,113✔
643
    }
644
    if (this.isPrimaryKey()) {
25,897✔
645
      this.addPrimaryKeyConstraint();
5,008✔
646
    }
647
    if (this.isAutoincrement()) {
25,897✔
648
      this.addAutoincrementConstraint();
4,392✔
649
    }
650
  }
651

652
  /**
653
   * Add a constraint
654
   *
655
   * @param constraint
656
   *            constraint
657
   */
658
  public addConstraint(constraint: Constraint): void {
1✔
659
    if (constraint.order == null) {
24,159✔
660
      this.setConstraintOrder(constraint);
119✔
661
    }
662

663
    this.constraints.add(constraint);
24,159✔
664

665
    switch (constraint.getType()) {
24,159✔
666
      case ConstraintType.PRIMARY_KEY:
24,159!
667
        this.primaryKey = true;
5,020✔
668
        break;
5,020✔
669
      case ConstraintType.UNIQUE:
670
        this.unique = true;
×
671
        break;
×
672
      case ConstraintType.NOT_NULL:
673
        this.notNull = true;
13,578✔
674
        break;
13,578✔
675
      case ConstraintType.DEFAULT:
676
        break;
1,157✔
677
      case ConstraintType.AUTOINCREMENT:
678
        this.autoincrement = true;
4,404✔
679
        break;
4,404✔
680
      default:
681
    }
682
  }
683

684
  /**
685
   * Set the constraint order by constraint type
686
   *
687
   * @param constraint
688
   *            constraint
689
   */
690
  public setConstraintOrder(constraint: Constraint): void {
1✔
691
    let order = null;
119✔
692
    switch (constraint.getType()) {
119✔
693
      case ConstraintType.PRIMARY_KEY:
119!
694
        order = UserColumn.PRIMARY_KEY_CONSTRAINT_ORDER;
12✔
695
        break;
12✔
696
      case ConstraintType.UNIQUE:
697
        order = UserColumn.UNIQUE_CONSTRAINT_ORDER;
×
698
        break;
×
699
      case ConstraintType.NOT_NULL:
700
        order = UserColumn.NOT_NULL_CONSTRAINT_ORDER;
53✔
701
        break;
53✔
702
      case ConstraintType.DEFAULT:
703
        order = UserColumn.DEFAULT_VALUE_CONSTRAINT_ORDER;
42✔
704
        break;
42✔
705
      case ConstraintType.AUTOINCREMENT:
706
        order = UserColumn.AUTOINCREMENT_CONSTRAINT_ORDER;
12✔
707
        break;
12✔
708
      default:
709
    }
710

711
    constraint.setOrder(order);
119✔
712
  }
713

714
  /**
715
   * Add a constraint
716
   * @param constraint  constraint
717
   */
718
  public addConstraintSql(constraint: string): void {
1✔
719
    const type = ConstraintParser.getType(constraint);
×
720
    const name = ConstraintParser.getName(constraint);
×
721
    this.constraints.add(new RawConstraint(type, name, constraint));
×
722
  }
723

724
  /**
725
   * Add a constraint
726
   *
727
   * @param type
728
   *            constraint type
729
   * @param constraint
730
   *            constraint
731
   * @param order
732
   *            constraint order
733
   */
734
  public addConstraintFrom(type: ConstraintType, constraint: string, order: number = null): void {
24,040!
735
    const name = ConstraintParser.getName(constraint);
24,040✔
736
    this.addConstraint(new RawConstraint(type, name, constraint, order));
24,040✔
737
  }
738

739
  /**
740
   * Add constraints
741
   *
742
   * @param constraints constraints
743
   */
744
  public addConstraintsArray(constraints: Constraint[]): void {
1✔
745
    for (const constraint of constraints) {
×
746
      this.addConstraint(constraint);
×
747
    }
748
  }
749

750
  /**
751
   * Add constraints
752
   *
753
   * @param constraints
754
   *            constraints
755
   */
756
  public addConstraintsFromColumnConstraints(constraints: ColumnConstraints): void {
1✔
757
    this.addConstraints(constraints.getConstraints());
×
758
  }
759

760
  /**
761
   * Add constraints
762
   *
763
   * @param constraints
764
   *            constraints
765

766
   */
767
  public addConstraints(constraints: Constraints): void {
1✔
768
    this.addConstraintsArray(constraints.all());
×
769
  }
770

771
  /**
772
   * Add a not null constraint
773
   */
774
  public addNotNullConstraint(): void {
1✔
775
    this.addConstraintFrom(ConstraintType.NOT_NULL, 'NOT NULL', UserColumn.NOT_NULL_CONSTRAINT_ORDER);
13,525✔
776
  }
777

778
  /**
779
   * Remove a not null constraint
780
   */
781
  public removeNotNullConstraint(): void {
1✔
782
    this.clearConstraintsForType(ConstraintType.NOT_NULL);
×
783
  }
784

785
  /**
786
   * Add a default value constraint
787
   *
788
   * @param defaultValue
789
   *            default value
790
   */
791
  public addDefaultValueConstraint(defaultValue: any): void {
1✔
792
    this.addConstraintFrom(
1,115✔
793
      ConstraintType.DEFAULT,
794
      'DEFAULT ' + GeoPackageDataType.columnDefaultValue(defaultValue, this.getDataType()),
795
      UserColumn.DEFAULT_VALUE_CONSTRAINT_ORDER,
796
    );
797
  }
798

799
  /**
800
   * Remove a default value constraint
801
   */
802
  public removeDefaultValueConstraint(): void {
1✔
803
    this.clearConstraintsForType(ConstraintType.DEFAULT);
2✔
804
  }
805

806
  /**
807
   * Add a primary key constraint
808
   */
809
  public addPrimaryKeyConstraint(): void {
1✔
810
    this.addConstraintFrom(ConstraintType.PRIMARY_KEY, 'PRIMARY KEY', UserColumn.PRIMARY_KEY_CONSTRAINT_ORDER);
5,008✔
811
  }
812

813
  /**
814
   * Remove a primary key constraint
815
   */
816
  public removePrimaryKeyConstraint(): void {
1✔
817
    this.clearConstraintsForType(ConstraintType.PRIMARY_KEY);
×
818
  }
819

820
  /**
821
   * Add an autoincrement constraint
822
   */
823
  public addAutoincrementConstraint(): void {
1✔
824
    this.addConstraintFrom(ConstraintType.AUTOINCREMENT, 'AUTOINCREMENT', UserColumn.AUTOINCREMENT_CONSTRAINT_ORDER);
4,392✔
825
  }
826

827
  /**
828
   * Remove an autoincrement constraint
829
   */
830
  public removeAutoincrementConstraint(): void {
1✔
831
    this.clearConstraintsForType(ConstraintType.AUTOINCREMENT);
×
832
  }
833

834
  /**
835
   * Add a unique constraint
836
   */
837
  public addUniqueConstraint(): void {
1✔
838
    this.addConstraintFrom(ConstraintType.UNIQUE, 'UNIQUE', UserColumn.UNIQUE_CONSTRAINT_ORDER);
×
839
  }
840

841
  /**
842
   * Remove a unique constraint
843
   */
844
  public removeUniqueConstraint(): void {
1✔
845
    this.clearConstraintsForType(ConstraintType.UNIQUE);
×
846
  }
847

848
  /**
849
   * Build the SQL for the constraint
850
   *
851
   * @param constraint
852
   *            constraint
853
   * @return SQL or null
854

855
   */
856
  public buildConstraintSql(constraint: Constraint): string {
1✔
857
    let sql = null;
1,362✔
858
    if (UserTable.DEFAULT_PK_NOT_NULL || !this.isPrimaryKey() || constraint.getType() != ConstraintType.NOT_NULL) {
1,362!
859
      sql = constraint.buildSql();
1,362✔
860
    }
861
    return sql;
1,362✔
862
  }
863

864
  /**
865
   * Comparison function that sorts user columns by index
866
   */
867
  public compareTo(another: UserColumn): number {
1✔
868
    return this.index - another.index;
×
869
  }
870

871
  /**
872
   * Validate that if max is set, the data type is text or blob
873
   */
874
  private validateMax(): void {
1✔
875
    if (this.max != null) {
25,897✔
876
      if (this.dataType == null) {
106!
877
        console.error('Column max set on a column without a data type. column: ' + name + ', max: ' + this.max);
×
878
      } else if (this.dataType !== GeoPackageDataType.TEXT && this.dataType !== GeoPackageDataType.BLOB) {
106!
879
        throw new GeoPackageException(
×
880
          'Column max is only supported for ' +
881
            GeoPackageDataType.nameFromType(GeoPackageDataType.TEXT) +
882
            ' and ' +
883
            GeoPackageDataType.nameFromType(GeoPackageDataType.BLOB) +
884
            ' columns. column: ' +
885
            this.name +
886
            ', max: ' +
887
            this.max +
888
            ', type: ' +
889
            GeoPackageDataType.nameFromType(this.dataType),
890
        );
891
      }
892
    }
893
  }
894
}
1✔
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

© 2026 Coveralls, Inc