typeorm / typescript-express-example Goto Github PK
View Code? Open in Web Editor NEWExample how to use Express and TypeORM with TypeScript
Example how to use Express and TypeORM with TypeScript
Either using curl or Postman:
Keep getting this error:
QueryFailedError: ER_NO_DEFAULT_FOR_FIELD: Field 'title' doesn't have a default value at new QueryFailedError (D:\business\prototyping\development\src\node\typescript-express-example\node_modules\typeorm\error\QueryFailedError.js:11:28) at Query.<anonymous> (D:\business\prototyping\development\src\node\typescript-express-example\node_modules\typeorm\driver\mysql\MysqlQueryRunner.js:169:45) at Query.<anonymous> (D:\business\prototyping\development\src\node\typescript-express-example\node_modules\mysql\lib\Connection.js:525:10) at Query._callback (D:\business\prototyping\development\src\node\typescript-express-example\node_modules\mysql\lib\Connection.js:491:16) at Query.Sequence.end (D:\business\prototyping\development\src\node\typescript-express-example\node_modules\mysql\lib\protocol\sequences\Sequence.js:83:24) at Query.ErrorPacket (D:\business\prototyping\development\src\node\typescript-express-example\node_modules\mysql\lib\protocol\sequences\Query.js:90:8) at Protocol._parsePacket (D:\business\prototyping\development\src\node\typescript-express-example\node_modules\mysql\lib\protocol\Protocol.js:291:23) at Parser._parsePacket (D:\business\prototyping\development\src\node\typescript-express-example\node_modules\mysql\lib\protocol\Parser.js:433:10) at Parser.write (D:\business\prototyping\development\src\node\typescript-express-example\node_modules\mysql\lib\protocol\Parser.js:43:10) at Protocol.write (D:\business\prototyping\development\src\node\typescript-express-example\node_modules\mysql\lib\protocol\Protocol.js:38:16)
I'm wondering how to write tests for this kind of express/typorm project setup.
How to mock the Repositories?
Any ideas/recommendations?
Hi, I have a question.I use the typeorm-cli command created the framework, how to compile release to production?
You have a single createConnection()
happening once at the top of this example. I understand that creates a connection pool. But how does TypeORM when it should add vs reuse connections in the pool? (If you have two requests coming in at the same time, and each request handler makes some queries, how does TypeORM know which queries go to which connection?)
how make class a controller there are 4 method: getAll, create , edit , update ?
运行的时候显示这个错误:
tsc && node src/index.js
node_modules/typeorm/driver/mongodb/typings.d.ts:4288:13 - error TS2339: Property 'asyncIterator' does not exist on type 'SymbolConstructor'.
4288 Symbol.asyncIterator: AsyncIterableIterator;
~~~~~~~~~~~~~
node_modules/typeorm/driver/mongodb/typings.d.ts:4288:31 - error TS2304: Cannot find name 'AsyncIterableIterator'.
4288 Symbol.asyncIterator: AsyncIterableIterator;
~~~~~~~~~~~~~~~~~~~~~
Hi,
Is there any approach how to set a mysql transaction inside a single request action method? So we may be able to rollback transaction whenever error occurs.
Code example:
export async function saveDepartmentAction(request: Request, response: Response) {
// data
let data = request.body
// insert department data
const result = await getEntityManager().query(`
// Some department insert (parent data)
`, [ some department data ])
// add child data (department positions)
data.positions.forEach(async position => {
const add_position = await getEntityManager().query(`
// Some position insert (child data)
`, [ some department id and position id ])
});
response.send(data)
}
I would like to achieved something like this https://github.com/mysqljs/mysql#transactions
Issue type:
[x ] question
[ ] bug report
[ ] feature request
[ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[x ] mysql / mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[x ] latest
[ ] @next
[ ] 0.x.x (or put your version here)
I'm adding unit testing by jest for express and typeorm but it's seem many things to handle from mocking server, app and connection from typeorm.
If somebody have already build the example and share it. that would be great.
Hi There
In typescript-express-example/src/index.ts you have some beautifully elegant code:
`
// register all application routes
AppRoutes.forEach(route => {
app[route.method](route.path, (request: Request, response: Response, next: Function) => {
route.action(request, response)
.then(() => next)
.catch(err => next(err));
});
});
`
That registers all applications routes.
If you enable
"strict": true
in the tsconfig.json I get the error:
src/index.ts:19:4 - error TS7017: Element implicitly has an 'any' type because type 'Express' has no index signature. 19 app[route.method](route.path, (request: Request, response: Response, next: Function) => { ~~~~~~~~~~~~~~~~~
Is there a way to combine modules in this elegant way and enable strict?
Kind regards
after cloning the project and replacing the database details i recieve this error when performing a GET request to http://localhost:3000/posts
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.