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 553 . run ` node src/app1-es5/index.js ` to run simple example of usage with ES5.
664 . run ` node src/app2-es5-json-schemas/index.js ` to run example of usage with ES5 + schemas defined in a JSON.
775 . 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 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}
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ module.exports = {
77 generated : true
88 } ,
99 name : {
10- type : "string "
10+ type : "varchar "
1111 }
1212 }
1313} ;
Original file line number Diff line number Diff 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"
Original file line number Diff line number Diff line change 11var typeorm = require ( "typeorm" ) ;
22
33typeorm . 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: " ) ;
Original file line number Diff line number Diff line change 77 "generated" : true
88 },
99 "name" : {
10- "type" : " string "
10+ "type" : " varchar "
1111 }
1212 }
1313}
Original file line number Diff line number Diff line change 77 "generated" : true
88 },
99 "title" : {
10- "type" : " string "
10+ "type" : " varchar "
1111 },
1212 "text" : {
1313 "type" : " text"
Original file line number Diff line number Diff line change 11var typeorm = require ( "typeorm" ) ;
22
33typeorm . 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: " ) ;
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 = {
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} ;
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 = {
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} ;
You can’t perform that action at this time.
0 commit comments