• 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

89.74
/lib/features/user/featureColumn.ts
1
import { UserColumn } from '../../user/userColumn';
1✔
2
import { GeoPackageDataType } from '../../db/geoPackageDataType';
1✔
3
import { DBValue } from '../../db/dbValue';
4
import { GeometryType } from '@ngageoint/simple-features-js';
1✔
5
import { TableColumn } from '../../db/table/tableColumn';
6
import { UserTableDefaults } from '../../user/userTableDefaults';
1✔
7
import { GeoPackageException } from '../../geoPackageException';
1✔
8

9
/**
10
 * Represents a user feature column
11
 */
12
export class FeatureColumn extends UserColumn {
1✔
13
  geometryType: GeometryType;
14

15
  constructor(
16
    index: number = UserColumn.NO_INDEX,
2,448!
17
    name: string,
18
    dataType: GeoPackageDataType,
19
    max?: number,
20
    notNull?: boolean,
21
    defaultValue?: any,
22
    primaryKey?: boolean,
23
    geometryType?: GeometryType,
24
    autoincrement?: boolean,
25
  ) {
26
    super(index, name, dataType, max, notNull, defaultValue, primaryKey, autoincrement);
2,448✔
27
    this.geometryType = geometryType;
2,448✔
28
    this.setType(this.getTypeName(name, dataType, geometryType));
2,448✔
29
  }
30

31
  /**
32
   * Create a new column
33
   *
34
   * @param tableColumn table column
35
   * @return feature column
36
   */
37
  public static createColumnWithTableColumn(tableColumn: TableColumn): FeatureColumn {
1✔
38
    return new FeatureColumn(
1,825✔
39
      tableColumn.getIndex(),
40
      tableColumn.getName(),
41
      tableColumn.getDataType(),
42
      tableColumn.getMax(),
43
      tableColumn.isNotNull(),
44
      tableColumn.getDefaultValue(),
45
      tableColumn.isPrimaryKey(),
46
      FeatureColumn.getGeometryTypeFromTableColumn(tableColumn),
47
      tableColumn.isAutoIncrement(),
48
    );
49
  }
50

51
  /**
52
   *  Create a new primary key column
53
   *  @param {string} name  column name
54
   *  @param {boolean} autoincrement  column name
55
   *
56
   *  @return feature column
57
   */
58
  static createPrimaryKeyColumn(
1✔
59
    name: string,
60
    autoincrement: boolean = UserTableDefaults.DEFAULT_AUTOINCREMENT,
111✔
61
  ): FeatureColumn {
62
    return FeatureColumn.createPrimaryKeyColumnWithIndex(FeatureColumn.NO_INDEX, name, autoincrement);
109✔
63
  }
64

65
  /**
66
   *  Create a new primary key column with a specified column index
67
   *  @param {Number} index column index
68
   *  @param {string} name  column name
69
   *  @param {boolean} autoincrement  column name
70
   *
71
   *  @return feature column
72
   */
73
  static createPrimaryKeyColumnWithIndex(
1✔
74
    index: number = FeatureColumn.NO_INDEX,
109!
75
    name: string,
76
    autoincrement: boolean = UserTableDefaults.DEFAULT_AUTOINCREMENT,
109!
77
  ): FeatureColumn {
78
    return new FeatureColumn(
109✔
79
      index,
80
      name,
81
      GeoPackageDataType.INTEGER,
82
      undefined,
83
      true,
84
      undefined,
85
      true,
86
      undefined,
87
      autoincrement,
88
    );
89
  }
90

91
  /**
92
   *  Create a new geometry column
93
   *
94
   *  @param {Number} index        column index
95
   *  @param {string} name         column name
96
   *  @param {GeometryType} type
97
   *  @param {Boolean} notNull      not null
98
   *  @param {Object} defaultValue default value or nil
99
   *
100
   *  @return feature column
101
   */
102
  static createGeometryColumn(
1✔
103
    name: string,
104
    type: GeometryType,
105
    notNull?: boolean,
106
    defaultValue?: DBValue,
107
  ): FeatureColumn {
108
    return FeatureColumn.createGeometryColumnWithIndex(FeatureColumn.NO_INDEX, name, type, notNull, defaultValue);
109✔
109
  }
110
  /**
111
   *  Create a new geometry column with a specified column index
112
   *
113
   *  @param {Number} index        column index
114
   *  @param {string} name         column name
115
   *  @param {GeometryType} type
116
   *  @param {Boolean} notNull      not null
117
   *  @param {Object} defaultValue default value or nil
118
   *
119
   *  @return feature column
120
   */
121
  static createGeometryColumnWithIndex(
1✔
122
    index: number = FeatureColumn.NO_INDEX,
109!
123
    name: string,
124
    type: GeometryType,
125
    notNull?: boolean,
126
    defaultValue?: DBValue,
127
  ): FeatureColumn {
128
    if (type === null || type === undefined) {
109!
129
      throw new GeoPackageException('Geometry Type is required to create column: ' + name);
×
130
    }
131
    return new FeatureColumn(
109✔
132
      index,
133
      name,
134
      GeoPackageDataType.BLOB,
135
      undefined,
136
      notNull,
137
      defaultValue,
138
      false,
139
      type,
140
      false,
141
    );
142
  }
143

144
  /**
145
   * Create a new column
146
   * @param name
147
   * @param type
148
   * @param notNull
149
   * @param defaultValue
150
   * @param max
151
   * @param autoincrement
152
   */
153
  static createColumn(
1✔
154
    name: string,
155
    type: GeoPackageDataType,
156
    notNull = false,
271✔
157
    defaultValue?: DBValue,
158
    max?: number,
159
    autoincrement?: boolean,
160
  ): FeatureColumn {
161
    return FeatureColumn.createColumnWithIndex(
269✔
162
      FeatureColumn.NO_INDEX,
163
      name,
164
      type,
165
      notNull,
166
      defaultValue,
167
      max,
168
      autoincrement,
169
    );
170
  }
171

172
  /**
173
   * Create a new column with a specified column index
174
   * @param index
175
   * @param name
176
   * @param type
177
   * @param notNull
178
   * @param defaultValue
179
   * @param max
180
   * @param autoincrement
181
   */
182
  static createColumnWithIndex(
1✔
183
    index: number = FeatureColumn.NO_INDEX,
404!
184
    name: string,
185
    type: GeoPackageDataType,
186
    notNull = false,
404!
187
    defaultValue?: DBValue,
188
    max?: number,
189
    autoincrement?: boolean,
190
  ): FeatureColumn {
191
    return new FeatureColumn(index, name, type, max, notNull, defaultValue, false, undefined, autoincrement);
404✔
192
  }
193

194
  /**
195
   * Get the type name from the data and geometry type
196
   * @param name column name
197
   * @param dataType data type
198
   * @param geometryType  geometry type
199
   * @return type name
200
   */
201
  getTypeName(name: string, dataType: GeoPackageDataType, geometryType?: GeometryType): string {
1✔
202
    let type;
203
    if (geometryType !== null && geometryType !== undefined) {
2,448✔
204
      type = GeometryType.nameFromType(geometryType);
386✔
205
    } else {
206
      type = UserColumn.getTypeName(name, dataType);
2,062✔
207
    }
208
    return type;
2,448✔
209
  }
210

211
  /**
212
   * Attempt to get the geometry type of the table column
213
   * @param tableColumn table column
214
   * @return geometry type
215
   */
216
  static getGeometryTypeFromTableColumn(tableColumn: TableColumn): GeometryType {
1✔
217
    let geometryType = null;
1,825✔
218
    if (tableColumn.isDataType(GeoPackageDataType.BLOB)) {
1,825✔
219
      geometryType = GeometryType.fromName(tableColumn.type);
461✔
220
    }
221
    return geometryType;
1,825✔
222
  }
223

224
  /**
225
   * Copy the column
226
   * @return copied column
227
   */
228
  copy(): FeatureColumn {
1✔
229
    return new FeatureColumn(
1✔
230
      this.getIndex(),
231
      this.getName(),
232
      this.getDataType(),
233
      this.getMax(),
234
      this.isNotNull(),
235
      this.getDefaultValue(),
236
      this.isPrimaryKey(),
237
      this.getGeometryType(),
238
      this.isAutoincrement(),
239
    );
240
  }
241

242
  /**
243
   * Determine if this column is a geometry
244
   *
245
   * @return true if a geometry column
246
   */
247
  isGeometry(): boolean {
1✔
248
    return this.geometryType != null;
25,636✔
249
  }
250

251
  /**
252
   * When a geometry column, gets the geometry type
253
   * @return geometry type
254
   */
255
  getGeometryType(): GeometryType {
1✔
256
    return this.geometryType;
1✔
257
  }
258
}
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