Comments (4)
hi. Yes, it does support async/await syntax. Actually its used almost everywhere in the documentation on the site
from typeorm.
Whoops! I was only looking at the Github readme. Awesome!
from typeorm.
can you give me a good example, or tell me what is the problen in my code, because it doesn't work in my project:
Console: Promise {undefined}
//
import {createConnection} from "typeorm";
import {User} from "../entities/User";
import {Field} from "../entities/Field";
import {Cow} from "../entities/Cow";
import {Semen} from "../entities/Semen";
export interface UserService {
getAll();
}
export class UserRepository implements UserService{
public async getAll(){
createConnection({
driver: {
type: "mysql",
host: "localhost",
port: 3306,
username: "root",
password: "1234",
database: "farmbook"
},
entities: [
User
],
autoSchemaSync: true,
}).then(async connection => {
return await connection.getRepository(User).createQueryBuilder("user").getMany();
}).catch(error => {console.log("Userek lekerdezesenel hiba;")});
}
}
//
import "reflect-metadata";
import {createConnection} from "typeorm";
import {User} from "./entities/User";
import {Cow} from "./entities/Cow";
import {Field} from "./entities/Field";
import {Semen} from "./entities/Semen";
import {UserRepository} from "./repositories/UserRepository";
let us = new UserRepository();
const users = us.getAll();
console.log(users);
//
from typeorm.
Because you should learn how async/await syntax works first. You don't use await
createConnection({
driver: {
type: "mysql",
host: "localhost",
port: 3306,
username: "root",
password: "1234",
database: "farmbook"
},
entities: [
User
],
autoSchemaSync: true,
}).then(async connection => {
return await connection.getRepository(User).createQueryBuilder("user").getMany();
}).catch(error => {console.log("Userek lekerdezesenel hiba;")});
should be replaced with
async function run() {
const connection = await createConnection({
driver: {
type: "mysql",
host: "localhost",
port: 3306,
username: "root",
password: "1234",
database: "farmbook"
},
entities: [
User
],
autoSchemaSync: true,
};
const users = await connection.getRepository(User).createQueryBuilder("user").getMany();
}
p.s. please format code properly before posing a comment
from typeorm.
Related Issues (20)
- typeorm query spesific selecion HOT 1
- typeorm TypeError: Cannot read properties of undefined (reading 'type')
- TypeORM Migration Bug: Duplicate Index Names in Generated Migration
- The getPendingMigrations creates migrations table
- Bug: ORDER BY NULLS (FIRST | LAST) for SQLServer
- Issues with migrations after upgrading typeorm from 0.2.31 to 0.3.20
- Similar tests with identical titles
- prettier should be enforced in circleci
- Instead of experimental decorators use the full version of decorators introduced in TS 5.0 HOT 1
- Postgres geometry column is always being altered to type geometry in every migration despite already being type geometry
- QueryFailedError: read ECONNRESET HOT 7
- Using transactions in tests w/ NestJS & TypeORM
- QueryBuilder looks up the wrong joinAttr when entities have identical property names
- Simple SQL statement generation with Repository object
- SSL AMAZON RDS HOT 2
- typeorm Not Compatible with Latest Version of Mongo HOT 1
- Can not generate migrations with capacitor driver: "Cannot use import statement outside a module"d HOT 1
- No metadata for "book" was found.
- Cascade save on 1 to 1 relations HOT 1
- Switching to esnext - fields not part of "select" are returned with "undefined"
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 typeorm.