Skip to content

yagizmdemir/mysql-queries

Repository files navigation

MySQL Queries For Node.js

Functions to help SQL queries from Node.js to MySQL.

Pre-Requirements

MySQL js (https://github.com/mysqljs/mysql)

$ npm install mysql

or

$ npm install mysqljs/mysql

Dotenv (https://github.com/motdotla/dotenv)

$ npm install dotenv --save

Create .env file like or add lines to your .env file;

DB_HOST=your_db_host
DB_USER=your_db_username
DB_PASSWORD=your_db_password
DB_DATABASE=your_db_database_name

Installation

npm i node-mysql-queries

Usage

SELECT * FROM table_name

res = controller response table_name = string (table name)

selectAllSQL(res, 'table_name')

SELECT * FROM table_name WHERE column_name = value

res = controller response table_name = string (table name) columns = string array (columns name) You can use multiple column like ['col1', 'col2'] values = array (values) You can use multiple value like [1, 'val2']

selectWhereSQL(res, 'table_name', ['column_name'], [values])

INSERT INTO posts SET id = 1, title = 'Hello World'

res = controller response table_name = string (table name) value = object for example: {id: 1, title: 'Hello World'}

insertSQL(res, 'table_name', {value})

UPDATE teble_name SET col1 = val1, col2 = val2 WHERE id = 1

res = controller response table = string (table name) columns = string array (columns name) You can use multiple column like ['col1', 'col2'] values = array (values) You can use multiple value like [1, 'val2'] where = string like (id = 1)

updateSQL(res, 'table', ['columns'], [values], 'where')

DELETE FROM table_name WHERE column = value

res = controller response table_name = string (table name) column = string (column name) value = string (value)

deleteSQL(res, 'table_name', 'column', 'value')

Results

Want to contribute?

You can read and follow our CONTRIBUTING.md and report it using GitHub Issues! for reporting bugs, suggesting enhancements, bugfixes, new features and extras are welcome.

Contributors ✨

All Contributors

Thanks goes to these wonderful people (emoji key):

Yağız Mehmet Demir
Yağız Mehmet Demir

🚇 💻 🐛 📖 💡 🚧 ⚠️

This project follows the all-contributors specification. Contributions of any kind welcome!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published