more readable querywrap func

This commit is contained in:
Rolands 2022-12-08 16:18:52 +02:00
parent bc86f5e391
commit 2515d90684
2 changed files with 7 additions and 2 deletions

View file

@ -17,7 +17,10 @@ await sequelize.query('INSERT INTO Users VALUES("John", 69);')
//set up the WebSocket SocioServer and give it the DB querying function that comes from whatever your DB interface lib provides.
//it needs the raw sql string, which can contain formatting parameters - insert dynamic data into the string.
//Either you in a wrapper function or your DB interface lib should do the sql validation and sanitization, as this lib does not!
const QueryWrap = async ({ id = 0, ses_id = '', sql = '', params = {} } = {}) => (await sequelize.query(sql, { logging: false, raw: true, replacements: params }))[0]
async function QueryWrap({ id = 0, ses_id = '', sql = '', params = {} } = {}) {
return (await sequelize.query(sql, { logging: false, raw: true, replacements: params }))[0]
}
const socserv = new SocioServer({ port: ws_port }, QueryWrap, {verbose:true} )
done(`Created SocioServer on port`, ws_port)

View file

@ -18,7 +18,9 @@ await sequelize.query('INSERT INTO Users VALUES("John", 69);')
//set up the WebSocket SocioServer and give it the DB querying function that comes from whatever your DB interface lib provides.
//it needs the raw sql string, which can contain formatting parameters - insert dynamic data into the string.
//Either you in a wrapper function or your DB interface lib should do the sql validation and sanitization, as this lib does not!
const QueryWrap = async ({ id = 0, ses_id = '', sql = '', params = {} } = {}) => (await sequelize.query(sql, { logging: false, raw: true, replacements: params }))[0]
async function QueryWrap({ id = 0, ses_id = '', sql = '', params = {} } = {}){
return (await sequelize.query(sql, { logging: false, raw: true, replacements: params }))[0]
}
//note that these key and iv are here for demonstration purposes and you should always generate your own. You may also supply any cipher algorithm supported by node's crypto module.
//It is always advised to load these keys from a .env file!