Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
modli-postgres
Advanced tools
This module provides adapter for the PostgreSQL datasource for integration with Modli.
npm install modli-postgres --save
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')
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', () => {
/*...*/
})
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.
Modli-Postgres is licensed under the MIT license. Please see LICENSE.txt
for full details.
Modli-Postgres was designed and created at TechnologyAdvice.
FAQs
Modli adapter for PostgreSQL
The npm package modli-postgres receives a total of 3 weekly downloads. As such, modli-postgres popularity was classified as not popular.
We found that modli-postgres demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.