是否可以从数据库转储生成knex种子文件? [英] Is it possible to generate knex seed files from a database dump?
本文介绍了是否可以从数据库转储生成knex种子文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
就我而言,我正在使用mysql.但是,我正在寻找一种用于从当前正在运行的数据库或数据库转储生成knex种子文件的通用解决方案.
In my case, I am using mysql. However, I am looking for a general solution for generating knex seed files from either the currently running database or a database dump.
我可以类似:
exports.seed = function(knex, Promise) {
var sql = fs.readFileSync('./data/workbench.sql').toString();
return knex.raw('DROP DATABASE workbench')
.then(() => knex.raw('CREATE DATABASE workbench'))
.then(() => knex.raw(sql))
};
但这并不理想...
推荐答案
AFAIK node-postgresql
驱动程序不支持在一个字符串中传递多个语句.
AFAIK node-postgresql
driver doesn't support passing multiple statements in one string.
当我需要从节点代码恢复文件中的转储时,我正在调用shell命令(使用shelljs).
I'm calling shell command (with shelljs) when I need to restore dump from file from node code.
这篇关于是否可以从数据库转储生成knex种子文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文