Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const mysql = require('mysql');
- const connection = mysql.createConnection({
- host:'localhost',
- user: 'root',
- password:'qweasdzxc',
- database: 'testdb',
- });
- const tableName = 'customers';
- connection.connect();
- /*==========METHODS==========*/
- //TODO
- const config = (function (){
- let from;
- let where,orderBy;
- });
- const getLimitObjects = function(table, number){
- const sqlText = `SELECT * FROM ${table} LIMIT ${number}`;
- connection.query(sqlText,(err,result)=>{
- if(err){
- throw err;
- }
- console.log(result);
- })
- };
- const getAllObjects = function(table,config){
- const sqlText = `SELECT * FROM ${table}`;
- connection.query(sqlText,(err,result)=>{
- if(err){
- throw err;
- }
- console.log(result);
- })
- };
- const dropTable = function(table){
- const sqText = `DROP TABLE ${table}`;
- connection.query(sql,(err,res)=>{
- if(err){
- throw err;
- }
- console.log(`Table ${table} was deleted`);
- });
- };
- const updateTable = function(table,config){
- const sqlText = `UPDATE ${table} SET address = 'Canyon 123' WHERE address = 'Valley 345'`; //config here;
- //TODO
- connection.query(sqlText,(err,res)=>{
- if(err){
- throw err;
- }
- console.log(`${res.affectedRows} records updated`);
- });
- };
- /*==========TESTING==========*/
- getLimitObjects(tableName,3);
- updateTable(tableName,null);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement