MCPcopy
hub / github.com/eveningkid/denodb / createTable

Method createTable

lib/model.ts:154–175  ·  view source on GitHub ↗

Create a model in the database. Should not be called from a child model.

()

Source from the content-addressed store, hash-verified

152
153 /** Create a model in the database. Should not be called from a child model. */
154 static async createTable() {
155 if (this._isCreatedInDatabase) {
156 throw new Error("This model has already been initialized.");
157 }
158
159 const createQuery = this._options.queryBuilder
160 .queryForSchema(this)
161 .table(this.table)
162 .createTable(
163 this.formatFieldToDatabase(this.fields) as ModelFields,
164 this.formatFieldToDatabase(this.defaults) as ModelDefaults,
165 {
166 withTimestamps: this.timestamps,
167 ifNotExists: true,
168 },
169 )
170 .toDescription();
171
172 await this._options.database.query(createQuery);
173
174 this._isCreatedInDatabase = true;
175 }
176
177 /** Manually find the primary field by going through the schema fields. */
178 private static _findPrimaryField(): FieldOptions {

Callers 1

syncMethod · 0.45

Calls 5

formatFieldToDatabaseMethod · 0.95
toDescriptionMethod · 0.80
tableMethod · 0.80
queryForSchemaMethod · 0.80
queryMethod · 0.65

Tested by

no test coverage detected