
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
NodeJS module for database access built on top of commonly used database drivers
Gimlet is a NodeJS module for database access built on top of commonly used database drivers. It gives some high level validations and helper methods on top of returned rows. This is not an ORM/ODM, queries must still be made by hand (more or less..).
Gimlet is available on NPM.
npm install gimlet
Since gimlet uses other drivers you must install the ones you need separately. For mysql just do:
npm install mysql
| Driver | Package |
|---|---|
| mysql | mysql |
If you want to use another package to access the same database type, you can register the package.
const gimlet = require("gimlet");
gimlet.register("mysql2", "mysql"); // will use mysql2 package with mysql integration
gimlet.connect("mysql2://...");
const gimlet = require("gimlet");
const db = gimlet.connect("mysql://....");
db.handler().query("SELECT * FROM users", (err, users) => {
// this is where the differences from the driver appear
console.log(users);
});
When you use gimlet.connect() you get a Connection instance.
Get a context isolation for possible transactions. This call is synchronous and returns an API to access the database using the connection pool.
Query the database, just like you do with the low level driver. Returned rows should be doped with features.
Similar to query but returns only the first row of the results.
Similar to query but returns only the first column of the first row of the results.
Just a shortcut to an INSERT query. data should be an object with the properties and values you want.
Just a shortcut to a DELETE query. conditions should be an object.
Close connection.
Open connection to database. Some drivers do not connect immediately so you need to call this if you want an immediate connection. MySQL for example connects on first query.
When calling connection.query(), returned rows should be instances of Record instead of plain objects. Records usually are extended with some base plugins (and perhaps external plugins). By default, a Record will be extended with record-base, record-changes and record-freeze that will give you the methods below.
Save record modifications. You can pass a changes object with a few more changes before saving.
Remove record from database.
Returns an object with the changes detected on the record.
Returns a boolean indicating if the record has been changed or not.
To simplify the use of POINT and POLYGON database types, there are special classes to help you. Here's an example.
const Gimlet = require("gimlet");
const db = Gimlet.connect("mysql://username:password@hostname/database");
db.handler().query("INSERT INTO locations SET ?", {
name : "Aveiro, Portugal",
position : new Gimlet.types.Point(-8.653602, 40.641271),
})
Some extensions are loaded by default, you can create and load others if you need. The syntax is similar to Express and others.
const Gimlet = require("gimlet");
const db = Gimlet.connect("test://");
db.use("cache"); // use built-in cache extension
db.cease("record-freeze"); // stop using built-in record freezing
This is an extension that gives a Connection the ability to create simple asynchronous caches.
const Gimlet = require("gimlet");
const db = Gimlet.connect("mysql://username:password@hostname/database");
db.use("cache");
let userCache = db.cache((id, next) => {
db.handler().queryRow("SELECT * FROM users WHERE id = ?", [ id ], next);
});
/**
* This will not trigger 2 queries, only one. The second will queue
* and wait for the first to return (because the `id` requested is
* the same).
**/
userCache.get(1, (err, user) => {
console.log(err, user);
});
userCache.get(1, (err, user) => {
console.log(err, user);
});
This extensions is the one responsible for creating the Record.save and Record.remove methods.
This extension is the one responsible for creating the Record.changes and Record.changed methods.
This extension just freezes the object. It just calls Object.freeze. This is a special case since, if detected in the extensions list, it will be moved to the end of the load process to avoid freezing objects before all the necessary changes.
FAQs
NodeJS module for database access built on top of commonly used database drivers
We found that gimlet 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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.