File tree Expand file tree Collapse file tree 11 files changed +73
-77
lines changed Expand file tree Collapse file tree 11 files changed +73
-77
lines changed Original file line number Diff line number Diff line change 5
5
3 . run ` node src/app1-es5/index.js ` to run simple example of usage with ES5.
6
6
4 . run ` node src/app2-es5-json-schemas/index.js ` to run example of usage with ES5 + schemas defined in a JSON.
7
7
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 ) .
Original file line number Diff line number Diff line change 21
21
" typeorm-sample" ,
22
22
" typeorm-example"
23
23
],
24
- "devDependencies" : {
25
- "typescript" : " ^2.1.5"
26
- },
27
24
"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 "
31
28
}
32
29
}
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ module.exports = {
7
7
generated : true
8
8
} ,
9
9
name : {
10
- type : "string "
10
+ type : "varchar "
11
11
}
12
12
}
13
13
} ;
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ module.exports = {
7
7
generated : true
8
8
} ,
9
9
title : {
10
- type : "string "
10
+ type : "varchar "
11
11
} ,
12
12
text : {
13
13
type : "text"
Original file line number Diff line number Diff line change 1
1
var typeorm = require ( "typeorm" ) ;
2
2
3
3
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 ,
12
11
entitySchemas : [
13
12
require ( "./entity/Post" ) ,
14
13
require ( "./entity/Category" )
15
- ] ,
16
- autoSchemaSync : true
14
+ ]
17
15
} ) . then ( function ( connection ) {
18
16
19
17
var category1 = {
@@ -32,7 +30,7 @@ typeorm.createConnection({
32
30
} ;
33
31
34
32
var postRepository = connection . getRepository ( "Post" ) ;
35
- postRepository . persist ( post )
33
+ postRepository . save ( post )
36
34
. then ( function ( savedPost ) {
37
35
console . log ( "Post has been saved: " , savedPost ) ;
38
36
console . log ( "Now lets load all posts: " ) ;
Original file line number Diff line number Diff line change 7
7
"generated" : true
8
8
},
9
9
"name" : {
10
- "type" : " string "
10
+ "type" : " varchar "
11
11
}
12
12
}
13
13
}
Original file line number Diff line number Diff line change 7
7
"generated" : true
8
8
},
9
9
"title" : {
10
- "type" : " string "
10
+ "type" : " varchar "
11
11
},
12
12
"text" : {
13
13
"type" : " text"
Original file line number Diff line number Diff line change 1
1
var typeorm = require ( "typeorm" ) ;
2
2
3
3
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 ,
12
11
entitySchemas : [
13
12
__dirname + "/entity/*.json"
14
- ] ,
15
- autoSchemaSync : true
13
+ ]
16
14
} ) . then ( function ( connection ) {
17
15
18
16
var category1 = {
@@ -31,7 +29,7 @@ typeorm.createConnection({
31
29
} ;
32
30
33
31
var postRepository = connection . getRepository ( "Post" ) ;
34
- postRepository . persist ( post )
32
+ postRepository . save ( post )
35
33
. then ( function ( savedPost ) {
36
34
console . log ( "Post has been saved: " , savedPost ) ;
37
35
console . log ( "Now lets load all posts: " ) ;
Original file line number Diff line number Diff line change 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 = {
3
4
target : Category ,
4
5
columns : {
5
6
id : {
@@ -8,11 +9,7 @@ const CategorySchema = {
8
9
generated : true
9
10
} ,
10
11
name : {
11
- type : "string "
12
+ type : "varchar "
12
13
}
13
14
}
14
- } ;
15
-
16
- module . exports = {
17
- CategorySchema : CategorySchema
18
15
} ;
Original file line number Diff line number Diff line change 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 = {
4
5
target : Post ,
5
6
columns : {
6
7
id : {
@@ -9,22 +10,18 @@ const PostSchema = {
9
10
generated : true
10
11
} ,
11
12
title : {
12
- type : "string "
13
+ type : "varchar "
13
14
} ,
14
15
text : {
15
16
type : "text"
16
17
}
17
18
} ,
18
19
relations : {
19
20
categories : {
20
- target : Category ,
21
+ target : ( ) => Category ,
21
22
type : "many-to-many" ,
22
23
joinTable : true ,
23
24
cascadeInsert : true
24
25
}
25
26
}
26
- } ;
27
-
28
- module . exports = {
29
- PostSchema : PostSchema
30
27
} ;
You can’t perform that action at this time.
0 commit comments