How to use the moleculer-db.MemoryAdapter function in moleculer-db

To help you get started, we’ve selected a few moleculer-db examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github icebob / kantab / backend / mixins / database.js View on Github external
schema.created = function() {
		this.adapter = adapter || new MemoryAdapter();

		this.adapter.init(this.broker, this);

		this.$fields = null;

		if (_.isObject(this.settings.fields)) {
			this.$fields = _.compact(_.map(this.settings.fields, (value, name) => {
				// Disabled field
				if (value === false)
					return;

				// Shorthand format { title: true } => { title: {} }
				if (value === true)
					value = {};

				// Shorthand format: { title: "string" } => { title: { type: "string" } }
github gothinkster / moleculer-node-realworld-example-app / services / articles.service.js View on Github external
"use strict";

const { MoleculerClientError } = require("moleculer").Errors;
const { ForbiddenError } = require("moleculer-web").Errors;

const _ = require("lodash");
const slug = require("slug");
const DbService = require("moleculer-db");

module.exports = {
	name: "articles",
	mixins: [DbService],
	adapter: new DbService.MemoryAdapter({ filename: "./data/articles.db" }),

	/**
	 * Default settings
	 */
	settings: {
		fields: ["_id", "title", "slug", "description", "body", "tagList", "createdAt", "updatedAt", "favorited", "favoritesCount", "author", "comments"],

		// Populates
		populates: {
			author: {
				action: "users.get",
				params: {
					fields: ["username", "bio", "image"]
				}
			},
			comments: {
github gothinkster / moleculer-node-realworld-example-app / mixins / db.mixin.js View on Github external
return {
			mixins: [DbService],
			adapter: new MongoAdapter(process.env.MONGO_URI),
			collection
		};
	}

	// --- NeDB fallback DB adapter
	
	// Create data folder
	mkdir(path.resolve("./data"));

	return {
		mixins: [DbService],
		adapter: new DbService.MemoryAdapter({ filename: `./data/${collection}.db` })
	};
};
github gothinkster / moleculer-node-realworld-example-app / services / follows.service.js View on Github external
"use strict";

const { MoleculerClientError } = require("moleculer").Errors;
const DbService = require("moleculer-db");

module.exports = {
	name: "follows",
	mixins: [DbService],
	adapter: new DbService.MemoryAdapter({ filename: "./data/follows.db" }),

	/**
	 * Default settings
	 */
	settings: {

	},

	/**
	 * Actions
	 */
	actions: {

		/**
		 * Create a new following record
		 * 
github gothinkster / moleculer-node-realworld-example-app / services / comments.service.js View on Github external
"use strict";

const { ForbiddenError } = require("moleculer-web").Errors;
const DbService = require("moleculer-db");

module.exports = {
	name: "comments",
	mixins: [DbService],
	adapter: new DbService.MemoryAdapter({ filename: "./data/comments.db" }),

	/**
	 * Default settings
	 */
	settings: {
		fields: ["_id", "author", "article", "body", "createdAt", "updatedAt"],
		populates: {
			"author": {
				action: "users.get",
				params: {
					fields: ["_id", "username", "bio", "image"]
				}
			}
		},
		entityValidator: {
			article: { type: "string" },
github gothinkster / moleculer-node-realworld-example-app / services / favorites.service.js View on Github external
"use strict";

const { MoleculerClientError } = require("moleculer").Errors;
const DbService = require("moleculer-db");

module.exports = {
	name: "favorites",
	mixins: [DbService],
	adapter: new DbService.MemoryAdapter({ filename: "./data/favorites.db" }),

	/**
	 * Default settings
	 */
	settings: {

	},

	/**
	 * Actions
	 */
	actions: {

		/**
		 * Create a new favorite record
		 * 

moleculer-db

Moleculer service to store entities in database

MIT
Latest version published 5 months ago

Package Health Score

69 / 100
Full package analysis