https://github.com/prettyblueberry/mysql-error-keys
NPM module: a list of error keys in Mysql
https://github.com/prettyblueberry/mysql-error-keys
constants error-code error-codes error-message error-messages mysql mysql-database mysql-error npm-module npm-package
Last synced: 4 months ago
JSON representation
NPM module: a list of error keys in Mysql
- Host: GitHub
- URL: https://github.com/prettyblueberry/mysql-error-keys
- Owner: prettyblueberry
- License: mit
- Created: 2023-03-08T10:31:50.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-27T02:22:31.000Z (over 2 years ago)
- Last Synced: 2025-09-16T10:28:38.681Z (5 months ago)
- Topics: constants, error-code, error-codes, error-message, error-messages, mysql, mysql-database, mysql-error, npm-module, npm-package
- Homepage: https://www.npmjs.com/package/mysql-error-keys
- Size: 76.2 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mysql-error-keys
[](https://www.npmjs.com/package/mysql-error-keys)
[](https://www.npmjs.com/package/mysql-error-keys)
[](https://github.com/prettyblueberry/mysql-error-keys)
[](https://github.com/prettyblueberry/mysql-error-keys/issues)
[](https://github.com/prettyblueberry/mysql-error-keys/blob/main/LICENSE)
[//]: # ([](https://github.com/prettyblueberry/mysql-error-keys/fork))
A list of name keys (string, not number) of `MySQL error messages`.
MySQL has lots of error messages, and it makes you to handle many raw key strings or code numbers in your coding.
Here is an example.
```javascript
authController.signUp({name, email, pwd}).then((res)=>{
console.log("success!");
}).catch((err)=>{
if(err.response.data.code === "ER_DUP_ENTRY"){ // this is raw string :(
console.log("error: email duplicated!");
return;
}
});
```
As you can see, the code uses raw string "ER_DUP_ENTRY". It is not good for coding style and quality.
If you use this list, you can handle error keys as predefined constants to avoid bugs and for better coding style, and you can experience autocomplete of the list in editor of IDEs like `Visual Studio Code` and `JetBrains WebStorm`.
## Install
```bash
$ npm install --save mysql-error-keys
```
or
```bash
$ yarn add mysql-error-keys
```
## Usage
### Using Import
```javascript
import { mek } from 'mysql-error-keys';
authController.signUp({name, email, pwd}).then((res)=>{
console.log("success!");
}).catch((err)=>{
if(err.response.data.code === mek.ER_DUP_ENTRY){
console.log("error: email duplicated!");
return;
}
});
```
or
```javascript
import { ER_DUP_ENTRY } from 'mysql-error-keys';
authController.signUp({name, email, pwd}).then((res)=>{
console.log("success!");
}).catch((err)=>{
if(err.response.data.code === ER_DUP_ENTRY){
console.log("error: email duplicated!");
return;
}
});
```
### Using Require
```javascript
const mek = require('mysql-error-keys')
authController.signUp({name, email, pwd}).then((res)=>{
console.log("success!");
}).catch((err)=>{
if(err.response.data.code === mek.ER_DUP_ENTRY){
console.log("error: email duplicated!");
return;
}
});
```
or
```javascript
const { ER_DUP_ENTRY } = require('mysql-error-keys')
authController.signUp({name, email, pwd}).then((res)=>{
console.log("success!");
}).catch((err)=>{
if(err.response.data.code === ER_DUP_ENTRY){
console.log("error: email duplicated!");
return;
}
});
```
## Error Message Reference
[MySQL Error Message Reference](https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html)
## Please Be a Contributor !
As you know, this module always should be same as the latest version of `MySQL Error Messages`. `MySQL Error Messages` might be updated and I might miss it.
So if you find an issue, please feel free to make a **pull request** and [an issue](https://github.com/prettyblueberry/mysql-error-keys/issues/new).
GitHub Repository: [https://github.com/prettyblueberry/mysql-error-keys](https://github.com/prettyblueberry/mysql-error-keys)
## License
MIT