Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@moleculer/database
Advanced tools
Advanced Database Access Service for Moleculer microservices framework
Advanced Database Access Service for Moleculer microservices framework. Use it to persist your data in a database.
This project is in work-in-progress. Be careful using it in production.
this module follows the one database per service pattern. To learn more about this design pattern and its implications check this article. For multiple entities/tables per service approach check FAQ.
npm i @moleculer/database nedb
Installing
nedb
is optional. It can be good for prototyping.
Define the service
// posts.service.js
const DbService = require("@moleculer/database").Service;
module.exports = {
name: "posts",
mixins: [
DbService({
adapter: "NeDB"
})
],
settings: {
fields: {
id: { type: "string", primaryKey: true, columnName: "_id" },
title: { type: "string", max: 255, trim: true, required: true },
content: { type: "string" },
votes: { type: "number", integer: true, min: 0, default: 0 },
status: { type: "boolean", default: true },
createdAt: { type: "number", readonly: true, onCreate: () => Date.now() },
updatedAt: { type: "number", readonly: true, onUpdate: () => Date.now() }
}
}
}
Call the actions
// sample.js
// Create a new post
let post = await broker.call("posts.create", {
title: "My first post",
content: "Content of my first post..."
});
console.log("New post:", post);
/* Results:
New post: {
id: 'Zrpjq8B1XTSywUgT',
title: 'My first post',
content: 'Content of my first post...',
votes: 0,
status: true,
createdAt: 1618065551990
}
*/
// Get all posts
let posts = await broker.call("posts.find", { sort: "-createdAt" });
console.log("Find:", posts);
// List posts with pagination
posts = await broker.call("posts.list", { page: 1, pageSize: 10 });
console.log("List:", posts);
// Get a post by ID
post = await broker.call("posts.get", { id: post.id });
console.log("Get:", post);
// Update the post
post = await broker.call("posts.update", { id: post.id, title: "Modified post" });
console.log("Updated:", post);
// Delete a user
const res = await broker.call("posts.remove", { id: post.id });
console.log("Deleted:", res);
Try it in your browser on repl.it
You can find here the documentation.
There is some benchmark with all adapters. You can find the results here.
The project is available under the MIT license.
Copyright (c) 2022 MoleculerJS
v0.1.0 (2022-10-02)
First public version.
FAQs
Advanced Database Access Service for Moleculer microservices framework
The npm package @moleculer/database receives a total of 105 weekly downloads. As such, @moleculer/database popularity was classified as not popular.
We found that @moleculer/database 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.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.