-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5 Start to work on TypeORM integration
- Loading branch information
jonatansalas
committed
Jul 1, 2017
1 parent
c63142a
commit 9b3b83b
Showing
8 changed files
with
401 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import {Connection, createConnection} from "typeorm"; | ||
|
||
import Logger from './helper/logger'; | ||
|
||
export default class Database { | ||
public static async init(): Promise<Connection> { | ||
try { | ||
Logger.info(`Creating db connection`); | ||
|
||
return await createConnection({ | ||
driver: { | ||
type: 'postgres', | ||
host: process.env.POSTGRES_HOST, | ||
port: process.env.POSTGRES_PORT, | ||
username: process.env.POSTGRES_USER, | ||
password: process.env.POSTGRES_PASSWORD, | ||
database: process.env.POSTGRES_DB, | ||
}, | ||
entities: [ | ||
__dirname + "/model/*.ts", | ||
], | ||
autoSchemaSync: true, | ||
}); | ||
} catch (error) { | ||
Logger.info(`Something went wrong when creating connection -> ${error}`); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,18 @@ | ||
export default class User { | ||
public id: string; | ||
import {Entity} from "typeorm/decorator/entity/Entity"; | ||
import {Column, PrimaryGeneratedColumn} from "typeorm"; | ||
|
||
@Entity() | ||
export class User { | ||
|
||
@PrimaryGeneratedColumn() | ||
public id: number; | ||
|
||
@Column() | ||
public age: string; | ||
|
||
@Column() | ||
public name: string; | ||
|
||
@Column() | ||
public lastName: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.