@motowhere/knex-waitfordb
v1.1.4
Published
Small utility that reads your knexfile.js and blocks until the DB is ready
Downloads
3
Readme
knex-waitfordb
Does what it says on the tin. Reads your knexfile.js, tries to run
SELECT 1 + 1;
on your database, if it fails it waits 1000ms, tries again, and returns
when it can run it. You can optionally pass a custom delay as last argv or via
the --delay [delay]
argument. If your knexfile.js
is not located in the
current working directory you can use the
--knexfile [path/to/your/knexfile.js]
argument.
What?
It's for use in your npm scripts. You might have something like this:
"scripts": {
"migrate": "knex migrate:latest"
}
but you need to make sure the database is up to run this, right? So do:
"scripts": {
"premigrate": "knex-waitfordb",
"migrate": "knex migrate:latest"
}
and npm install --save-dev knex-waitfordb
. Now npm run migrate
waits
for your database to be up. No hassle!
You can also use it directly in your code:
const waitForDB = require("@motowhere/knex-waitfordb")
waitForDB().then(() => {
// Do cool database stuff in here
knex.migrate.latest()
})
Err...
It's really useful in Docker containers. You'll see.
Okay?
And it's MIT.