Comments (15)
+1 for @gregbty
The knex instance is not destroyed after running seed. Any ideas?
from knex.
Yep, covered now in: http://knexjs.org/#Installation-pooling
If you ever need to explicitly teardown the connection pool, you may use knex.destroy([callback]). You may use knex.destroy by passing a callback, or by chaining as a promise, just not both.
from knex.
Yeah... those two are coming from the node-generic-pool library, which is a little hard to follow (I've got a fork here that I'm looking to use in the next release after the refactor I'm working on currently based on your other suggestions.
Basically, the database connection pool currently automatically shuts down with process.on('exit', ...
, but if you have a better idea for how it should be set up, I'm all ears.
from knex.
It does indeed shut down on process exit, but what I'm talking about is requesting shutting down akin to server.close()
. That — knex.close()
— would suit much better with the new architecture we were talking about the other day. :)
I quickly just did the following to get going:
Knex.close = function() {
var pool = Knex.client.pool
pool.drain(pool.destroyAllNow)
}
from knex.
Sounds good, I'll make sure it's in there... if you want to take a look at what I've got sofar here it is
from knex.
I just realized, shutting down in the exit
event handler is entirely useless because the process gets killed right after the handler runs, even though there might be events in the eventloop.
from knex.
Example of the above:
process.on("exit", function() {
console.log("My life ends!")
process.nextTick(function() { console.log("FML") })
})
"FML" never put out.
from knex.
@moll That behavior is documented
from knex.
@caseywebdev Absolutely. I was merely pointing out that Knex doing its shutdown there is pointless.
from knex.
Okay so it no longer does the process.exit thing, there is now a client.pool.destroy
- http://knexjs.org/docs/clients/pool.html which handles calling the pool draining.
from knex.
Please reopen. The link above 404s. How about something like:
var knex = require('knex')(config)
knex.close()
knex.disconnect()
// something else?
Would be nice for Gulp tasks and unit tests. I shouldn't have to process.exit
.
from knex.
Ah true! Thanks @tgriesser.
from knex.
This works fine with the migrations API but the seed API doesn't seem to adhere to the destroy call. If I try knex.migration.latest alone with knex.destroy it works fine, but knex.seed.run does not.
var instance = knex(db);
return instance.migrate.latest()
.finally(function () {
return instance.destroy(); //works
});
...
return instance.seed.run()
.finally(function () {
return instance.destroy(); //does not work
});
from knex.
The issue exists as mentioned in #55 (comment). Are there any workarounds?
from knex.
@thebrodmann Please open bug report, this issue was closed, because it was about different thing.
from knex.
Related Issues (20)
- knex.table({ t: knex.select(...) }) style is supported but error by type check
- unique vs dropUnique inconsistency when using predicate
- `.raw()` should allow specifying different queries for different engines
- Middleware/wrapper to wrap all queries in a transaction
- About the "Too many connections" behavior
- Bad connection not being released from pool
- Transforming the result of a query promise?
- Document not to use propagateCreateError: false
- insert can use Buffer, but not work with Uint8Array (I use mysql2)
- Knex Migrate MSSQL error HOT 1
- feat: Is there any plan to support bun:sqlite?
- KnexTimeout connection Issue while connecting with PostgreSQL DB
- Cannot read properties of undefined HOT 2
- Altar table fails against MySQL, possibly invalid SQL generation HOT 2
- The value of a Date type field is shared by multiple records. (With Oracle Client)
- SQLITE_NOTADB: file is not a database with SQLCipher
- Add comments to promise aware knex transaction commits
- Using Jest with Knex, I get 'Error: Unable to acquire a connection' every time HOT 1
- Parse a query string back to QueryBuilder object?
- Transaction method resolves if the provided callback rejects with `undefined`.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from knex.