TypeORM-readme-20.ts
· 702 B · TypeScript
原始檔案
import "reflect-metadata"
import { DataSource } from "typeorm"
import { Photo } from "./entity/Photo"
const AppDataSource = new DataSource({
type: "postgres",
host: "localhost",
port: 5432,
username: "root",
password: "admin",
database: "test",
entities: [Photo],
synchronize: true,
logging: false,
})
// to initialize the initial connection with the database, register all entities
// and "synchronize" database schema, call "initialize()" method of a newly created database
// once in your application bootstrap
AppDataSource.initialize()
.then(() => {
// here you can start to work with your database
})
.catch((error) => console.log(error))
1 | import "reflect-metadata" |
2 | import { DataSource } from "typeorm" |
3 | import { Photo } from "./entity/Photo" |
4 | |
5 | const AppDataSource = new DataSource({ |
6 | type: "postgres", |
7 | host: "localhost", |
8 | port: 5432, |
9 | username: "root", |
10 | password: "admin", |
11 | database: "test", |
12 | entities: [Photo], |
13 | synchronize: true, |
14 | logging: false, |
15 | }) |
16 | |
17 | // to initialize the initial connection with the database, register all entities |
18 | // and "synchronize" database schema, call "initialize()" method of a newly created database |
19 | // once in your application bootstrap |
20 | AppDataSource.initialize() |
21 | .then(() => { |
22 | // here you can start to work with your database |
23 | }) |
24 | .catch((error) => console.log(error)) |