@databases lets you read and write data to Postgres, MySQL, SQLite and other databases in Node.js using ordinary SQL, with parameters automatically escaped to prevent SQL injection.
100% free and open source
await tables.users(db).insert({
email: `[email protected]`,
active: true,
});
active | ||
---|---|---|
[email protected] | true | |
[email protected] | true | |
[email protected] | true | |
+ | [email protected] | true |
await tables.users(db).update(
{email: `[email protected]`},
{active: false},
);
active | ||
---|---|---|
[email protected] | true | |
[email protected] | true | |
⇄ | [email protected] | false |
[email protected] | true |
await tables.users(db).delete({
email: `[email protected]`,
});
active | ||
---|---|---|
[email protected] | true | |
- | [email protected] | true |
[email protected] | false | |
[email protected] | true |
await tables.users(db)
.find({
email: anyOf([
`[email protected]`,
`[email protected]`,
]),
})
.all();
active | ||
---|---|---|
· | [email protected] | true |
[email protected] | false | |
· | [email protected] | true |
await db.query(sql`
SELECT
users.email,
count(*) AS posts
FROM users
INNER JOIN posts
ON (users.email = posts.author)
GROUP BY users.email
WHERE users.active = true
`);
posts | ||
---|---|---|
[email protected] | 4 | |
[email protected] | 16 |
await db.tx(async (db) => {
await tables.users(db).update(
{email: `[email protected]`},
{active: true},
);
return await db.query(sql`
SELECT
users.email,
count(*) AS posts
FROM users
INNER JOIN posts
ON (users.email = posts.author)
GROUP BY users.email
WHERE users.active = true
`);
});
posts | ||
---|---|---|
[email protected] | 4 | |
[email protected] | 3 | |
[email protected] | 16 |
Type Safe
Modular
Promises