MCPcopy
hub / github.com/sequelize/sequelize / createTable

Method createTable

lib/dialects/db2/query-interface.js:75–140  ·  lib/dialects/db2/query-interface.js::Db2QueryInterface.createTable
(tableName, attributes, options, model)

Source from the content-addressed store, hash-verified

73 }
74
75 async createTable(tableName, attributes, options, model) {
76 let sql = class="st">'';
77
78 options = { ...options };
79
80 if (options && options.uniqueKeys) {
81 _.forOwn(options.uniqueKeys, uniqueKey => {
82 if (uniqueKey.customIndex === undefined) {
83 uniqueKey.customIndex = true;
84 }
85 });
86 }
87
88 if (model) {
89 options.uniqueKeys = options.uniqueKeys || model.uniqueKeys;
90 }
91 attributes = _.mapValues(
92 attributes,
93 attribute => this.sequelize.normalizeAttribute(attribute)
94 );
95 if (options.indexes) {
96 options.indexes.forEach(fields=>{
97 const fieldArr = fields.fields;
98 if (fieldArr.length === 1) {
99 fieldArr.forEach(field=>{
100 for (const property in attributes) {
101 if (field === attributes[property].field) {
102 attributes[property].unique = true;
103 }
104 }
105 });
106 }
107 });
108 }
109 if (options.alter) {
110 if (options.indexes) {
111 options.indexes.forEach(fields=>{
112 const fieldArr = fields.fields;
113 if (fieldArr.length === 1) {
114 fieldArr.forEach(field=>{
115 for (const property in attributes) {
116 if (field === attributes[property].field && attributes[property].unique) {
117 attributes[property].unique = false;
118 }
119 }
120 });
121 }
122 });
123 }
124 }
125
126 if (
127 !tableName.schema &&
128 (options.schema || !!model && model._schema)
129 ) {
130 tableName = this.queryGenerator.addSchema({
131 tableName,
132 _schema: !!model && model._schema || options.schema

Callers 11

testFunction · 0.45
syncMethod · 0.45
operators.test.jsFile · 0.45
field.test.jsFile · 0.45
dropEnum.test.jsFile · 0.45

Calls 5

addSchemaMethod · 0.80
normalizeAttributeMethod · 0.45
attributesToSQLMethod · 0.45
createTableQueryMethod · 0.45
queryMethod · 0.45

Tested by 1

testFunction · 0.36