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?

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.