Skip to content

Commit 9550be2

Browse files
author
Umed Khudoiberdiev
committed
updated all dependencies, fixed es6 issues
1 parent 6a8a9f4 commit 9550be2

File tree

11 files changed

+73
-77
lines changed

11 files changed

+73
-77
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
3. run `node src/app1-es5/index.js` to run simple example of usage with ES5.
66
4. run `node src/app2-es5-json-schemas/index.js` to run example of usage with ES5 + schemas defined in a JSON.
77
5. run `node src/app3-es6/index.js` to run simple example of usage with ES6.
8+
9+
If you are looking for more advanced JavaScript example with latest ES features and Babel used see [here](https://github.com/typeorm/babel-example).

package.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@
2121
"typeorm-sample",
2222
"typeorm-example"
2323
],
24-
"devDependencies": {
25-
"typescript": "^2.1.5"
26-
},
2724
"dependencies": {
28-
"pg": "^6.1.0",
29-
"reflect-metadata": "^0.1.9",
30-
"typeorm": "0.0.8"
25+
"mysql": "^2.14.1",
26+
"reflect-metadata": "^0.1.10",
27+
"typeorm": "0.1.0-alpha.49"
3128
}
3229
}

src/app1-es5/entity/Category.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = {
77
generated: true
88
},
99
name: {
10-
type: "string"
10+
type: "varchar"
1111
}
1212
}
1313
};

src/app1-es5/entity/Post.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = {
77
generated: true
88
},
99
title: {
10-
type: "string"
10+
type: "varchar"
1111
},
1212
text: {
1313
type: "text"

src/app1-es5/index.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
var typeorm = require("typeorm");
22

33
typeorm.createConnection({
4-
driver: {
5-
type: "postgres",
6-
host: "localhost",
7-
port: 5432,
8-
username: "test",
9-
password: "admin",
10-
database: "test"
11-
},
4+
type: "mysql",
5+
host: "localhost",
6+
port: 3306,
7+
username: "test",
8+
password: "test",
9+
database: "test",
10+
synchronize: true,
1211
entitySchemas: [
1312
require("./entity/Post"),
1413
require("./entity/Category")
15-
],
16-
autoSchemaSync: true
14+
]
1715
}).then(function (connection) {
1816

1917
var category1 = {
@@ -32,7 +30,7 @@ typeorm.createConnection({
3230
};
3331

3432
var postRepository = connection.getRepository("Post");
35-
postRepository.persist(post)
33+
postRepository.save(post)
3634
.then(function(savedPost) {
3735
console.log("Post has been saved: ", savedPost);
3836
console.log("Now lets load all posts: ");

src/app2-es5-json-schemas/entity/category.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"generated": true
88
},
99
"name": {
10-
"type": "string"
10+
"type": "varchar"
1111
}
1212
}
1313
}

src/app2-es5-json-schemas/entity/post.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"generated": true
88
},
99
"title": {
10-
"type": "string"
10+
"type": "varchar"
1111
},
1212
"text": {
1313
"type": "text"

src/app2-es5-json-schemas/index.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
var typeorm = require("typeorm");
22

33
typeorm.createConnection({
4-
driver: {
5-
type: "postgres",
6-
host: "localhost",
7-
port: 5432,
8-
username: "test",
9-
password: "admin",
10-
database: "test"
11-
},
4+
type: "mysql",
5+
host: "localhost",
6+
port: 3306,
7+
username: "test",
8+
password: "test",
9+
database: "test",
10+
synchronize: true,
1211
entitySchemas: [
1312
__dirname + "/entity/*.json"
14-
],
15-
autoSchemaSync: true
13+
]
1614
}).then(function (connection) {
1715

1816
var category1 = {
@@ -31,7 +29,7 @@ typeorm.createConnection({
3129
};
3230

3331
var postRepository = connection.getRepository("Post");
34-
postRepository.persist(post)
32+
postRepository.save(post)
3533
.then(function(savedPost) {
3634
console.log("Post has been saved: ", savedPost);
3735
console.log("Now lets load all posts: ");

src/app3-es6/entity/CategorySchema.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
const Category = require("../model/Category"); // import {Category} from "../model/Category";
2-
const CategorySchema = {
1+
const Category = require("../model/Category").Category; // import {Category} from "../model/Category";
2+
3+
module.exports = {
34
target: Category,
45
columns: {
56
id: {
@@ -8,11 +9,7 @@ const CategorySchema = {
89
generated: true
910
},
1011
name: {
11-
type: "string"
12+
type: "varchar"
1213
}
1314
}
14-
};
15-
16-
module.exports = {
17-
CategorySchema: CategorySchema
1815
};

src/app3-es6/entity/PostSchema.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
const Post = require("../model/Post"); // import {Post} from "../model/Post";
2-
const Category = require("../model/Category"); // import {Category} from "../model/Category";
3-
const PostSchema = {
1+
const Post = require("../model/Post").Post; // import {Post} from "../model/Post";
2+
const Category = require("../model/Category").Category; // import {Category} from "../model/Category";
3+
4+
module.exports = {
45
target: Post,
56
columns: {
67
id: {
@@ -9,22 +10,18 @@ const PostSchema = {
910
generated: true
1011
},
1112
title: {
12-
type: "string"
13+
type: "varchar"
1314
},
1415
text: {
1516
type: "text"
1617
}
1718
},
1819
relations: {
1920
categories: {
20-
target: Category,
21+
target: () => Category,
2122
type: "many-to-many",
2223
joinTable: true,
2324
cascadeInsert: true
2425
}
2526
}
26-
};
27-
28-
module.exports = {
29-
PostSchema: PostSchema
3027
};

0 commit comments

Comments
 (0)