forked from typeorm/javascript-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
48 lines (41 loc) · 1.21 KB
/
index.js
File metadata and controls
48 lines (41 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var typeorm = require("typeorm");
var EntitySchema = typeorm.EntitySchema;
typeorm.createConnection({
type: "mysql",
host: "localhost",
port: 3306,
username: "test",
password: "test",
database: "test",
synchronize: true,
entities: [
new EntitySchema(require("./entity/Post")),
new EntitySchema(require("./entity/Category")),
]
}).then(function (connection) {
var category1 = {
name: "TypeScript"
};
var category2 = {
name: "Programming"
};
var post = {
title: "Control flow based type analysis",
text: "TypeScript 2.0 implements a control flow-based type analysis for local variables and parameters.",
categories: [
category1, category2
]
};
var postRepository = connection.getRepository("Post");
postRepository.save(post)
.then(function(savedPost) {
console.log("Post has been saved: ", savedPost);
console.log("Now lets load all posts: ");
return postRepository.find();
})
.then(function(allPosts) {
console.log("All posts: ", allPosts);
});
}).catch(function(error) {
console.log("Error: ", error);
});