Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
dbq
= (node-mysql
+ async
for batch execution & flow control) / (a preference for brevity × medium naiveté).
Example: two queries, executed in parallel, two results:
db("select * from ricks order by rickness desc limit 1"
,"select * from mortys where dim=? order by mortyness desc limit 1",["c-137"]
,(rickest,mortyest)=>/*fiddle*/)
Pass a function as the last input, and that will receive query results as inputs in the order supplied:
db("select * from user where name=?",['morty']
"select name,volume from dims where dim=?",['c-137']
,(morty,dim)=>{/*fiddle*/})
If the last input isn't a function, a promise is returned, so is then
able:
db( "select * from jerrys where dim=?",["c-137"]
,"select * from ricks where dim=?",["J19ζ7"]
) .then(([jerry,doofusRick])=>{//a promise resolves to 1 value, but es6 destructuring can separate them
//fiddle
})
//if it's thenable, you can catch, too
.catch(errorHandler)
//but it's already going to log out when errors happen anyway
It can execute queries in series or parallel (assuming you have connection pooling on).
//Parallel looks like this:
db( //could also have been db.parallel or db.qp or db.q
"select * from user"
,"select * from book"
,"select * from dinosaur"
).then(([users,books,dinosaurs])=>{/*fiddle*/})
//series would be:
db.qs( //or db.series
"update cat set living=false"
,"update treaty set active=true where title='Spider Peace'"
,"insert into cat2 select * from cat where living=false"
)
node-mysql's ?-substitution syntax is also allowed adjacently, as needed:
db( "select * from grandpa where name=?",["rick"]
,"select * from council"//note no substitution needed here, so no [] is supplied
,"select * from morty where ?",[{alignment:"evil"}]
,"select * from dinosaur"
).then(fiddle)
Queries are often performed to retrieve single value results, not arrays of objects.
If you end a query with limit 1
, it will take that one result out of its result []
, returning just the row {}
.
If you also supply only one select
clause column, the result will be just that value
, not a {key:value}
.
If your credentials have information_schema
access, db.schemize()
will query it and put a representation of the database's tables and their columns at db.table
for easy referencing elsewhere in code.
Any key:value passed to the db
options object is Object.assign
ed to db
, so will overwrite defaults. Useful to create your own logging. For example, I like to add an ellipsize
option to it & the logger so I can see partial or full queries if debugging.
var mysql=require("mysql").createPool({
host:'x',user:'x',password:'x',database:'x'
,useConnectionPooling:true//allow parallel querying!
,connectionLimit:16
,connectTimeout:15*60*1000
})
,db=require("dbq")(mysql,{//pass in node-mysql initialized above, then an options {}
//option:[default]
,verbose:true// console.log queries as they happen?
,log:(query,rows,queryLine,took,db)=>{//maybe you want to customize how queries are logged
console.log(`query in ${took}s:`,query.sql)
}
})
FAQs
terse node-mysql query wrapper to ease parallel & series execution, + simple CRUD ops
The npm package dbq receives a total of 1 weekly downloads. As such, dbq popularity was classified as not popular.
We found that dbq demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.