(table: string)
| 162 | |
| 163 | // Create a string for the model of the table |
| 164 | private addTable(table: string) { |
| 165 | |
| 166 | const [schemaName, tableNameOrig] = qNameSplit(table); |
| 167 | const space = this.space; |
| 168 | let timestamps = (this.options.additional && this.options.additional.timestamps === true) || false; |
| 169 | let paranoid = (this.options.additional && this.options.additional.paranoid === true) || false; |
| 170 | |
| 171 | // add all the fields |
| 172 | let str = ''; |
| 173 | const fields = _.keys(this.tables[table]); |
| 174 | fields.forEach((field, index) => { |
| 175 | timestamps ||= this.isTimestampField(field); |
| 176 | paranoid ||= this.isParanoidField(field); |
| 177 | |
| 178 | str += this.addField(table, field); |
| 179 | }); |
| 180 | |
| 181 | // trim off last ",\n" |
| 182 | str = str.substring(0, str.length - 2) + "\n"; |
| 183 | |
| 184 | // add the table options |
| 185 | str += space[1] + "}, {\n"; |
| 186 | if (!this.options.useDefine) { |
| 187 | str += space[2] + "sequelize,\n"; |
| 188 | } |
| 189 | str += space[2] + "tableName: '" + tableNameOrig + "',\n"; |
| 190 | |
| 191 | if (schemaName && this.dialect.hasSchema) { |
| 192 | str += space[2] + "schema: '" + schemaName + "',\n"; |
| 193 | } |
| 194 | |
| 195 | if (this.hasTriggerTables[table]) { |
| 196 | str += space[2] + "hasTrigger: true,\n"; |
| 197 | } |
| 198 | |
| 199 | str += space[2] + "timestamps: " + timestamps + ",\n"; |
| 200 | if (paranoid) { |
| 201 | str += space[2] + "paranoid: true,\n"; |
| 202 | } |
| 203 | |
| 204 | // conditionally add additional options |
| 205 | const hasadditional = _.isObject(this.options.additional) && _.keys(this.options.additional).length > 0; |
| 206 | if (hasadditional) { |
| 207 | _.each(this.options.additional, (value, key) => { |
| 208 | if (key === 'name') { |
| 209 | // name: true - preserve table name always |
| 210 | str += space[2] + "name: {\n"; |
| 211 | str += space[3] + "singular: '" + table + "',\n"; |
| 212 | str += space[3] + "plural: '" + table + "'\n"; |
| 213 | str += space[2] + "},\n"; |
| 214 | } else if (key === "timestamps" || key === "paranoid") { |
| 215 | // handled above |
| 216 | } else { |
| 217 | value = _.isBoolean(value) ? value : ("'" + value + "'"); |
| 218 | str += space[2] + key + ": " + value + ",\n"; |
| 219 | } |
| 220 | }); |
| 221 | } |
no test coverage detected