{"id":13650177,"url":"https://github.com/AGenson/moleculer-mysql-template","last_synced_at":"2025-04-22T18:31:05.504Z","repository":{"id":54610793,"uuid":"123781457","full_name":"AGenson/moleculer-mysql-template","owner":"AGenson","description":"moleculer-mysql-template","archived":false,"fork":false,"pushed_at":"2018-04-29T11:54:25.000Z","size":62,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-08-03T02:03:40.200Z","etag":null,"topics":["api","microservices","moleculer","mysql"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AGenson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-04T11:19:01.000Z","updated_at":"2024-04-02T17:38:29.000Z","dependencies_parsed_at":"2022-08-13T21:30:47.670Z","dependency_job_id":null,"html_url":"https://github.com/AGenson/moleculer-mysql-template","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AGenson%2Fmoleculer-mysql-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AGenson%2Fmoleculer-mysql-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AGenson%2Fmoleculer-mysql-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AGenson%2Fmoleculer-mysql-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AGenson","download_url":"https://codeload.github.com/AGenson/moleculer-mysql-template/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223903063,"owners_count":17222484,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","microservices","moleculer","mysql"],"created_at":"2024-08-02T02:00:34.517Z","updated_at":"2024-11-10T01:30:36.047Z","avatar_url":"https://github.com/AGenson.png","language":"JavaScript","funding_links":[],"categories":["Examples"],"sub_categories":["Repositories"],"readme":"![Moleculer logo](http://moleculer.services/images/banner.png)\n\n# moleculer-mysql-template\n\nMoleculer template for creating a secure web api, with a remote MySQL database, and a default account management.\n\n**This template is based on [moleculer](https://github.com/moleculerjs/moleculer), using:**\n- [moleculer-web](https://github.com/moleculerjs/moleculer-web)\n- [moleculer-db](https://github.com/moleculerjs/moleculer-db)\n- [sequelize](https://github.com/sequelize/sequelize)\n- [mysql2](https://github.com/sidorares/node-mysql2)\n- [password-hash](https://github.com/davidwood/node-password-hash)\n- [JSON Web Token](https://github.com/auth0/node-jsonwebtoken) (JWT)\n\n# Description\n\n**This adapter overwrites the one from moleculer-db:**\n- So less functionalities\n- But some are added (like multi-table management per service).\n\nFor now the actions are very limited, but when understanding the adapter, you can change it to add your own features.\n\n**It is more an example of usage than a template, but you can :**\n- Change as you want the tables' model\n- Create your own services (just be sure to keep the configuration described in [Usage](https://github.com/AGenson/moleculer-mysql-template/wiki/Usage))\n- Change API routes to your own purpose (*cf - [moleculer-web](https://github.com/moleculerjs/moleculer-web)* for more details)\n\n**New**\n- Securing the API with an authentification process (password / tokens)\n- Create, manage or delete user accounts\n- ADMIN priviledge management\n\n---\n\n# Features\n- Remote MySQL connection\n- Simple CRUD actions\n- Fields filtering\n- Multi-table management (one service can do operations on several tables of the database)\n- Formatting answers from requests ( Responses / Errors )\n\n**New Features**\n- Authentification of http request\n- Default user account management\n- Securing of accounts with hashed password and tokens management\n\n---\n\n# Install\n``` bash\n# Clone repository\ngit clone https://github.com/AGenson/moleculer-mysql-template\n\n# Install dependencies\nnpm install\n```\n\n---\n---\n# The following is to resume functionalities\n## [-\u003e See the detailed version here](https://github.com/AGenson/moleculer-mysql-template/wiki)\n---\n---\n\n# Usage\n\n## Configure database informations:\nAll the following configuration will be in this folder : **./src/fixtures/database_template/**\n### Database Connection:\ndatabase.config.js\n```js\nmodule.exports = {\n\thost: \"mysql.example.host\",\n\tport: \"3306\", // Default for mysql =\u003e 3306\n\tdatabase: \"db_example\",\n\tusername: \"db_user\",\n\tpassword: \"db_password\"\n}\n```\n\n### Database Schema Examples: models/\nindex.js\n```js\nconst Table1Model = require(\"./Table1Model\");\nconst Table2Model = require(\"./Table2Model\");\n\n\nmodule.exports = {\n\tTable1: Table1Model,\n\tTable2: Table2Model\n};\n```\n\nTable1Model.js\n```js\nmodule.exports = {\n\tname: \"table1_elt\",\n\tdefine: {\n\t\tid: { // id must always exist\n\t\t\ttype: Sequelize.UUID, // Uses uuidv4 by default (default value is recommended)\n\t\t\tprimaryKey: true,\n\t\t\tdefaultValue: Sequelize.UUIDV4\n\t\t},\n\n\t\tfirst: {\n\t\t\ttype: Sequelize.STRING(255),\n\t\t\tallowNull: false,\n\t\t\tdefaultValue: \"Default\"\n\t\t},\n\n\t\t...\n\t},\n\toptions: {\n\t\ttimestamps: false\n\t}\n};\n```\n\n## Give service access to database\n- Change Filters to your need\n- And add the tables you want for your service\n```js\n\"use strict\";\nconst Database = require(\"../adapters/Database\");\n\n// Filters applied when searching for entities\n// Elements correspond to the columns of the table\nconst Filters_T1 = {\n\tfull: [\"id\", \"first\", \"second\", \"third\"]\n};\nconst Filters_T2 = {\n\tfull: [\"id\", \"first\", \"second\"]\n};\n\n\nmodule.exports = {\n\tname: \"service\",\n\n\tactions: { ... },\n\n\tcreated() {\n\t\tthis.DB_Table1 = new Database(\"Table1\", Filters_T1.full);\n\t\tthis.DB_Table2 = new Database(\"Table2\"); // Default: Filters_T2.full\n\t}\n\n```\n\n## Call action on wanted table\n```js\ngetAll: {\n\tparams: { },\n\thandler(ctx) {\n\t\treturn this.DB_Table1.find(ctx)\n\t}\n}\n```\n\n---\n\n# Database Management Functions\nFunctions are all detailed [HERE](https://github.com/AGenson/moleculer-mysql-template/wiki/Functions)\n## Constructor\n| Property | Type             | Default      | Description                                      |\n| :------: | :--------------: | :----------: | ------------------------------------------------ |\n| `table`  | `String`         | **required** | Name of the wanted table (defined in ./src/fixtures/database_template/models/index.js) |\n| `filter` | `Array.\u003cString\u003e` | all columns  | Default filter for search (columns of the table) |\n\n## Operations\nAll operations on a table\n* [***find***](https://github.com/AGenson/moleculer-mysql-template/wiki/find) : Find all entities by query, and filter the fileds of results\n* [***findOne***](https://github.com/AGenson/moleculer-mysql-template/wiki/findOne) : Find only one entity by query, and filter the fileds of the result\n* [***findById***](https://github.com/AGenson/moleculer-mysql-template/wiki/findById) : Find the entity with the given id, and filter the fileds of the result\n* [***count***](https://github.com/AGenson/moleculer-mysql-template/wiki/count) : Count the entities found corresponding to the given querry\n* [***insert***](https://github.com/AGenson/moleculer-mysql-template/wiki/insert) : Insert a new entity into the table of the database\n* [***insertMany***](https://github.com/AGenson/moleculer-mysql-template/wiki/insertMany) : Insert several entities into the table of the database\n* [***updateById***](https://github.com/AGenson/moleculer-mysql-template/wiki/updateById) : Update the entity with the given id\n* [***updateMany***](https://github.com/AGenson/moleculer-mysql-template/wiki/updateMany) : Update all entity corresponding to the given query\n* [***removeById***](https://github.com/AGenson/moleculer-mysql-template/wiki/removeById) : Remove the entity with the given id\n* [***removeMany***](https://github.com/AGenson/moleculer-mysql-template/wiki/removeMany) : Remove several entities with the given query\n* [***removeAll***](https://github.com/AGenson/moleculer-mysql-template/wiki/removeAll) : Remove all entities from the table\n\n---\n\n# Database Errors\n\n## Errors handling\nEach operation functions return the wanted information, with a **specific format** (name, message, data).\n\nBut they may encounters errors. And the error format is the same as for normal answers: **name, message(, data)**\n\nHere's a little description of how they are handled.\n\nSee details [HERE](https://github.com/AGenson/moleculer-mysql-template/wiki/Errors-handling)\n\n## Errors handling (from service)\nThe adapter will manage the format of the response, as described in functions or errors handling.\n\nBut you do not especially want your client to see all those formatted responses. So here is an implementation of what could be a modulable solution.\n\nSee details [HERE](https://github.com/AGenson/moleculer-mysql-template/wiki/Errors-handling-(from-service))\n\n---\n\n# User account \u0026 Priviledge Management\nDetailed description of authentification processes and user account functions.\n\n* [API Gateway](https://github.com/AGenson/moleculer-mysql-template/wiki/API-Gateway)\n* [Auth Service](https://github.com/AGenson/moleculer-mysql-template/wiki/Auth-Service)\n* [User Service](https://github.com/AGenson/moleculer-mysql-template/wiki/User-Service)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAGenson%2Fmoleculer-mysql-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAGenson%2Fmoleculer-mysql-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAGenson%2Fmoleculer-mysql-template/lists"}