0

I'm having db.js file which consist of

var mysql      = require('mysql2');
var mysqlModel = require('mysql-model');
    var appModel = mysqlModel.createConnection({
      host     : 'localhost',
      user     : 'root',
      password : 'root',
      database : 'tabio',
    }); 

var User = appModel.extend({
    first: "table_first",
});
var Message = appModel.extend({
    second: "table_second",
});

module.exports = {
  first : first,
  second : second
};    

I am requesting the db.js in another file main.js like

var connection = require('./db.js');
test = new connection.first({ 
    column1: 12, 
    column2: 34,  
});
test.save();

it successfully saves the recored. But how can i run select, delete, update query here.

while using var test = connection.first.find(1);, i get the error TypeError: connection.User.find is not a function. how to use the select & update query using db-migrate?

m2j
  • 1,152
  • 5
  • 18
  • 43

1 Answers1

1
test = new connection.first();

then you can use test.query, test.find.

query Runs custom query

Usage:

movie.query(query); movie.query(query, callback); Parameters:

string query: Your custom sql query to run function callback: returns errors and results Example:

movie.query("SELECT name FROM movies WHERE director = 'James Cameron' ORDER BY year", function(err, rows, fields) { // Do something... });

BlackMamba
  • 10,054
  • 7
  • 44
  • 67