Skip to content

Instantly share code, notes, and snippets.

@govorov
Last active October 7, 2017 02:16
Show Gist options
  • Select an option

  • Save govorov/db95a639c9eea353116b9fb430852831 to your computer and use it in GitHub Desktop.

Select an option

Save govorov/db95a639c9eea353116b9fb430852831 to your computer and use it in GitHub Desktop.
export const databaseInitializer = async () => {
return await createConnection({
type : 'postgres',
host : '0.0.0.0',
port : 5432,
username : 'db_user',
password : 'db_password',
database : 'db_name',
entities: [
Card,
],
synchronize: true,
}).then((connection) => {
console.log('Database connection established');
// Create new instance
const card = new Card();
card.title = 'First card';
card.done = false;
// Persist to database
return connection.manager
.save(card)
.then(card => {
console.log('card saved');
})
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment