【发布时间】:2016-12-14 21:01:35
【问题描述】:
我有 db.js 文件,其中包含
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
};
我在另一个文件main.js 中请求db.js 喜欢
var connection = require('./db.js');
test = new connection.first({
column1: 12,
column2: 34,
});
test.save();
它成功保存了记录。但是我怎样才能在这里运行select、delete、update 查询。
在使用var test = connection.first.find(1); 时,我收到错误TypeError: connection.User.find is not a function。如何使用db-migrate 使用select 和update 查询?
【问题讨论】:
标签: javascript mysql node.js express dbmigrate