
Research
Security News
Malicious PyPI Package Exploits Deezer API for Coordinated Music Piracy
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
@janiscommerce/model
Advanced tools
[](https://travis-ci.org/janis-commerce/model) [](https://coveralls.io/github/ja
npm install @janiscommerce/model
The session injection is useful when you have a dedicated database per client.
Using the public setter session
, the session will be stored in the controller
instance.
All the controllers and models getted using that controller will have the session injected.
The Model
uses Database Dispatcher for getting the correct DBDriver for a Model
.
The DBDriver will perform all the queries to the database.
If you have the connection settings you should add a databaseKey
getter in you Model
.
class MyModel extends Model {
get databaseKey() {
return 'core';
}
}
Database Dispatcher will try to use one of the following settings
Using Settings, with settings in file /path/to/root/.janiscommercerc.json
:
{
"database": {
"core": {
"host": "http://my-host-name.org",
"type": "mysql",
// ...
}
}
}
When your Model
is a Client Model, and the database connection settings are in the injected session, you don't need to configurate the databaseKey
.
You can add database connection settings by adding the field names from the received client that contains the settings, with the setting what will be passed to the DBDriver. Also you can add config for read/write databases.
Example of settings:
// .janiscommercerc.json
{
"databaseWriteType" : "someDBDriver",
"databaseReadType": "someOtherDBDriver",
"clients": {
"database": {
"fields": {
"databaseKey": "core",
"table": "clients",
"identifierField": "code",
"read": {
"dbReadHost" : "host",
"dbReadProtocol" : "protocol",
"dbReadPort" : "port",
"elasticSearchPrefix" : "name",
"elasticSearchAws" : "awsCredentials"
},
"write": {
"dbWriteHost" : "host",
"dbWriteProtocol" : "protocol",
"dbWriteDatabase" : "database",
"dbWriteUser" : "user",
"dbWritePassword" : "password",
"dbWritePort" : "port"
}
}
}
}
}
/*
Received client:
{
"name": "someclient",
"dbReadHost": "http://localhost",
"dbReadPort": 27017,
"elasticSearchPrefix": "someclient",
"elasticSearchAws": true
}
Database connection settings:
{
"host": "http://localhost",
"port": 27017,
"prefix": "someclient",
"awsCredentials": true
}
*/
const items = await myModel.get({ filters: { status: 'active' } });
await myModel.getPaged({ filters: { status: 'active' } }, (items, page, limit) => {
// items is an array with the result from DB
});
get()
sometimes you need data of totals. This method returns an object with that information.
Result object structure:
pages: The total pages for the filters applied
page: The current page
limit: The limit applied in get
total: The total number of items in DB for the applied filters
await myModel.get({ filters: { status: 'active' } });
const totals = await myModel.getTotals();
/**
totals content:
{
pages: 3,
page: 1,
limit: 500,
total: 1450
}
*/
const uniqueValues = await myModel.distinct('status');
const uniqueValues = await myModel.distinct('status', {
filters: {
type: 'some-type'
}
});
await myModel.insert({ foo: 'bar' });
const items = await myModel.get({ filters: { foo: 'bar' }});
/**
itemInserted content:
[
{
foo: 'bar'
}
//...
]
*/
await myModel.save({ foo: 'bar' });
const items = await myModel.get({ filters: { foo: 'bar' }});
/**
items content:
[
{
foo: 'bar'
}
//...
]
*/
filter
.await myModel.update({ updated: 1 }, { status: 5 });
// will set updated = 1 for the items that has status = 5
await myModel.remove({ foo: 'bar' });
const items = await myModel.get({ filters: { foo: 'bar' }});
/**
items content:
[]
*/
await myModel.multiInsert([{ foo: 1 }, { foo: 2 }]);
const items = await myModel.get();
/**
items content:
[
{ foo: 1 },
{ foo: 2 }
]
*/
await myModel.multiSave([{ foo: 1 }, { foo: 2 }]);
const items = await myModel.get();
/**
items content:
[
{ foo: 1 },
{ foo: 2 }
]
*/
await myModel.multiRemove({ status: 2 });
const items = await myModel.get({ filters: { status: 2 }});
/**
items content:
[]
*/
[3.3.0] - 2019-11-06
@janiscommerce/log
packagelib/utils.js
moduleFAQs
A package for managing Janis Models
The npm package @janiscommerce/model receives a total of 344 weekly downloads. As such, @janiscommerce/model popularity was classified as not popular.
We found that @janiscommerce/model demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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 uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.
Security News
Newly introduced telemetry in devenv 1.4 sparked a backlash over privacy concerns, leading to the removal of its AI-powered feature after strong community pushback.