简体   繁体   中英

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.

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. You could just instantiate it for both databases and write into the sqlite file if mysql access fails. 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

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 . You should be able to catch any errors and use the fs module to read and write to disk as a backup. Should be pretty straightforward imo!

Best of luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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