Giter Site home page Giter Site logo

transactions broken with postgres about knex HOT 7 CLOSED

knex avatar knex commented on July 30, 2024
transactions broken with postgres

from knex.

Comments (7)

tgriesser avatar tgriesser commented on July 30, 2024

Hey @kubino - you're right, I did some major refactoring of a few pieces before shipping the initial release and didn't realize I didn't have any tests for transactions. I believe I just fixed it up and added some tests, please take a look and let me know if you see any issues now.

from knex.

kubino avatar kubino commented on July 30, 2024

Hi perfect, transactions are now working. Your library looks amazing. I am pretty new to promises, so it's hard to get full picture of your internals for me. However I have different problem now. In Postgres also Schema changes can be run inside the transaction. This is also a good way how to control order of sql command - I want to ensure delete table is called before create table. I am passing now transaction object to dropTable and createTable methods and inside I am instructing to use same connection. Maybe it would be usefull to support it out of the box.

from knex.

tgriesser avatar tgriesser commented on July 30, 2024

@kubino - If you want to ensure dropTable is called before createTable, you should be able to achieve that with a promise, no transaction necessary.

Knex.Schema.dropTableIfExists('users').then(function () {

   return Knex.Schema.createTable('users', function (t) {
      t.increments('id');
      t.string('first_name');
      t.string('last_name');
   });

}).then(function() {
   console.log('users has been dropped and created');
})

from knex.

kubino avatar kubino commented on July 30, 2024

Hi I did tried this, sorry I forgot to mention it before.
It works with mysql but NOT with postgres. However when runned within transaction and same connection is used, everything is just fine. Not sure where is the difference between these two databases. I guess both are opening new connection, and we are just relying here there everything will get processed by database as it was issued by node server. But this was not my case with Postgres. I believe it can work on other machines...

from knex.

tgriesser avatar tgriesser commented on July 30, 2024

@kubino Can you paste some example code where it didn't work.

from knex.

kubino avatar kubino commented on July 30, 2024

sorry forget it it was my fault, just called a method instead of passing a function reference in then() !!!

Your library is awesome , I was looking hard for some simple but powerful API. Great Job. Thank you for sharing it

from knex.

tgriesser avatar tgriesser commented on July 30, 2024

Glad to hear it! Also, you don't need to create individual when.defer() instances or individual error handlers for each a promise, just return a promise to the promise and the first promise becomes the second... and if any of them fail the last promise gets that error... i.e.:

var promises = [];
_.each(Object.keys(tablesDefinition), function(tblName) {
   promises.push(Knex.Schema.createTable(tblName, tablesDefinition[tblName]).then(function() {
      console.log('Created %s!', tblName);
   }));
});
return when.all(promises).then(null, function(e) { 
   console.log('createTableError: ' + e.toString()) 
});

rather than what you had posted before.

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.