strapi
strapi copied to clipboard
enhancement(db): allow connection to be a function
What does it do?
Allow database connection functions in user configs without any breaking changes by adding a check in init to resolve the connection and configure the dialect.
There is no risk of a breaking change for anyone currently using connection objects because those will still always handled synchronously exactly as before.
Why is it needed?
https://github.com/strapi/strapi/issues/18474
Essentially, connection functions are a requirement for many database services that require refreshing access tokens rather than a fixed auth.
There is still a potential problem where if a plugin tries to address db.connection
prior to init
, it can now potentially fail, so connection functions will only be added as experimental and we can ban that practice and provide an alternate solution in v6 as a breaking change so that we can consider it stable.
How to test it?
experimental: 0.0.0-experimental.b391efb8ce3832d4f280928b99ef5cb9c228fdee
npx create-strapi-app@0.0.0-experimental.b391efb8ce3832d4f280928b99ef5cb9c228fdee
Use a function in your database config connection instead of an object
Unit tests have been added
Related issue(s)/PR(s)
https://github.com/strapi/strapi/issues/18474
https://github.com/strapi/strapi/pull/18857
Docs PR: https://github.com/strapi/documentation/pull/2252
PR for Knex to fix Sqlite3 warning: https://github.com/knex/knex/pull/6136