
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
@anysols/anysols-odm
Advanced tools
Anysols ODM (Object Document Mapper) is built for NodeJS and provides transparent persistence for JavaScript objects to MongoDB database
Anysols ODM (Object Document Mapper) is built for NodeJS and provides transparent persistence for JavaScript objects to MongoDB database.
Supports schemas with multi-level inheritance. Also supports interception on operations (create, read, update and delete).
npm install --save @anysols/anysols-odm
const {AnysolsODM} = require("@anysols/anysols-odm");
const anysolsODM = new AnysolsODM();
const config = {
"host": "localhost",
"port": "27017",
"database": "anysols-collection-service",
"dialect": "mongodb",
};
anysolsODM.connect(config).then(() => {
console.log('connection success');
anysolsODM.databaseExists().then(() => {
console.log('db exists');
anysolsODM.closeConnection();
}, () => {
console.log("db does not exists");
anysolsODM.closeConnection();
});
}, (err) => {
console.log('connection failed');
anysolsODM.closeConnection();
});
// after establishing connection
anysolsODM.addInterceptor({
getName: function () {
return "my-intercept";
},
intercept: (collectionName, operation, when, payload) => {
return new Promise((resolve, reject) => {
if (collectionName === 'student') {
if (operation === 'CREATE') {
console.log("[collectionName=" + collectionName + ", operation=" + operation + ", when=" + when + "]");
if (when === "BEFORE") {
for (let record of payload.records) {
console.log("computed field updated for :: " + record.get('name'));
record.set("computed", record.get("name") + " +++ computed");
}
}
}
if (operation === 'READ') {
console.log("[collectionName=" + collectionName + ", operation=" + operation + ", when=" + when + "]");
if (when === "AFTER") {
for (let record of payload.records)
console.log(JSON.stringify(record.toObject(), null, 4));
}
}
}
resolve(payload);
});
}
});
anysolsODM.defineCollection({
name: 'student',
fields: [{
name: 'name',
type: 'string'
}, {
name: 'computed',
type: 'string'
}]
});
let studentCollection = anysolsODM.collection("student");
let s = studentCollection.createNewRecord();
s.set("name", "John " + new Date().toISOString());
s.insert().then(function () {
studentCollection.find().toArray().then(function (students) {
anysolsODM.closeConnection();
});
});
// after establishing connection
anysolsODM.addFieldType({
getDataType: function (fieldDefinition) {
return new StringDataType({pattern: "(.+)@(.+){2,}\\.(.+){2,}"})
},
getType: function () {
return "email"
},
validateDefinition: function (fieldDefinition) {
return !!fieldDefinition.name
}
});
anysolsODM.defineCollection({
name: 'student',
fields: [{
name: 'name',
type: 'string'
}, {
name: 'email',
type: 'email'
}, {
name: 'dob',
type: 'date'
}]
});
let studentCollection = anysolsODM.collection("student");
let s = studentCollection.createNewRecord();
s.set("name", "John");
s.set("email", "test@example.com");
s.set("dob", new Date());
s.insert().then(function () {
console.log("Student created");
anysolsODM.closeConnection();
}, (err) => {
console.log(err);
anysolsODM.closeConnection();
});
Check the examples >> here <<
FAQs
Anysols ODM (Object Document Mapper) is built for NodeJS and provides transparent persistence for JavaScript objects to MongoDB database
We found that @anysols/anysols-odm 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
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.