【问题标题】:Total.js save data to databaseTotal.js 将数据保存到数据库
【发布时间】:2018-02-07 00:23:35
【问题描述】:

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

请帮忙谢谢。

【问题讨论】:

  • 您是否安装并初始化了 SQL 代理?

标签: total.js


【解决方案1】:

您在此行向数据库输入错误

var sql = DB(error);

你传递了错误,你应该使用

var sql = DB(model);

【讨论】:

  • total.js世界中向DB传递错误是正确的
猜你喜欢
  • 1970-01-01
  • 2019-11-22
  • 2012-07-21
  • 2019-03-31
  • 2013-04-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多