Comments (7)
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.
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.
@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.
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.
@kubino Can you paste some example code where it didn't work.
from knex.
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.
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)
- pglite support
- esm migrations does not work on Node 22
- Straightforward way of getting the PID of a query, ahead-of-time.
- can't extend existing method
- Error without actual reason in CLI due to TypeScript error
- Unknown pending operation error HOT 1
- Mysql forShare query compiler error
- `timestamps` method signature in schema is misleading
- knexfile.ts broken in esm
- Compile sql during webpack build time
- Unnamed error when JSON constraint prevents an update/insert HOT 2
- [Typescript] Can't return something else than knex in the extend function HOT 1
- Use custom MySQL2 connection pool into Knex - getting stucked
- Knex saving into wrong database, no errors, other tables work fine
- MongoDB Realm Web - features request
- increment/decrement lacks precision for large integers
- Knex knex.fn.now() function triggers syntax error in MSSQL
- Add serverless-postgres to client
- Hey Team, we want to authenticate our Node.js to MySQL using Kerberos. Does knex have built in support for that? Do you have any documentation for that?
- Feature Request/Clarification - per migration transactions
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.