Coder Social home page Coder Social logo

Comments (15)

alechirsch avatar alechirsch commented on May 13, 2024 21

+1 for @gregbty

The knex instance is not destroyed after running seed. Any ideas?

from knex.

tgriesser avatar tgriesser commented on May 13, 2024 2

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.

tgriesser avatar tgriesser commented on May 13, 2024

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.

moll avatar moll commented on May 13, 2024

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.

tgriesser avatar tgriesser commented on May 13, 2024

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.

moll avatar moll commented on May 13, 2024

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.

moll avatar moll commented on May 13, 2024

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.

caseywebdev avatar caseywebdev commented on May 13, 2024

@moll That behavior is documented

from knex.

moll avatar moll commented on May 13, 2024

@caseywebdev Absolutely. I was merely pointing out that Knex doing its shutdown there is pointless.

from knex.

tgriesser avatar tgriesser commented on May 13, 2024

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.

aj0strow avatar aj0strow commented on May 13, 2024

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.

aj0strow avatar aj0strow commented on May 13, 2024

Ah true! Thanks @tgriesser.

from knex.

gregbty avatar gregbty commented on May 13, 2024

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-dr-lazy avatar the-dr-lazy commented on May 13, 2024

The issue exists as mentioned in #55 (comment). Are there any workarounds?

from knex.

elhigu avatar elhigu commented on May 13, 2024

@thebrodmann Please open bug report, this issue was closed, because it was about different thing.

from knex.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.