2017-03-14 221 views
1

js框架。我试图将数据从POST请求保存到数据库Total.js将数据保存到数据库

模型(article.js):

NEWSCHEMA('Article').make(function(schema) { 

schema.define('title', 'String', true); // title of article 
schema.define('about', 'String', true); // about 
schema.define('text', 'String', true); // text 
schema.define('date', 'Date'); // created date 

schema.setSave(function(error , model, options, callback){ 
    var sql = DB(error); 

    sql.insert('articles').make(function(builder) { 
     builder.set('title', model.title); 
     builder.set('about', model.about);  
     builder.set('text', model.text); 
     builder.set('date', F.datetime); 
    }); 

    sql.exec(n => callback(SUCCESS(true))); 
}); 

}); 

和我有控制器(default.js):

exports.install = function() { 
    F.route('/add_article', add_article, ['authorize', '*Article', 'post']); 
}; 

function add_article(){ 
    var self = this; 
    self.body.$save(self, self.callback()); 
} 

但我获取错误:

======= default ---> TypeError: sql.insert(...).make is not a function (http://127.0.0.1:8000/add_article?ts=1489500750601)TypeError: sql.insert(...).make is not a function 

请帮忙谢谢。

+0

你已经安装并initalized SQL代理? –

回答

0

你在这一行

var sql = DB(error); 

你传递错误输入错误的数据库,你应该使用

var sql = DB(model);