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

modli-postgres

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

modli-postgres

Modli adapter for PostgreSQL

  • 3.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
2
Weekly downloads
 
Created
Source

Modli - PostgreSQL Adapter

This module provides adapter for the PostgreSQL datasource for integration with Modli.

Installation

npm install modli-postgres --save

Config and Usage

When defining a property which will utilize the adapter it is required that a tableName be supplied:

const { model, adapter, obey, use } = require('modli')
const postgres = require('modli-postgres')

model.add({
  name: 'foo',
  version: 1,
  tableName: 'tblFoo'
  schema: obey.model({
    id: { type: 'number' },
    fname: { type: 'string', min: 3, max: 30 },
    lname: { type: 'string', min: 3, max: 30 },
    email: { type: 'email', min: 3, max: 254, required: true }
  })
})

Then add the adapter as per usual with the following config object structure:

adapter.add({
  name: 'postgresFoo',
  source: postgres
  config: {
    host: {HOST_IP},
    user: {USERNAME},
    password: {PASSWORD},
    database: {DATABASE}
  }
})

You can then use the adapter with a model via:

// Use(MODEL, ADAPTER)
const postgresTest = use('foo', 'postgresFoo')

Methods

The following methods exist natively on the PostgreSQL adapter:

query

Allows for passing standard PostgreSQL queries:

postgresTest.query('SELECT * FROM tblFoo')
  .then(/*...*/)
  .catch(/*...*/)

createTable

Creates (IF NOT EXISTS) a table based on params:

postgresTest.createTable({
    'id': [ 'serial', 'NOT NULL', 'PRIMARY KEY'],
    'fname': [ 'varchar(255)' ],
    'lname': [ 'varchar(255)' ],
    'email': [ 'varchar(255)' ]
  })
  .then(/*...*/)
  .catch(/*...*/)

create

Creates a new record based on object passed:

postgresTest.create({
    fname: 'John',
    lname: 'Smith',
    email: 'jsmith@gmail.com'
  })
  .then(/*...*/)
  .catch(/*...*/)

read

Runs a SELECT with optional WHERE:

postgresTest.read('fname=\'John\'')
  .then(/*...*/)
  .catch(/*...*/)

update

Updates record(s) based on query and body:

postgresTest.update('fname=\'John\'', {
    fname: 'Bob',
    email: 'bsmith@gmail.com'
  })
  .then(/*...*/)
  .catch(/*...*/)

delete

Deletes record(s) based on query:

postgresTest.delete('fname=\'Bob\'')
  .then(/*...*/)
  .catch(/*...*/)

extend

Extends the adapter to allow for custom methods:

postgresTest.extend('myMethod', () => {
  /*...*/
})

Development

The PostgreSQL adapter requires the following environment variables to be set for running the tests. These should be associated with the PostgreSQL instance running locally.

MODLI_POSTGRES_HOST,
MODLI_POSTGRES_USERNAME,
MODLI_POSTGRES_PASSWORD,
MODLI_POSTGRES_DATABASE

This repository includes a base container config for running locally which is located in the /docker directory.

License

Modli-Postgres is licensed under the MIT license. Please see LICENSE.txt for full details.

Credits

Modli-Postgres was designed and created at TechnologyAdvice.

Keywords

FAQs

Package last updated on 05 Oct 2017

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