Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

db-facade

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

db-facade

Thin abstraction layer for sequelize.

  • 1.1.3
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

db-facade

npm

Boiler-plate code and thin wrapper for sequelize and umzug packages.

npm i --save umzug sequelize db-facade

Connect

import path from 'path';
import { DbLayer, DbLayerFactory, DialectTypes } from 'db-facade';

(async function() {

  const dbLayer: DbLayer = DbLayerFactory.newDbLayer({
    dialectType: DialectTypes.POSTGRES,
    databaseCredentials: {
      username: 'tmp_user',
      password: 'tmp_pass',
      database: 'tmp_db'
    },
    migrationOptions: {
      migrationsPath: path.join(__dirname, 'app-migrations'),
      migrationTableName: 'app_migrations'
    }
  });

  console.info('authenticating db . . .');
  await dbLayer.authenticate();
  console.info('Success!');
  
}());

Run the Migrations

Run the umzug migrations by simply calling runMigrations().

await dbLayer.runMigrations();  

Initialize the Models

Pass an initialization function for loading up all your models.

import { Sequelize } from 'sequelize';
import User from '../models/User';

// ...

await dbLayer.initialize(async (sequelize: Sequelize) => {
  // ensure User.init is invoked in load implementation
  User.load(sequelize);
});

Models are used like normal after initialization.

import User from '../models/User';

// ...

await User.findOne({ where: { id } });

Start up a database for testing

You can use docker to stand up a new postgres db from scratch for testing with.

docker run -it --name pg-db \
    -e POSTGRES_USER=tmp_user \
    -e POSTGRES_PASSWORD=tmp_pass \
    -e POSTGRES_DB=tmp_db \
    -p 5432:5432 \
    -d \
    postgres:9.5

You can kill the container with docker kill pg-db once your done.

FAQs

Package last updated on 04 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc