Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
moleculer-db-adapter-sequelize
Advanced tools
SQL adapter (Postgres, MySQL, SQLite & MSSQL) for Moleculer DB service
SQL adapter (Postgres, MySQL, SQLite & MSSQL) for Moleculer DB service with Sequelize.
$ npm install moleculer-db-adapter-sequelize sequelize --save
You have to install additional packages for your database server:
# For SQLite
$ npm install sqlite3 --save
# For MySQL
$ npm install mysql2 --save
# For MariaDB
$ npm install mariadb --save
# For PostgreSQL
$ npm install pg pg-hstore --save
# For MSSQL
$ npm install tedious --save
"use strict";
const { ServiceBroker } = require("moleculer");
const DbService = require("moleculer-db");
const SqlAdapter = require("moleculer-db-adapter-sequelize");
const Sequelize = require("sequelize");
const broker = new ServiceBroker();
// Create a Sequelize service for `post` entities
broker.createService({
name: "posts",
mixins: [DbService],
adapter: new SqlAdapter("sqlite://:memory:"),
model: {
name: "post",
define: {
title: Sequelize.STRING,
content: Sequelize.TEXT,
votes: Sequelize.INTEGER,
author: Sequelize.INTEGER,
status: Sequelize.BOOLEAN
},
options: {
// Options from http://docs.sequelizejs.com/manual/tutorial/models-definition.html
}
},
});
broker.start()
// Create a new post
.then(() => broker.call("posts.create", {
title: "My first post",
content: "Lorem ipsum...",
votes: 0
}))
// Get all posts
.then(() => broker.call("posts.find").then(console.log));
You can reach the sequelize
instance via this.adapter.db
. To call Raw queries:
actions: {
findHello2() {
return this.adapter.db.query("SELECT * FROM posts WHERE title = 'Hello 2' LIMIT 1")
.then(([res, metadata]) => res);
}
}
Every constructor arguments are passed to the Sequelize
constructor. Read more about Sequelize connection.
Example with connection URI
new SqlAdapter("postgres://user:pass@example.com:5432/dbname");
Example with connection options
new SqlAdapter('database', 'username', 'password', {
host: 'localhost',
dialect: /* one of 'mysql' | 'mariadb' | 'postgres' | 'mssql' */,
pool: {
max: 5,
min: 0,
idle: 10000
},
// SQLite only
storage: 'path/to/database.sqlite'
});
$ npm test
In development with watching
$ npm run ci
The project is available under the MIT license.
Copyright (c) 2016-2024 MoleculerJS
FAQs
SQL adapter (Postgres, MySQL, SQLite & MSSQL) for Moleculer DB service
The npm package moleculer-db-adapter-sequelize receives a total of 0 weekly downloads. As such, moleculer-db-adapter-sequelize popularity was classified as not popular.
We found that moleculer-db-adapter-sequelize 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
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.