Total.js将数据保存到数据库

时间:2017-03-14 16:10:37

标签: total.js

js框架。我正在尝试从发布请求中将数据保存到数据库

model(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

请帮助谢谢。

1 个答案:

答案 0 :(得分:0)

您正在此行的数据库中输入错误

var sql = DB(error);

您传递错误,应使用

var sql = DB(model);
相关问题