Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
convergence
Advanced tools
npm install --save convergence
A practical use case says more than a 1000 words!
Lets declare an employee model, this gateway will define a typed schema and return a collection of functions to operate on the underlying store such as find, findOne, update, insert, upsert.
const {types, defineModel, engines} = require('convergence');
const store = {};
const engine = engines.memory(store);
const collection = 'employees';
const EmployeeModel = () => {
const definition = {
id: types.UUID,
name: types.STRING,
lastName: types.STRING,
job: types.JSON
};
return defineModel(Object.assign({}, {engine, collection, definition}));
};
That´s it, now we can call the model methods as we are used to.
const EmployeeModel = require('./../gateways/employee');
EmployeeModel.findOne({where: {id: 'someid'}})
.then(handleYourSuccessCase)
.catch(handleErrors);
EmployeeModel.insert({name: 'some name', lastName: 'some last name'})
.then(handleYourSuccessCase)
.catch(handleErrors);
The main feature of this Table Gateway lib is that it allows you to change the underlying
database engine seamlessly. Check this implementation.
models/employee.js
const {types, defineModel} = require('convergence');
const collection = 'employees';
const EmployeeModel = engine => {
const definition = {
id: types.UUID,
name: types.STRING,
lastName: types.STRING,
job: types.JSON
};
return defineModel(Object.assign({}, {engine, collection, definition}));
};
models/users.js
const {types, defineModel} = require('convergence');
const collection = 'users';
const UserModel = engine => {
const definition = {
id: types.UUID,
username: types.STRING,
email: types.STRING,
hashedPassword: types.STRING,
salt: types.JSON
};
return defineModel(Object.assign({}, {engine, collection, definition}));
};
Of course we don´t want to be declaring models everywhere, so we can do so in a file dedicated to it.
models/index.js
let models;
const getModels = engine => {
if (models) return models;
const UserModel = require('./users')(engine);
const EmployeeModel = require('./employees')(engine);
models = {UserModel, EmployeeModel};
return models;
};
module.exports = getModels;
We use the closure of this file to cache the models, so they will just be created once.
FAQs
## Install
We found that convergence demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 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
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.