Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
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
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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.