-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support knexfile, migration and seeds in TypeScript #1769
Conversation
I just saw this has already been requested in #1564. |
// Deletes ALL existing entries | ||
return knex("table_name").del() | ||
.then(function () { | ||
return Promise.all([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Promise.all should not be promoted here, since people are using it wrong in places where order of queries matters. It should be fixed in every other stub as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, you mean this — ?
.then(function () {
return knex("table_name").insert([
{ id: 1, colName: "rowValue1" },
{ id: 2, colName: "rowValue2" },
{ id: 3, colName: "rowValue3" }
]);
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep definitely better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated this branch for the TypeScript stub, have a patch ready for the other stubs once you find it good to merge.
thanks! |
Can anybody help me run Knex with Typescript? {
"dependencies": {
"knex": "github:tgriesser/knex#49aa6f73142a7710f33acc095d4b9cdfe6919f46"
},
"devDependencies": {
"@types/knex": "0.0.39",
"@types/node": "^7.0.0",
"ts-node": "^2.0.0",
"typescript": "^2.1.5"
}
} My tsconfig.json: {
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"sourceMap": true,
"typeRoots": [
"node_modules/@types"
]
}
} I run Requiring external module ts-node/register
Using environment: development
C:\Users\barin\project\knex-test\node_modules\knex\lib\index.js:2
import Raw from './raw';
^^^^^^
SyntaxError: Unexpected token import
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\barin\project\knex-test\node_modules\knex\knex.js:8:18)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19) It does not understand ES6 syntax. But after install Knex by commit hash I processed |
The issue here is that the source isn't getting transpiled to commonjs modules because @elhigu When can we expect the next release? |
@prashaantt, thanks! |
@prashaantt I haven't thought about it, but I could roll out next version when I got some spare time... can't say exactly when. |
Hi @elhigu! Have you got any news about release? |
* Support knexfile, migration and seeds in TypeScript * Look for .ts seed files * Fix linter warning for max-len * Enforce migration scripts to return a promise * Remove Promise.all example from stub
This is a breaking change for existing TypeScript users. This has broken my existing project migrations by now using TypeScript files by default where I have been compiling to JavaScript. Using |
* Support knexfile, migration and seeds in TypeScript * Look for .ts seed files * Fix linter warning for max-len * Enforce migration scripts to return a promise * Remove Promise.all example from stub
This will allow using
knex
in a TypeScript project. These commands will now work:knex
will now generate and automatically pick upknexfile.ts
,migration_name.ts
,seed_name.ts
, assumingts-node
is available to execute from within the project.If you like this, I'll also update the docs to indicate that this option is now available.