- About
- Install
- Run script
- Example of .env File
- Example JSON List file
- Error Codes
- License
- Contributing
- Author
This project is a script for execute massive queries to SQL database server. The queries are read from a JSON List file.
This script is useful for execute massive queries to a database server and not worry about the number of queries.
The script will execute the queries in the JSON List file and if some statement fails, the script will generate a file named {JSON_LIST_FILE_NAME}_errors.json
with the failed statements.
This project uses Node.js and npm as package manager, so you need to install it first.
After that, you can install the project dependencies with the following command:
npm install
First of all, you need to create a .env
file in the root of the project with the following parameters:
# File to be used as input for the script (Must be a JSON List)
# * Use relative path. ("data.json")
# * JSON File must be in project folder
# * for use absolute path use: abs:<ABSOLUTE_PATH> (Example: "abs:/home/user/data.json")
JSON_LIST_FILE_NAME=""
# Database connection parameters
DB_HOST=""
DB_PORT=""
DB_USER=""
DB_PASSWORD=""
DB_NAME=""
The JSON_LIST_FILE_NAME
parameter is the path to the JSON List file.
You can use relative path or absolute path.
- Relative path:
data.json
- Absolute path:
abs:/home/user/data.json
The DB_HOST
, DB_PORT
, DB_USER
, DB_PASSWORD
and DB_NAME
parameters are the connection parameters to the database server.
And then, you can run the script with the following command:
npm run execute
If some statement fails, the script will generate a file named {JSON_LIST_FILE_NAME}_errors.json
.
[
"INSERT INTO users ( id, username, password ) VALUES ( '1' , 'admin' , 'admin' );",
"INSERT INTO users ( id, username, password ) VALUES ( '2' , 'user' , 'user' );",
"INSERT INTO users ( id, username, password ) VALUES ( '3' , 'guest' , 'guest' );",
"INSERT INTO users ( id, username, password ) VALUES ( '4' , 'test' , 'test' );"
]
Code | Description |
---|---|
0 | No errors |
1 | Some statements failed, written errors to file |
2 | Missing .env file |
3 | Missing JSON_LIST_FILE_NAME in .env |
4 | Error in SQL Connection |
5 | Cannot read input file |
6 | Cannot write error file |
This project is licensed under the terms of the free and open-source MIT license.
If you have any idea to improve this project, feel free to open an issue or a pull request.
This project was made with love by Alejandro Fandos.