This repository was archived by the owner on Apr 24, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathindex.ts
More file actions
45 lines (37 loc) · 1.3 KB
/
index.ts
File metadata and controls
45 lines (37 loc) · 1.3 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
import {createConnection} from "typeorm";
import {Author} from "./entity/Author";
import {Post} from "./entity/Post";
import {Category} from "./entity/Category";
createConnection({
type: "sqljs",
location: "test",
autoSave: true,
entities: [
Author,
Post,
Category
],
logging: ['query', 'schema'],
synchronize: true
}).then(async connection => {
document.write("Writing new post...<br>");
const category1 = new Category();
category1.name = "TypeScript";
const category2 = new Category();
category2.name = "Programming";
const author = new Author();
author.name = "Person";
const post = new Post();
post.title = "Control flow based type analysis";
post.text = `TypeScript 2.0 implements a control flow-based type analysis for local variables and parameters.`;
post.categories = [category1, category2];
post.author = author;
const postRepository = connection.getRepository(Post);
await postRepository.save(post);
document.write("<br>Post has been save:<br>");
document.write("<pre>", JSON.stringify(post, null, 2), "</pre>");
console.log("Post has been saved: ", post);
}).catch(error => {
document.write("<b>Error: ", JSON.stringify(error, null, 2), "</b>");
console.log("Error: ", error)
});