
Security News
Open Source Maintainers Demand Ability to Block Copilot-Generated Issues and PRs
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.
sails-hook-fireline
Advanced tools
Sails.js hook to use sequelize ORM. It's like Waterline but so much hotter. (Also, exclusive to SQL DB's)
Install this hook with:
$ npm install sails-hook-fireline bluebird sequelize --save
As you can see, you have to install bluebird
and sequelize
independently and add them as dependencies. This allows you to better control you ORM versions, as this hook is somewhat version agnostic.
Bluebird is needed for transactions to work correctly. Please, refer to the official Sequelize docs linked above for more info about patching Bluebird (done inside this hook).
This hook supports versions 4 and 5.0-beta currently.
Modify .sailsrc
to resemble the next file:
{
"hooks": {
"orm": false,
"pubsub": false
}
}
To make a connection, configure sails like so
//sails.config.connections or sails.config.datastores
module.exports.connections = {
somePostgresqlServer: {
//You can pass an URI connection string. Be aware that this takes precedence
//uri: 'postgresql://user:password@host:port/database',
user: 'postgres',
password: '',
database: 'sequelize',
//Thisi s a typical Sequelize constructor `options` object
options: {
dialect: 'postgres',
host : 'localhost',
port : 5432,
logging: console.log //Why not? Just ship it like this to production. No biggie.
}
}
}
module.exports.models = {
//You can also use sails.config.models.datastore
connection: "somePostgresqlServer",
migrate: "drop", // 'alter' and 'safe' are also options
}
An example of model configuration on models/user.js
module.exports = {
attributes: {
name: {
type: Sequelize.STRING,
allowNull: false
},
age: {
type: Sequelize.INTEGER
}
},
associations: function() {
user.hasMany(image, {
foreignKey: {
name: 'owner',
allowNull: false
}
});
},
options: {
tableName: 'user',
classMethods: {},
instanceMethods: {},
hooks: {}
}
};
Sequelize
or sails.Sequelize
as the constructorsequelize
or sails.Sequelize
as the instanceOp
as a shortcut to Sequelize.Op
To avoid a potential loss of an unique index when using deletedAt
(for unicity and softDelete),
an option can be passed to the model, making its default zero, avoiding such SQL halting experience.
module.exports = {
attributes: {},
associations: () => {},
options: {
classMethods: {},
instanceMethods: {},
hooks: {},
paranoidSchizophrenia: true,
}
};
It work just the same, except for some minor changes:
deletedAt
is Date(0)deletedAt
is accessed, if date is Date(0), it will return null
(custom getter)paranoid: false
, a non-default scope must be used.
This package provides the drugged
scope that has no effect over queries whatsoever for this specific purpose.
//All three are equivalent
let query = {
where: {},
paranoid: false,
};
User.scope(null).findAll(query);
User.scope('drugged').findAll(query);
User.unscoped().findAll(query);
When fireline is preparing your modelrs, you can run your own functions to alter the default behaviour.
somePostgresqlServer: {
user: 'postgres',
password: '',
database: 'sequelize',
options: {
dialect: 'postgres',
host : 'localhost',
port : 5432,
logging: console.log
},
hooks: {
myFirstHook: {
beforeDefinition: (modelDef, modelList) => {},
afterDefinition: (modelDef, modelList) => {},
beforeLoad: (modelDef, modelList) => {},
afterLoad: (modelList) => {},
beforeAssociation: (model, modelList) => {},
afterAssociation: (model, modelList) => {},
beforeDefaultScope: (model, modelList) => {},
afterDefaultScope: (model, modelList) => {},
}
}
}
The hooks to be run are:
(Refering to model loading from files, just an object is loaded)
(Sequelize define
)
(Associations are created with the association()
methods of each model)
(Default scope is added)
A big shoutout to Gergely Munkacsy for starting the base of this fork at sails-hook-sequelize
.
Also, special a special mention goes to Susana Hahn for using this hook to make awsome-factory-associator
, a module that provides a syntax for easily creating factories when unit testing.
FAQs
Sails.js hook to use sequelize ORM
The npm package sails-hook-fireline receives a total of 27 weekly downloads. As such, sails-hook-fireline popularity was classified as not popular.
We found that sails-hook-fireline demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.
Research
Security News
Malicious Koishi plugin silently exfiltrates messages with hex strings to a hardcoded QQ account, exposing secrets in chatbots across platforms.
Research
Security News
Malicious PyPI checkers validate stolen emails against TikTok and Instagram APIs, enabling targeted account attacks and dark web credential sales.