-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.ejs
27 lines (26 loc) · 1.03 KB
/
model.ejs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
* Created by ddl2Model on <%= (new Date().toLocaleString())%>
* TableName: <%=name%> <<%=comment%>>
*/
"use strict";
module.exports = function(sequlize, DataTypes){
return sequlize.define("<%=name%>",{
<% for(var i=0; i < fields.length; i++){%>
<% var fd = fields[i]
var fds = []
if(fd.type == 'TEXT')fds.push("type:Sequelize.TEXT")
else if(fd.type == 'TINYTEXT')fds.push('type:Sequelize.TEXT("tiny")')
else fds.push(`type:Sequelize.${fd.type}(${fd.length})`)
if(fd.name == autoincrementField) fds.push('autoIncrement:true')
if(fd.name == primaryKey) fds.push('primaryKey:true')
if(fd.defaultValue != '' && fd.name != autoincrementField && fd.name != primaryKey){
if(fd.defaultValue === 'timestamps') fds.push('defaultValue: Data.now()')
else fds.push(`defaultValue: ${fd.defaultValue}`)
}%>
<%=fields[i].name%>: { <%- fds.join(', ')%>}, <%if(fields[i].comment != '') {%>//<%=fields[i].comment%><%}%>
<%}%>
},{
freezeTableName: true,
tableName: "<%=name%>"
})
}