Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

support LONGTEXT in mysql #63

Merged
merged 1 commit into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 9, 2013
  1. @joeferner

    support LONGTEXT in mysql

    joeferner authored
This page is out of date. Refresh to see the latest.
Showing with 33 additions and 9 deletions.
  1. +33 −9 lib/driver/mysql.js
View
42 lib/driver/mysql.js
@@ -10,12 +10,23 @@ var MysqlDriver = Base.extend({
this.connection = connection;
},
- mapDataType: function(str) {
- switch(str) {
+ mapDataType: function(spec) {
+ var len;
+ switch(spec.type) {
case type.STRING:
return 'VARCHAR';
case type.TEXT:
- return 'TEXT';
+ len = parseInt(spec.length) || 1000;
+ if(len > 16777216) {
+ return 'LONGTEXT';
+ }
+ if(len > 65536) {
+ return 'MEDIUMTEXT';
+ }
+ if(len > 256) {
+ return 'TEXT';
+ }
+ return 'TINYTEXT';
case type.INTEGER:
return 'INTEGER';
case type.DATE_TIME:
@@ -23,7 +34,17 @@ var MysqlDriver = Base.extend({
case type.REAL:
return 'REAL';
case type.BLOB:
- return 'BLOB';
+ len = parseInt(spec.length) || 1000;
+ if(len > 16777216) {
+ return 'LONGBLOB';
+ }
+ if(len > 65536) {
+ return 'MEDIUMBLOB';
+ }
+ if(len > 256) {
+ return 'BLOB';
+ }
+ return 'TINYBLOB';
case type.TIMESTAMP:
return 'TIMESTAMP';
case type.BINARY:
@@ -34,13 +55,16 @@ var MysqlDriver = Base.extend({
},
createColumnDef: function(name, spec, options) {
- var type = this.mapDataType(spec.type);
- var len = spec.length ? util.format('(%s)', spec.length) : '';
- if (type === 'VARCHAR' && len === '') {
- len = '(255)';
+ var t = this.mapDataType(spec);
+ var len;
+ if(spec.type !== type.TEXT && spec.type !== type.BLOB) {
+ len = spec.length ? util.format('(%s)', spec.length) : '';
+ if (t === 'VARCHAR' && len === '') {
+ len = '(255)';
+ }
}
var constraint = this.createColumnConstraint(spec, options);
- return [name, type, len, constraint].join(' ');
+ return [name, t, len, constraint].join(' ');
},
createColumnConstraint: function(spec, options) {
Something went wrong with that request. Please try again.