-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathindex.js
More file actions
33 lines (24 loc) · 945 Bytes
/
index.js
File metadata and controls
33 lines (24 loc) · 945 Bytes
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
import { DataSource } from "typeorm";
import Post from "./model/Post.js";
import Category from "./model/Category.js";
const dataSource = new DataSource({
type: "better-sqlite3",
database: "app3-es6.db",
synchronize: true,
logging: false,
entities: [Post.schema, Category.schema],
});
await dataSource.initialize();
const category1 = new Category(1, "TypeScript");
const category2 = new Category(2, "Programming");
await Category.save([category1, category2]);
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];
const savedPost = await post.save();
console.log("Post has been saved: ", savedPost);
console.log("Now lets load all posts: ");
const allPosts = await Post.find({ relations: { categories: true } });
console.log("All posts: ", allPosts);