hash_ Posted June 7, 2021 Posted June 7, 2021 Hello I'm fairly new to RAGEMP development using JS So i have this function sql.js : module.exports = function SQLQuery(player,sql,returning = 0) { connection.query(sql, function (err,result) { if (err) { console.log('[SQL-ERROR] : ' + err); throw err; } else //do stuff if(returning != 0) return result; }); } //or exporting using this >> module.exports.SQLQuery = SQLQuery(); im trying to read the "results" I've returned from the SQLQuery function in my LoginReg.JS file which looks like this : const sql = require("./mysql.js")(); function SocialClubCheck(player,clubid) { var exists = sql.SQLQuery(player,`SELECT COUNT * FROM accounts WHERE rockstar_id = ${clubid}`,1); if(exists[0] != 0 ) console.log(`account with ${clubid} FOUND! `); else console.log(`account with ${clubid} NOT FOUND! `); } but i don't think I'm doing it the right way i keep getting this error : TypeError: Cannot read property 'SQLQuery' of undefined var exists = sql.SQLQuery(player,`SELECT COUNT * FROM accounts WHERE rockstar_id = ${clubid}`,1); i would like any kind of hints of what am i doing wrong here Thanks
spaghetti_man Posted July 24, 2021 Posted July 24, 2021 (edited) You have it wrong here. You are trying to access the property of `sql`, whereas you are exporting a function as a complete module.export object, what you need to do is call your sql const with the parameters you've provided up. So it will be var exists = sql(player,`SELECT COUNT * FROM accounts WHERE rockstar_id = ${clubid}`,1); If you want to export a function attached to the module.exports object, you need to link it through module.exports.sqlQuery = function sqlQuery()... Edited July 24, 2021 by spaghetti_man
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now