Merge pull request #37 from strongloop/feature/fix-issue-36
Map object/json to TEXT
This commit is contained in:
commit
d97e05fb4a
|
@ -980,10 +980,12 @@ function datatype(p) {
|
|||
switch (p.type.name) {
|
||||
default:
|
||||
case 'String':
|
||||
case 'JSON':
|
||||
dt = columnType(p, 'VARCHAR');
|
||||
dt = stringOptionsByType(p, dt);
|
||||
break;
|
||||
case 'JSON':
|
||||
case 'Object':
|
||||
case 'Any':
|
||||
case 'Text':
|
||||
dt = columnType(p, 'TEXT');
|
||||
dt = stringOptionsByType(p, dt);
|
||||
|
@ -1023,7 +1025,8 @@ function stringOptionsByType(p, dt) {
|
|||
default:
|
||||
case 'varchar':
|
||||
// The maximum length for an ID column is 1000 bytes
|
||||
var len = p.limit || ((p.type !== String) ? 32768 : p.id ? 255: 1024);
|
||||
// The maximum row size is 64K
|
||||
var len = p.limit || ((p.type !== String) ? 8192 : p.id ? 255: 1024);
|
||||
dt += '(' + len + ')';
|
||||
break;
|
||||
case 'char':
|
||||
|
|
|
@ -10,6 +10,8 @@ describe('mysql', function () {
|
|||
Post = db.define('PostWithDefaultId', {
|
||||
title: { type: String, length: 255, index: true },
|
||||
content: { type: String },
|
||||
comments: [String],
|
||||
history: Object,
|
||||
stars: Number
|
||||
});
|
||||
|
||||
|
@ -33,6 +35,26 @@ describe('mysql', function () {
|
|||
});
|
||||
});
|
||||
|
||||
it('should allow array or object', function (done) {
|
||||
Post.create({title: 'a', content: 'AAA', comments: ['1', '2'],
|
||||
history: {a: 1, b: 'b'}}, function (err, post) {
|
||||
|
||||
should.not.exist(err);
|
||||
|
||||
Post.findById(post.id, function (err, p) {
|
||||
p.id.should.be.equal(post.id);
|
||||
|
||||
p.content.should.be.equal(post.content);
|
||||
p.title.should.be.equal('a');
|
||||
p.comments.should.eql(['1', '2']);
|
||||
p.history.should.eql({a: 1, b: 'b'});
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('updateOrCreate should update the instance', function (done) {
|
||||
Post.create({title: 'a', content: 'AAA'}, function (err, post) {
|
||||
post.title = 'b';
|
||||
|
|
Loading…
Reference in New Issue