3

js framework. I'm trying to save data to DB from post request

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)));
});

});

and i have controller(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());
}

But i am getting error:

======= 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

please help thanks.

1 Answers1

-1

You are entering an error to the DB on this line

var sql = DB(error);

You're passing the error, you should use

var sql = DB(model);
fp007
  • 412
  • 1
  • 4
  • 18