Skip to Content
Learning TypeScript 2.x - Second Edition
book

Learning TypeScript 2.x - Second Edition

by Remo H. Jansen
April 2018
Beginner content levelBeginner
536 pages
13h 21m
English
Packt Publishing
Content preview from Learning TypeScript 2.x - Second Edition

Database

In our repository, we have used the getConnection function from TypeORM. Before we can invoke this function, we need to ensure that a connection has been created. The following function is used later to create a database connection:

import { createConnection } from "typeorm"; import { Movie } from "./entities/movie"; export async function getDbConnection() { const DATABASE_HOST = process.env.DATABASE_HOST || "localhost"; const DATABASE_USER = process.env.DATABASE_USER || ""; const DATABASE_PORT = 5432; const DATABASE_PASSWORD = process.env.DATABASE_PASSWORD || ""; const DATABASE_DB = "demo"; const entities = [ Movie ]; const conn = await createConnection({ type: "postgres", host: DATABASE_HOST, port: DATABASE_PORT, username: DATABASE_USER, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering TypeScript - Fourth Edition

Mastering TypeScript - Fourth Edition

Nathan Rozentals
Learning TypeScript

Learning TypeScript

Josh Goldberg
TypeScript for Beginners

TypeScript for Beginners

Bharath Thippireddy

Publisher Resources

ISBN: 9781788391474Supplemental Content