Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@miroculus/sails-redis-schema
Advanced tools
Readme
A redis adapter for Sails / Waterline with basic schema and indexing support.
This adapter is intended to be used with models with very simple attributes
(only number
, boolean
, string
and json
types are supported) and to do very simple queries,
if you need something more complex you should be considering not using redis
and move to a full featured DB like MongoDB, PostgreSQL, etc.
To install this adapter, run:
npm install sails-redis-schema
Then, add the adapter to the config/datastores.js
file like this:
module.exports.datastores = {
'redis-schema': {
adapter: require('sails-redis-schema'),
url: 'redis://user:password@127.0.0.1:6379' // defaults to '127.0.0.1:6379'
}
};
You could also use the options field with any of the values listed here: https://github.com/luin/ioredis/blob/HEAD/API.md#new-redisport-host-options
module.exports.datastores = {
'redis-schema': {
adapter: require('sails-redis-schema'),
options: {
host: '192.168.1.1',
port: 5412,
db: 3,
enableOfflineQueue: false
}
}
};
More info about datastores at: https://sailsjs.com/documentation/reference/configuration/sails-config-datastores
In most cases I added easy to understand errors, but as a rule of thumb, if some functionality is not listed here is probably because is not implemented. Keep in mind that I tried to implement this adapter as minimal as possible.
First, define your model and configure it to use the redis-schema
datastore
like this:
module.exports = {
identity: 'user',
datastore: 'redis-schema',
attributes: {
id: {
type: 'string'
},
age: {
type: 'number',
defaultsTo: 18,
meta: { index: true }
},
firstName: {
type: 'string',
required: true,
meta: { index: true }
},
lastName: {
type: 'string'
}
}
}
Things to keep in mind:
type
's number
, boolean
, string
and json
are allowed.primaryKey
,
you have to index it, to do so, do the same as we did with firstName
,
and add:
meta: { index: true }
The find method only allows to query items using only 1 attribute; you won't
be able to do composed querys like: { firstName: 'Ada', age: 20 }
.
Also, don't forget to add the meta: { index: true }
to all the attributes that
you want to use to query items.
Examples:
// Correct
User.find({ id: '123123123' }) // Find users with id '123123123'
User.find({ firstName: 'Mark' }) // Find users named 'Mark'
User.find({ firstName: ['Mark', 'Ada'] }) // Find users named `Mark` or `Ada`
// Select fields
User.find({
where: { firstName: ['Mark', 'Ada'] }
select: ['firstName', 'lastName']
})
// Incorrect
User.find({ firstName: 'Mark', age: 20 }) // Throws an error
The create method works as expected. And, if you don't define an id
, we will
create one for you using nanoid
.
Examples:
const ada = await User.create({
firstName: 'Ada',
lastName: 'Lovelace',
age: 36
}).fetch()
Destroys one or multiple items, query rules apply the same as .find()
.
const deletedItems = await User.destroy({
firstName: ['Mark', 'Ada']
}).fetch()
👆 Deletes all users named "Mark" or "Ada", and, in this case we added the
.fetch()
call so it will bring back all the deleted items.
Updates one or multiple items, query rules apply the same as .find()
.
await User.update({
firstName: 'Mark',
}, {
age: 32
})
👆 Changes the age of all users named "Mark" to be 32
years old.
The same as .find()
, but returns the amount of queried items.
const marksCount = await User.count({ firstName: 'Mark' })
// `There are ${marksCount} marks.`
Visit Models & ORM in the docs for more information about using models, datastores, and adapters in your app/microservice.
To run the tests, first make sure to have a redis server running. Or start one using Docker with:
docker-compose up
And then, to execute the tests run (this will connect to the running redis on 127.0.0.1:6378
):
npm test
Or, you can use a custom redis instance setting the environment variable like this:
TEST_REDIS_URL=127.0.0.1:6379 npm test
MIT
FAQs
A redis adapter for Sails / Waterline with basic schema support
The npm package @miroculus/sails-redis-schema receives a total of 18 weekly downloads. As such, @miroculus/sails-redis-schema popularity was classified as not popular.
We found that @miroculus/sails-redis-schema demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 8 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.