{"repo":"thetutlage/knex-dynamic-connection","free":true,"listed":false,"github":"https://github.com/thetutlage/knex-dynamic-connection","clone":"git clone https://github.com/thetutlage/knex-dynamic-connection.git","description":"Adds support for dynamically returning connection config for knex queries. Helpful when you want to deal with write/read replicas","language":"JavaScript","stars":39,"topics":["knexjs","database"],"license":"MIT","category":"databases-storage","readme_excerpt":"Knex Dynamic Connection This module is meant to patch knex and add support for defining dynamic connection configuration. [![gh-workflow-image]][gh-workflow-url] [![npm-image]][npm-url] Table of contents - Why you need it? - Is it reliable? - How does it actually work? - Will this work in the future? Why you need it? Knex.js doesn't have inbuilt support for read/write connections. One can create two seperate instances of knex for read and write, but that still doesn't completely solve the problem. For example: Now, if you want to use multiple servers for read operations, you cannot do that, since knex.js allows only one connection server and will pool connections within that server. Following is not possible With the help of this module, you can make knex create a connection using the dynamic config for every query. The patchKnex method overwrites the acquireRawConnection on all the dialects and make them fetch the config from your callback vs reading it from a static source. Is it reliable? Yes! 1. I have copied the code of acquireRawConnection from the knex codebase and have just made one line of change to read the config from a different source. 2. I have written tests for select , insert , transactions and schema methods. 3. The code is tested against mssql , mysql , mysql2 and pg . 4. The connection is still managed inside the pool, so don't worry about any extra maintaince overhead. How does it actually work? Knex.js makes use of tarn.js for managing pool resources and ","default_branch":null,"files":null,"tree":[],"storefront":"/r/thetutlage","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/thetutlage/knex-dynamic-connection/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}