
Research
/Security News
9 Malicious NuGet Packages Deliver Time-Delayed Destructive Payloads
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.
@apparts/db
Advanced tools
#+TITLE: @apparts/db #+DATE: [2021-03-25 Thu] #+AUTHOR: Philipp Uhl
A wrapper and query builder around the [[https://node-postgres.com/][pg]]. The API exposed by this package is meant to be usable with other database system (e.g. mongodb), too. Thus this package shall serve as an adapter between the database driver and your code.
Install:
#+BEGIN_SRC sh npm i --save @apparts/db #+END_SRC
#+BEGIN_SRC js const connect = require("@apparts/db");
const DB_CONFIG = { "use": "postgresql", "postgresql": { // pg settings "host": "localhost", "port": 5432, "user": "postgres", "pw": "password", "db": "databasename", "maxPoolSize": 5, "connectionTimeoutMillis": 0, "idleTimeoutMillis": 1000,
// Use bigint as id instead of integer
"idsAsBigInt": false,
// Should bigint be returned as number? If false, a string will be returned
"bigIntAsNumber": true,
// Use json type when finding an array, defaults to false
"arrayAsJSON": true,
// Turn on logging on error. Default: no logging
"logs": "errors",
// Also log query parameters on error. Only effective if "logs" === "errors".
"logParams": true
} };
connect(DB_CONFIG, (e, dbs) => { if(e) { // handle error throw e; } // use dbs }); #+END_SRC
** Raw SQL queries
#+BEGIN_SRC js
try {
const { rows } = await dbs.raw(
SELECT * FROM "testTable" WHERE a = $1 AND b = $2,
[1, "test"]);
// use data here
} catch (e) {
// handle error
}
#+END_SRC
** Query builder
#+BEGIN_SRC js // insert something const ids = await dbs.collection("testTable") .insert([{ number: 100 }, { number: 101 }]); // by default returns the "id" collumn // ids[0].id -> 1
// insert with custom return values const ids = await dbs.collection("testTable") .insert([{ number: 102 }, { number: 103 }], returning = ["number"]); // ids === [ { number: 102 }, { number: 103 } ]
// retrieve values const filter = { id: { op: "in", val: [2, 3] }}; // see below for everything you can stick into filter and into order const limit = 10, offset = 0, order = [{ key: "id", dir: "ASC" }]; await dbs.collection("testTable").find(filter, limit, offset, order);
// retrieve values by ids, easier await dbs.collection("testTable") .findByIds({ id: [ 2, 3 ]}, limit, offset, order);
// update values const newContent = { number: 1000 }; await dbs.collection("testTable").update(filter, newContent);
// DEPRICATED, same as update: await dbs.collection("testTable").updateOne(filter, newContent);
// delete values await dbs.collection("testTable").remove(filter);
// drop table await dbs.collection("testTable").drop();
#+END_SRC
*** Order
The order is given as an array of objects. The order is established, using the first array element. If two elements are equal according to that order, the next array element is used for ordering (and so on).
The order array takes this form:
#+BEGIN_SRC js [{ key: "", dir: "ASC" | "DESC" }, ... ] #+END_SRC
The object can contain these keys:
*** Filters
The filter is given as an object. The keys represent the column that
the filter should be applied against. The value is either a value or
an object that has op and val keys. op can be one of
**** Filter Grammar
The filter syntax is like this:
#+BEGIN_SRC js const filter = { : , ...}; // where is a key from the type and // where matcher is = | { op: , val: } | { op: , val: } | { op: "and", val: } // logical and for all subconditions | { op: "in", val: [] } // one of the values | { op: "of", path: [], value: } // match the prop of a nested JSON object | { op: "exists", val: }
= lte // less than or equals | lt // less than | gte // greater than or equals | gt // greater than = like // sql like, a string comparison where the "%" character // will be matched against anything. E.g. "bread%crumb" // matches "bread crumb" or "bread eating crumb". = | | | null = , | // nothing #+END_SRC
FAQs
Database drivers for multiple databases
The npm package @apparts/db receives a total of 4 weekly downloads. As such, @apparts/db popularity was classified as not popular.
We found that @apparts/db demonstrated a healthy version release cadence and project activity because the last version was released less than 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.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.