Skip to content

Commit 61d8b8a

Browse files
author
Umed Khudoiberdiev
committed
updated all dependencies and example itself to the latest typeorm version
1 parent ba771ff commit 61d8b8a

File tree

5 files changed

+38
-39
lines changed

5 files changed

+38
-39
lines changed

ormconfig.json

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
[
2-
{
3-
"name": "default",
4-
"type": "mysql",
5-
"host": "localhost",
6-
"port": 3306,
7-
"username": "test",
8-
"password": "test",
9-
"database": "test",
10-
"autoSchemaSync": true,
11-
"entities": [
12-
"src/entity/*.js"
13-
],
14-
"subscribers": [
15-
"src/subscriber/*.js,"
16-
],
17-
"migrations": [
18-
"src/migration/*.js"
19-
],
20-
"cli": {
21-
"entitiesDir": "src/entity",
22-
"migrationsDir": "src/migration",
23-
"subscribersDir": "src/subscriber"
24-
}
1+
{
2+
"name": "default",
3+
"type": "mysql",
4+
"host": "localhost",
5+
"port": 3306,
6+
"username": "test",
7+
"password": "test",
8+
"database": "test",
9+
"synchronize": true,
10+
"logging": false,
11+
"entities": [
12+
"src/entity/*.js"
13+
],
14+
"subscribers": [
15+
"src/subscriber/*.js"
16+
],
17+
"migrations": [
18+
"src/migration/*.js"
19+
],
20+
"cli": {
21+
"entitiesDir": "src/entity",
22+
"migrationsDir": "src/migration",
23+
"subscribersDir": "src/subscriber"
2524
}
26-
]
25+
}

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@
2323
"typeorm-example"
2424
],
2525
"devDependencies": {
26-
"typescript": "^2.4.2"
26+
"typescript": "^2.1.5"
2727
},
2828
"dependencies": {
29-
"@types/node": "^8.0.19",
29+
"@types/node": "^8.0.29",
3030
"mysql": "^2.14.1",
31-
"reflect-metadata": "^0.1.9",
32-
"typeorm": "0.1.0-alpha.33"
31+
"reflect-metadata": "^0.1.10",
32+
"typeorm": "0.1.0-alpha.49"
3333
},
3434
"scripts": {
35-
"start": "tsc && node src/index.js"
35+
"start": "tsc && node src/index.js",
36+
"typeorm": "./node_modules/.bin/typeorm -v"
3637
}
3738
}

src/entity/Category.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {Entity, PrimaryColumn, Column} from "typeorm";
1+
import {Column, PrimaryGeneratedColumn, Entity} from "typeorm";
22

33
@Entity()
44
export class Category {
55

6-
@PrimaryColumn("int", { generated: true })
6+
@PrimaryGeneratedColumn()
77
id: number;
88

99
@Column()

src/entity/Post.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import {Entity, PrimaryColumn, Column, ManyToMany, JoinTable} from "typeorm";
1+
import {Column, Entity, JoinTable, ManyToMany, PrimaryGeneratedColumn} from "typeorm";
22
import {Category} from "./Category";
33

44
@Entity()
55
export class Post {
66

7-
@PrimaryColumn("int", { generated: true })
7+
@PrimaryGeneratedColumn()
88
id: number;
99

1010
@Column()
@@ -13,9 +13,7 @@ export class Post {
1313
@Column("text")
1414
text: string;
1515

16-
@ManyToMany(type => Category, {
17-
cascadeInsert: true
18-
})
16+
@ManyToMany(type => Category)
1917
@JoinTable()
2018
categories: Category[];
2119

src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@ createConnection().then(async connection => {
88

99
const category1 = new Category();
1010
category1.name = "TypeScript";
11+
await connection.manager.save(category1);
1112

1213
const category2 = new Category();
1314
category2.name = "Programming";
15+
await connection.manager.save(category2);
1416

1517
const post = new Post();
1618
post.title = "Control flow based type analysis";
1719
post.text = `TypeScript 2.0 implements a control flow-based type analysis for local variables and parameters.`;
1820
post.categories = [category1, category2];
1921

20-
const postRepository = connection.getRepository(Post);
21-
await postRepository.persist(post);
22+
await connection.manager.save(post);
2223

2324
console.log("Post has been saved: ", post);
2425

0 commit comments

Comments
 (0)