Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/blinet/iexpire
Adding an expiration period in the form of a count and you can also update the duration in your model and here it will automatically synchronize the new period And when this period expires, the event will be issued, this package currently supports these database systems. MongoDB How this package works: You will create a connection to the model with data that you want to create for an expiration period, and note that the package only supports milliseconds Then it will create a dummy container within the process that has a duration for each object, and it will subtract the period that you put within the option every time the session of the intervel period that you put into the option ends. I do not know my explanation is understandable or not, but this package you run only once on the model you want to create an expiration period and you do not need to create a new one every time
https://github.com/blinet/iexpire
Last synced: 10 days ago
JSON representation
Adding an expiration period in the form of a count and you can also update the duration in your model and here it will automatically synchronize the new period And when this period expires, the event will be issued, this package currently supports these database systems. MongoDB How this package works: You will create a connection to the model with data that you want to create for an expiration period, and note that the package only supports milliseconds Then it will create a dummy container within the process that has a duration for each object, and it will subtract the period that you put within the option every time the session of the intervel period that you put into the option ends. I do not know my explanation is understandable or not, but this package you run only once on the model you want to create an expiration period and you do not need to create a new one every time
- Host: GitHub
- URL: https://github.com/blinet/iexpire
- Owner: blinet
- License: apache-2.0
- Created: 2022-08-04T22:26:48.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-08-06T23:00:16.000Z (over 2 years ago)
- Last Synced: 2024-05-01T18:30:07.176Z (7 months ago)
- Language: JavaScript
- Size: 61.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# **About**
Adding an expiration period in the form of a count and you can also update the duration in your model and here it will automatically synchronize the new period
And when this period expires, the event will be issued, this package currently supports these database systems.
MongoDB
How this package works: You will create a connection to the model with data that you want to create for an expiration period, and note that the package only supports milliseconds
Then it will create a dummy container within the process that has a duration for each object, and it will subtract the period that you put within the [option](#options) every time the session of the intervel period that you put into the [option](#options) ends.I do not know my explanation is understandable or not, but this package you run only once on the model you want to create an expiration period and you do not need to create a new one every time
use [Example Test](#example) to see How does this package work- Easy to use
# **Alert**
property "\_id" must be included in the data because we use it as the container key
# **Installation**
```sh-session
npm install iexpire
yarn add iexpire
```# **How to use**
```js
const { MongoDbExpirer } = require("iexpire");
const iexpire = new MongoDbExpirer(, {});
```# **Options**
```js
{
subtract: "",// He will subtract this period and then update it each time
interval: "",//Here the Interval, when the period ends, it will subtract the number
property: "",// property for expiration that will be updated
delete: false,// If true, it will delete the document when the period ends
sync: "2s",//Here it checks if there is new data with a new id, and if it finds new data, it will create a new container for it with a different expiration period
}
```# **Example**
### **Example Test**
```js
const mongoose = require("mongoose");
const ms = require("ms");
mongoose.connect("").then(async () => {
const { MongoDbExpirer } = require("iexpire");
const mongoose = require("mongoose");
//Modal is the model that you want to create an expiration period
const Schema = new mongoose.Schema({
expiresAt: Number, //milliseconds
});
const Modal = mongoose.model("subscriptions", Schema); //Your model
const iexpire = new MongoDbExpirer(Modal, {
subtract: "1d",
interval: "1s", //This is just an example. If the expiration period is in days, it is preferable to put it "1d" instead of "1s"
property: "expiresAt",
delete: true, // If true, it will delete the document when the period ends
sync: "2s",
});
//This event if you get an error
iexpire.on("error", (data) => {
console.log(data);
});
//The data from which it was subtracted
iexpire.on("subtract", (data) => {
console.log(data);
});
//Here is the data that was deleted
iexpire.on("delete", (data) => {
console.log(data);
});
//And here it is when it expires
iexpire.on("end", (data) => {
console.log(data);
});
console.log("Connect To MongoDB Successfully");
//There is no need to use this if you are taking the process seriously {This is just an example}
Modal.create({
expiresAt: ms("30d"),
});
//
});
```### **Example Seriously**
```js
const mongoose = require("mongoose");
const ms = require("ms");
mongoose.connect("").then(async () => {
const { MongoDbExpirer } = require("iexpire");
const mongoose = require("mongoose");
//Modal is the model that you want to create an expiration period
const Schema = new mongoose.Schema({
expiresAt: Number,//milliseconds
});
const Modal = mongoose.model("subscriptions", Schema); //Your model
const iexpire = new MongoDbExpirer(Modal, {
subtract: "1d",
interval: "1d",
property: "expiresAt",
delete: true, // If true, it will delete the document when the period ends
sync: "2s",
});
//This event if you get an error
iexpire.on("error", (data) => {
console.log(data);
});
//The data from which it was subtracted
iexpire.on("subtract", (data) => {
console.log(data);
});
//Here is the data that was deleted
iexpire.on("delete", (data) => {
console.log(data);
});
//And here it is when it expires
iexpire.on("end", (data) => {
console.log(data);
});
console.log("Connect To MongoDB Successfully");
});
```## Links
- [Twiter](https://twitter.com/onlyarth)
- [Github](https://github.com/4i8)## License
- [Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0)