Could someone enlighten me, how Exposed offers rea...
# exposed
d
Could someone enlighten me, how Exposed offers reader/writer node splitting, and if there are any recommended practices for handling this efficiently?
s
If you mean writes go to one database and reads to another then it doesnt. You need to do it manually by passing an explicit
Database
to the transaction function
thank you color 1
d
...That's so sad. I used sequelize that support automatically depends on query type(select or insert). select query goes to reader node, insert query goes to writer node.
Copy code
const sequelize = new Sequelize('database', null, null, {
  dialect: 'mysql',
  port: 3306,
  replication: {
    read: [
      { host: '8.8.8.8', username: 'read-1-username', password: process.env.READ_DB_1_PW },
      { host: '9.9.9.9', username: 'read-2-username', password: process.env.READ_DB_2_PW }
    ],
    write: { host: '1.1.1.1', username: 'write-username', password: process.env.WRITE_DB_PW }
  },
  pool: { // If you want to override the options used for the read/write pool you can do so here
    max: 20,
    idle: 30000
  },
})
s
I dont really see much need for this in the framework? Its just something like:
Copy code
transaction(masterDb) {
 // DO stuff
}
transaction(readDb) {
 // Do stuff
}
You can even get the read pool by:
Copy code
transaction(masterDb) {
 // DO stuff
}
transaction(readDbList.random()) {
 // Do stuff
}
Then its explicit without violating the transaction and isolation level guarantees of the database
👍 1
pepe clap 1
d
I somewhat agree with your opinion, too. But, manual is manual, you know 😹 Do you know any github repo using similar mothod?
s
No but havent really looked outside exposed
a
Just make function “write { … }” and “read { … }” and it is more explicit. Otherwise make a custom implementation for the Connection that delegates based on the action to inner Connection. I believe that is how Sequalize does it.
👍 1
Actually…. Hikari supports this and I think you can just use the HikariPool for this
👀 1
s
Can you link to Hikari documentation of this ?
a
I am searching but only finding obscure GitHub issues… so maybe not the best route
d
Does HikariCP supports this function?