Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
@ff00ff/mammoth
Advanced tools
> This is `mammoth@next` which just had a major revamp. I'm about to publish a blog post with some more info. This will move to master soon.
This is
mammoth@next
which just had a major revamp. I'm about to publish a blog post with some more info. This will move to master soon.
npm i @ff00ff/mammoth@1.0.0-rc.1
Mammoth is a type-safe query builder. It only supports Postgres which we consider a feature. It's syntax is as close to SQL as possible so you already know how to use it. It's autocomplete features are great. It helps you avoid mistakes so you can develop applications faster.
const rows = await db
.select(foo.id, bar.name)
.from(foo)
.leftJoin(bar)
.on(foo.barId.eq(bar.id))
.where(foo.id.eq(`1`));
The above query produces the following SQL:
SELECT
foo.id,
bar.name
FROM foo
LEFT JOIN bar ON (foo.bar_id = bar.id)
WHERE
foo.id = $1
More importantly, the resulting type of rows is { id: string; name: string | undefined }[]
. Notice how the name is automatically nullable because of the left join.
const updateCount = await db.update(foo).set({ name: `Test` }).where(foo.value.gt(0));
UPDATE foo
SET
name = $1
WHERE
value > $2
const rows = await db
.insertInto(foo)
.values({
name: `Test`,
value: 123,
})
.returning(`id`);
INSERT INTO foo (
name,
value
) VALUES (
$1,
$2
)
RETURNING
id
const affectedCount = await db
.insertInto(foo, ['name'])
.select(bar.name)
.from(bar)
.where(bar.name.isNotNull());
Mammoth is a query builder pur sang so it doesn't include a database driver. You need to create a db and pass a callback to execute the query.
import { defineDb } from '@ff00ff/mammoth';
const db = defineDb(async (query, parameters) => {
const result = await pool.query(query, parameters);
return {
affectedRowCount: result.rowCount,
rows: result.rows,
};
});
To
const foo = defineTable(`foo`, {
id: uuid().primaryKey().default(`gen_random_id()`),
createDate: timestampWithTimeZone().notNull().default(`now()`),
name: text().notNull(),
value: integer(),
});
You should keep your column names camelCase in the defineTable call as they are automatically transformed to train_case throughout Mammoth.
Below is a list of clauses per query and a short description on what we Mammoth supports.
Function | SQL data type |
---|---|
binary() | BYTEA |
blob() | BYTEA |
bytea() | BYTEA |
caseInsensitiveText() | CITEXT |
citext() | CITEXT |
date() | DATE |
decimal() | DECIMAL |
integer() | INTEGER |
interval() | INTERVAL |
jsonb<T>() | JSONB |
json<T>() | JSON |
money() | MONEY |
number() | IntegerColumn |
serial() | SERIAL |
string() | TextColumn |
text() | TEXT |
text<T>() | TEXT |
time() | TIME |
timestamp() | TIMESTAMP |
timestampWithoutTimeZone() | TIMESTAMP WITHOUT TIME ZONE |
timestampWithTimeZone() | TIMESTAMP WITH TIME ZONE |
timeWithoutTimeZone() | TIME WITHOUT TIME ZONE |
timeWithTimeZone() | TIME WITH TIME ZONE |
uuid() | UUID |
Once you clone the repo, do a npm install
you should be able to run npm test
seeing everything turn green. Feel free to pick up one of the open issues — in particular you can pick up one labeled with "good first issue". Be sure to claim the issue before you start so we avoid two or more people working on the same thing.
FAQs
![Mammoth](https://s3-eu-west-1.amazonaws.com/mammoth-static.ff00ff.nl/mammoth-logo.png)
The npm package @ff00ff/mammoth receives a total of 68 weekly downloads. As such, @ff00ff/mammoth popularity was classified as not popular.
We found that @ff00ff/mammoth demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.