1.0.6 • Published 4 years ago
satyaminfo_mysql_crud_node v1.0.6
satyaminfo mysql crun in nodejs?
this package to create auto crud operation in node js api
Install
# with npm
npm install satyaminfo_mysql_crud_node
# with npm
npm install express mysql dotenv sequelize
Usage
Create a .env
file in the root directory of your project. Add
environment-specific variables on new lines in the form of NAME=VALUE
.
For example:
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=s1mpl3
DB_NAME=demo_db
Create a config/config.js
file in the root directory of your project.
For example:
const mysql=require('mysql');
const dotenv=require('dotenv').config();
var con={
host: process.env.DB_HOST,
user:process.env.DB_USER,
password:process.env.DB_PASSWORD,
database: process.env.DB_NAME,
dialect: "mysql",
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
}
};
var db_con=mysql.createConnection({
host: process.env.DB_HOST,
user:process.env.DB_USER,
password:process.env.DB_PASSWORD,
database: process.env.DB_NAME
});
module.exports.con=con;
module.exports.db_con=db_con;
Create a crud_request/app.js
file in the root directory of your project.
For example:
app.js file is following
const {mysqlCrudNode}=require('satyaminfo_mysql_crud_node');
const {db_con} = require('../config/config');
mysqlCrudNode({
table_name:'user',
table_fields:{
name:'STRING',
email:'STRING',
password:'TEXT',
phone:'INTEGER'
},
valid_fields:{
name:"required|min:2",
email:"email|required",
password:"required"
},con:db_con
});
$ node crud_request/app.js
Options
In this package 3 Options are there
- table_name here is your table name
- table_fields here is your table fields name list
- valid_fields here is your table fields multiple vaidation list / (default to false)