简体   繁体   English

使用SQLite故障转移的nodejs MySQL连接

[英]nodejs MySQL connection with SQLite Failover

I'm looking for a simple example (as I'm new to node) on how to connect to MySQL to do a write (INSERT) from node.js and if that connection to the DB is unsuccessful I'd like to write the INSERT to either file so it can be replayed later or a local SQLite DB file. 我正在寻找一个关于如何连接到MySQL以便从node.js进行写入(INSERT)的简单示例(因为我是Node的新手),并且如果与数据库的连接不成功,我想编写插入到任一文件中,以便以后可以重播,也可以插入本地SQLite DB文件。

Willing to take advice on if there is a better way to do this. 愿意就是否有更好的方法提出建议。

Any help greatly appreciated. 任何帮助,不胜感激。

Regards Ric 问候里克

You could use Sequelize as it supports currently MySQL and SQLite. 您可以使用Sequelize,因为它目前支持MySQL和SQLite。 You could just instantiate it for both databases and write into the sqlite file if mysql access fails. 您可以只为两个数据库实例化它,如果mysql访问失败,则将其写入sqlite文件。 If you are interested in that I could also provide an example. 如果您对此感兴趣,我也可以提供一个示例。 Check this http://sequelizejs.com/#installation and this http://sequelizejs.com/?active=dialects#dialects 检查此http://sequelizejs.com/#installation和此http://sequelizejs.com/?active=dialects#dialects

Sounds like an interesting idea but I can't say I've seen anybody implement it. 听起来像一个有趣的主意,但我不能说我见过有人实现它。

That said, I can point you in the right direction. 也就是说,我可以指出正确的方向。 Take a look at Felix's mysql module . 看一下Felix的mysql模块 You should be able to catch any errors and use the fs module to read and write to disk as a backup. 您应该能够捕获任何错误,并使用fs模块作为备份读取和写入磁盘。 Should be pretty straightforward imo! imo应该很简单!

Best of luck. 祝你好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM