@GaG Thank you for your help. Till now i found my way to manage easy csv tasks , since csv files are just text with comma for change column, and new lines for change row i can deal this on BAS by creating lists from "Read File to List" and then i can break each list item from "Parse string" with comma as separator. Then i use "Write File" for saving and i can live visualize the edited results on the csv file with a program called "Modern CSV". Thing is that on more advanced scripts i have big CSV files with a lots of rows and columns , sometimes i must to constant return to BAS the index position of partial value search terms on those files. I have found also an alternative way to manage by creating and executing a bat file with call for python for converting csv to xlsx and then i may use "module Excel" that haves all the actions im looking for, but Im wondering why BAS haves those actions only for xslx files, why not for csv also? Anyways till now im very satisfied to BAS but i might need more help in the future on this matter.
Use SQL connection file in NodeJS in other file
-
Hello I tried using SQL connection files with other files but for some reason it always gives me error or doesn't show anything. Can somebody please help me where I am going wrong or is it allowed in BAS?
Here's the code:
configmodule.exports = async function () { const mysql = require('mysql2'); // create the connection to database const connection = mysql.createConnection({ host: 'localhost', user: 'user', database: 'user' }); }Current:
await require("../mysqlconfig")(); module.exports = async function () { await (new Promise((resolve, reject) => { connection.query( 'SELECT * FROM `table` WHERE 1 LIMIT 1', function (err, results, fields) { if (err) { reject(err) return } if(results.length>0){ console.log(results) console.log(err) } else console.log("Not found") console.log(err) resolve() } ); })) } -
Nobody who knows this? Or is it not possible? @support
-
@GaG I can implement it without any problems if I don't use file but because I have to connect to the database everytime I use node it becomes redundant, I just want to make a code where I can connect from 1 file and use that file to connect wherever I want.
-
Still not sure what could be the reason, but maybe you should take a closer look at positioning "resolve()" in your code. Looks like its executed only in else condition in your code. Maybe you should firstly "resolve()" results and after that set "if" condition or go with "try" and "catch" approach.
-
@hippyzipp9 Man, just return your connection object from file import. And use it after in main file. Something like this:
const connection = await require("../mysqlconfig")();Just learn a bit more info about node.js usage.
-
@Oyasumi-Punpun Bruhh it worked, thank you so much <3
Still learning about node :)