New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

drizzle-toolbelt

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

drizzle-toolbelt - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

dist/index.d.mts

2

package.json
{
"name": "drizzle-toolbelt",
"version": "1.1.0",
"version": "1.1.1",
"description": "Set of tools for drizzle-orm.",

@@ -5,0 +5,0 @@ "scripts": {

@@ -29,4 +29,6 @@ # Drizzle Toolbelt

Takes first element from array or throws if no results.
Takes first element from array or throws if length is zero.
**With default error**
```ts

@@ -37,12 +39,26 @@ import { db } from "./db";

const firstUserOrThrowDefault = await db.select().from(users)
.then(takeFirstOrThrow);
const firstUserOrThrowDefault = await db
.select()
.from(users)
// throw inline
.then(takeFirstOrThrow());
const firstUserOrThrow = await db.select().from(users)
.then(takeFirstOrThrow("No users found"));
// or
const firstUserOrThrowCustom = await db.select().from(users)
.then(takeFirstOrThrow(new UnauthorizedError("You cannot view this page.")));
```
// prepare errors
const takeFirstOrError = takeFirstOrThrow();
const takeFirstOrUnauthorized = takeFirstOrThrow(new UnauthorizedError("You cannot view this page."));
// and pass it
const firstUserOrThrow = await db
.select()
.from(users)
.then(takeFirstOrError);
const firstUserOrUnauthorized = await db
.select()
.from(users)
.then(takeFirstOrUnauthorized);
```
### `aggregate`

@@ -58,4 +74,3 @@

const usersPosts = await db.select({
const usersWithPosts = await db.select({
id: users.id,

@@ -78,9 +93,11 @@ post: posts

id: number;
posts: {id: number, …otherPostProperties}[];
// `post` was removed
// `posts` was added as an array of `post`
posts: { id: number, …otherPostProperties }[];
}
```
### `aggregateRows`
#### Data-first
Data-first version of `aggregate` to be used stand-alone.
You may choose to pass rows in the arguments to call `aggregate` in a stand-alone way.

@@ -90,11 +107,19 @@ ```ts

import { users } from "./schema";
import { aggregateRows } from "drizzle-toolbelt";
import { aggregate } from "drizzle-toolbelt";
const usersRows = await db.select({
id: users.id,
post: posts
}).from(users)
.leftJoin(posts.id, eq(posts.author_id, users.id))
const usersCount = await db.select().from(users)
.then(aggregateRows("count"));
const usersWithPosts = aggregateRows({rows, pkey: 'id', fields: { posts: 'post.id' }});
```
## Contributing
This project is open to contributions. Feel free to open an issue or a pull request.
## License
MIT
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc