{"id":26606937,"url":"https://github.com/zationserver/zation-service-mysql","last_synced_at":"2026-05-18T11:06:54.697Z","repository":{"id":40138773,"uuid":"169802600","full_name":"ZationServer/zation-service-mysql","owner":"ZationServer","description":"Zation service for MySql.","archived":false,"fork":false,"pushed_at":"2023-07-12T02:38:14.000Z","size":588,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-24T20:23:06.450Z","etag":null,"topics":["extension","mysql","pool","service","zation","zation-service"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ZationServer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-08T21:40:50.000Z","updated_at":"2021-12-16T00:46:55.000Z","dependencies_parsed_at":"2024-11-16T05:30:32.744Z","dependency_job_id":"edb35a63-47c1-4cf0-8a3c-be57b8d47015","html_url":"https://github.com/ZationServer/zation-service-mysql","commit_stats":{"total_commits":71,"total_committers":3,"mean_commits":"23.666666666666668","dds":"0.14084507042253525","last_synced_commit":"88f910fb4924bcf5586197ffc20a668765d1b0cb"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ZationServer/zation-service-mysql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZationServer%2Fzation-service-mysql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZationServer%2Fzation-service-mysql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZationServer%2Fzation-service-mysql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZationServer%2Fzation-service-mysql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZationServer","download_url":"https://codeload.github.com/ZationServer/zation-service-mysql/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZationServer%2Fzation-service-mysql/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265121391,"owners_count":23714503,"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":["extension","mysql","pool","service","zation","zation-service"],"created_at":"2025-03-23T22:34:21.004Z","updated_at":"2026-05-18T11:06:49.648Z","avatar_url":"https://github.com/ZationServer.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# zation-service-mysql ⚙️\n*Zation service for MySQL*\n\n\u003ch1 align=\"center\"\u003e\n  \u003c!-- Logo --\u003e\n  \u003cbr/\u003e\n  \u003ca href=\"https://zation.dev\"\u003e\n      \u003cimg src=\"https://zation.dev/img/zationWideLogoDark.svg\" alt=\"Logo Zation\" height=\"200\"/\u003e\n  \u003c/a\u003e\n  \u003cbr/\u003e\n\u003c/h1\u003e\n\n\u003ch1 align=\"center\"\u003e\n  \u003c!-- Stability --\u003e\n  \u003ca href=\"https://nodejs.org/api/documentation.html#documentation_stability_index\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/stability-stable-brightgreen.svg\" alt=\"API Stability\"/\u003e\n  \u003c/a\u003e\n  \u003c!-- TypeScript --\u003e\n  \u003ca href=\"http://typescriptlang.org\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/%3C%2F%3E-typescript-blue.svg\" alt=\"TypeScript\"/\u003e\n  \u003c/a\u003e\n  \u003c!-- Downloads --\u003e\n  \u003ca href=\"https://npmjs.org/package/zation-service-mysql\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/dm/zation-service-mysql.svg\" alt=\"Downloads\"/\u003e\n  \u003c/a\u003e\n  \u003c!-- Size --\u003e\n  \u003ca href=\"https://npmjs.org/package/zation-service-mysql\"\u003e\n      \u003cimg src=\"https://img.shields.io/bundlephobia/min/zation-service-mysql.svg\" alt=\"Size\"/\u003e\n  \u003c/a\u003e\n\u003c/h1\u003e\n\n## What is Zation-service-mysql?\n***Zation-service-mysql*** is a zation service wrapper of the npm package [mysql](https://www.npmjs.com/package/mysql) for creating connections to MySQL servers.\nThis service will automatically create connection pools with your provided instance configurations.\nAlso, it will extend the Bag with new functionality to easily access your databases.\n\n## Install\n\n```bash\n$ npm install --save zation-service-mysql\n```\n\n## Usage\nTo use this service, you have to define it in the services configuration of your zation server.\nTo do this, use the default exported function that requires an instances argument.\nIn this argument, you can define different database connection configurations linked to a name (instanceName).\nThe connection settings are the same as in the npm module [mysql](https://www.npmjs.com/package/mysql).\nIf you only want to specify one connection setting or\nyou have a primary connection setting that you will use the most it is recommended to use the default instance name for it.\nThat will make it later easier to access your connection because you don't have to provide every time the instance name.\n\n```typescript\nimport {Config}         from \"zation-server\";\nimport MySqlService     from \"zation-service-mysql\";\n\nexport default Config.servicesConfig({\n    ...MySqlService({\n        default: {\n            port: 3306,\n            database: 'MyFirstDatabase',\n            user: process.env.DB_USER,\n            password: process.env.DB_PASSWORD,\n            charset: 'utf8mb4_unicode_ci'\n        },\n        secondDb: {\n            port: 3307,\n            database: 'MySecondDatabase',\n            user: process.env.DB_SECOND_USER,\n            password: process.env.DB_SECOND_PASSWORD,\n            charset: 'utf8mb4_unicode_ci'\n        }\n    })\n});\n```\nIn this example code, the zation server will create two connection pools in the start process with the two configurations.\nAfter the launch, these two pools can be accessed by using the Bag.\n\n### Access\nTo access your connections, you can use one of these new functionalities that will be added to the Bag class.\nNotice that this service also adds the typescript definitions.\nThe new functionalities:\n\n* `getMySql` (`Function (instanceName?: string): Promise\u003cMySql.Pool\u003e`) - This function returns the MySQL service instance as a MySql.Pool,\nif it exists otherwise, it will throw a ServiceNotFoundError error.\nIt takes a instance name as an argument if you don't provide one it will use the default instance name.\n\n* `hasMySql` (`Function (instanceName?: string): boolean`) - This function returns a boolean that indicates if the MySQL service instance exists.\nIf you don't provide a instance name, it will use the default instance name.\n\n* `mySqlFormat` (`Function (query: string, inserts: any[], stringifyObjects?: boolean, timeZone?: string) =\u003e string`) - With this function, you can format mysql queries to escaping query values.\nIts the same function as the format function from the mysql npm package.\n```typescript\nconst sql = bag.mySqlFormat('SELECT * FROM posts WHERE id = ?', [42]);\nconsole.log(sql); // SELECT * FROM posts WHERE id = 42\n```\n\n* `mySqlQuery` (`Function (query: string, instanceName?: string) =\u003e Promise\u003c{ results: any, fields: MySql.FieldInfo[] }\u003e`) - With this function, you can make a simple promise based MySQL query by using one of your service instances.\nNotice that this function can throw a ServiceNotFoundError error if the MySQL service with the instance name is not found.\nThe function takes a query and the instance name as arguments.\nIf you don't provide a instance name, it will use the default instance name.\n```typescript\nconst res = await bag.mySqlQuery('SELECT * FROM user WHERE id = 1');\nif(res.results[0]) return res.results[0];\nelse throw new BackError(\"UserNotFound\");\n```\n\n## License\n\nMIT License\n\nCopyright (c) 2018 Ing. Luca Gian Scaringella\n\nThis MIT license applies only to zation-service-mysql.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzationserver%2Fzation-service-mysql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzationserver%2Fzation-service-mysql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzationserver%2Fzation-service-mysql/lists"}