|
Permit using Master/slave implementation, with failover capability
see the mysql reference documentation https://www.npmjs.com/package/mysql#poolcluster.
Cluster handle pools with according to patterns and handle failover / distributed load (round robin / random / ordered ).
Example :
const cluster = mariadb.createPoolCluster();
|
cluster.add("master1", {...connection options...});
|
cluster.add("slave1", {...connection options...});
|
cluster.add("slave2", {...connection options...});
|
|
cluster.getConnection(/^slave*$, "RR")
|
.then(conn => {
|
return conn.query("SELECT 1")
|
.then(row => {
|
conn.end();
|
return row[0]["@node"];
|
})
|
.finally(() => {
|
conn.end();
|
});
|
});
|
|