Skip to content

Commit 752359f

Browse files
committed
Add columnDataType as base function
1 parent 8dcf69b commit 752359f

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

lib/sql.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,25 @@ SQLConnector.prototype.addPropertyToActual = function(model, propName) {
164164
};
165165

166166
SQLConnector.prototype.columnDataType = function(model, property) {
167-
throw new Error(g.f('{{columnDataType()}} must be implemented by the connector'));
167+
var columnMetadata = this.columnMetadata(model, property);
168+
var colType = columnMetadata && columnMetadata.dataType;
169+
if (colType) {
170+
colType = colType.toUpperCase();
171+
}
172+
var prop = this.getModelDefinition(model).properties[property];
173+
if (!prop) {
174+
return null;
175+
}
176+
var colLength = columnMetadata && columnMetadata.dataLength ||
177+
prop.length || prop.limit;
178+
if (colType && colLength) {
179+
return colType + '(' + colLength + ')';
180+
}
181+
return this.buildColumnType(prop);
182+
};
183+
184+
SQLConnector.prototype.buildColumnType = function(property) {
185+
throw new Error(g.f('{{buildColumnType()}} must be implemented by the connector'));
168186
};
169187

170188
SQLConnector.prototype.propertyHasNotBeenDeleted = function(model, propName) {

0 commit comments

Comments
 (0)