{"_id":"drizzle-toolbelt","_rev":"4-c2c6df901c565695e204df6bd997afe6","name":"drizzle-toolbelt","description":"Set of tools for drizzle-orm.","dist-tags":{"latest":"1.2.0"},"versions":{"0.0.0":{"name":"drizzle-toolbelt","version":"0.0.0","keywords":["drizzle","orm","sql","sqlite","postgres","pg","postgresql","mysql","database","db"],"author":{"name":"fredericoo"},"license":"MIT","_id":"drizzle-toolbelt@0.0.0","maintainers":[{"name":"fredericoo","email":"rincofrederico@gmail.com"}],"dist":{"shasum":"843f77df48c3c5c27a81af02799799b54fa2de10","tarball":"https://registry.npmjs.org/drizzle-toolbelt/-/drizzle-toolbelt-0.0.0.tgz","fileCount":2,"integrity":"sha512-Til+W7ZfPz90o00+fPg6CbmElYz6ISSFWeExjfkYyjsC15NRKcDa+6C3FqGAqbm+QF5s3H+XIDfVxDUdD0bDzg==","signatures":[{"sig":"MEUCIGHxYx7EwiNAsB+W9AjH0Mnzab+SuKAhH3wyZD2Cx1pQAiEA8Dvq1tsmJz3AcDzSVaSV/jMJeEkZZQ/0RJtcW5I5Tco=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2723},"main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"gitHead":"a3e5e7fd8b6cd4a3d9b769b786a418a1facd8a63","scripts":{"test":"bun test src","build":"tsup --dts --dts-resolve","check":"bunx @biomejs/biome check --apply ./src","release":"changeset publish"},"_npmUser":{"name":"fredericoo","email":"rincofrederico@gmail.com"},"_npmVersion":"10.5.0","description":"Set of tools for drizzle-orm.","directories":{},"_nodeVersion":"18.20.2","_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.2","lodash":"^4.17.21","@types/bun":"^1.1.0","typescript":"^5.4.5","type-testing":"^0.2.0","@types/lodash":"^4.17.0","@biomejs/biome":"1.7.1","@changesets/cli":"^2.27.1"},"_npmOperationalInternal":{"tmp":"tmp/drizzle-toolbelt_0.0.0_1714221090097_0.5675437181649594","host":"s3://npm-registry-packages"}},"1.0.0":{"name":"drizzle-toolbelt","version":"1.0.0","keywords":["drizzle","orm","sql","sqlite","postgres","pg","postgresql","mysql","database","db"],"author":{"name":"fredericoo"},"license":"MIT","_id":"drizzle-toolbelt@1.0.0","maintainers":[{"name":"fredericoo","email":"rincofrederico@gmail.com"}],"dist":{"shasum":"49d593ae7aa3599f15b987928694a3d4defe6cb5","tarball":"https://registry.npmjs.org/drizzle-toolbelt/-/drizzle-toolbelt-1.0.0.tgz","fileCount":2,"integrity":"sha512-HUyThPt5CFP4BGfCCqfj4H/BeKDoFMFQT4VjZfgZ4kdbNrR3KGfvwCQ6adRGDGBJRjMeiuXwZ3rb2vycY4VTmw==","signatures":[{"sig":"MEQCIF3hnmf+1xGS/NOr0kzy7KVxmluHbGwWMEeSgF0CqDmZAiB9ljOeLM5cdCuFRlIbZVt5LkyghFRgmx2AKQ9dpu+XOQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2751},"main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"gitHead":"db0c13028422a3c287414d0a1a390543870a9748","scripts":{"test":"bun test src","build":"tsup --dts --dts-resolve","check":"bunx @biomejs/biome check --apply ./src","release":"changeset publish"},"_npmUser":{"name":"fredericoo","email":"rincofrederico@gmail.com"},"_npmVersion":"10.5.0","description":"Set of tools for drizzle-orm.","directories":{},"_nodeVersion":"18.20.2","_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.2","lodash":"^4.17.21","@types/bun":"^1.1.0","typescript":"^5.4.5","type-testing":"^0.2.0","@types/lodash":"^4.17.0","@biomejs/biome":"1.7.1","@changesets/cli":"^2.27.1"},"_npmOperationalInternal":{"tmp":"tmp/drizzle-toolbelt_1.0.0_1714221549919_0.9262957332738728","host":"s3://npm-registry-packages"}},"1.1.0":{"name":"drizzle-toolbelt","version":"1.1.0","keywords":["drizzle","orm","sql","sqlite","postgres","pg","postgresql","mysql","database","db"],"author":{"name":"fredericoo"},"license":"MIT","_id":"drizzle-toolbelt@1.1.0","maintainers":[{"name":"fredericoo","email":"rincofrederico@gmail.com"}],"dist":{"shasum":"437becae610bb7c070be13426430e9a5a310317d","tarball":"https://registry.npmjs.org/drizzle-toolbelt/-/drizzle-toolbelt-1.1.0.tgz","fileCount":2,"integrity":"sha512-iyUvsk5HZBuLRpPylDcEbdvyMxXHP2OKDvDah2z6tkkPYvY1/7INr600YT8/o/w1ma7FxuRU12nbycWZ3c7rng==","signatures":[{"sig":"MEUCIQCmioJl4cpShRjv6/AR8d6dB1jufjakjiXW+NKFnwWK8wIgYiv4jG9vT8lF82xEYGNKtkzcX0oYdK5iAQ7lk8mbQkY=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2840},"main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"gitHead":"3a2925814b3301066ce548580681bd995309df83","scripts":{"test":"bun test src","build":"tsup --dts --dts-resolve","check":"bunx @biomejs/biome check --apply ./src","release":"changeset publish"},"_npmUser":{"name":"fredericoo","email":"rincofrederico@gmail.com"},"_npmVersion":"10.5.0","description":"Set of tools for drizzle-orm.","directories":{},"_nodeVersion":"18.20.2","_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.2","lodash":"^4.17.21","@types/bun":"^1.1.0","typescript":"^5.4.5","type-testing":"^0.2.0","@types/lodash":"^4.17.0","@biomejs/biome":"1.7.1","@changesets/cli":"^2.27.1"},"_npmOperationalInternal":{"tmp":"tmp/drizzle-toolbelt_1.1.0_1714235607489_0.931031516019488","host":"s3://npm-registry-packages"}},"1.1.1":{"name":"drizzle-toolbelt","version":"1.1.1","keywords":["drizzle","orm","sql","sqlite","postgres","pg","postgresql","mysql","database","db"],"author":{"name":"fredericoo"},"license":"MIT","_id":"drizzle-toolbelt@1.1.1","maintainers":[{"name":"fredericoo","email":"rincofrederico@gmail.com"}],"dist":{"shasum":"4aecf50b656af9afdb43edce03817b14eff49584","tarball":"https://registry.npmjs.org/drizzle-toolbelt/-/drizzle-toolbelt-1.1.1.tgz","fileCount":8,"integrity":"sha512-IpvUtaO5aPLT+LqvJUNGUnXalruMpvjJixCYiIcEMe6pxqhYSGC5mu3y7+1VlhhjOnx6g/XA+GEdstBDqTA3WA==","signatures":[{"sig":"MEQCIF2vhgvfmon8Sq0Dl2RfsP7iC1pt6A8ATF8oc4NAQ80qAiAS2mwQNKxSe9N1BALjElPslSQX7QowDsgJejHGFcM7bQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":150477},"main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"gitHead":"f081bbf5be9f1dd362e7fdbe70cd8463ea2cd1b7","scripts":{"test":"bun test src","build":"tsup --dts --dts-resolve","check":"bunx @biomejs/biome check --apply ./src","release":"changeset publish"},"_npmUser":{"name":"fredericoo","email":"rincofrederico@gmail.com"},"_npmVersion":"10.5.0","description":"Set of tools for drizzle-orm.","directories":{},"_nodeVersion":"18.20.2","_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.2","lodash":"^4.17.21","@types/bun":"^1.1.0","typescript":"^5.4.5","type-testing":"^0.2.0","@types/lodash":"^4.17.0","@biomejs/biome":"1.7.1","@changesets/cli":"^2.27.1"},"_npmOperationalInternal":{"tmp":"tmp/drizzle-toolbelt_1.1.1_1714406153545_0.32580155795700216","host":"s3://npm-registry-packages"}},"1.2.0":{"name":"drizzle-toolbelt","version":"1.2.0","description":"Set of tools for drizzle-orm.","scripts":{"build":"tsup --dts --dts-resolve","test":"bun test src","check":"bunx @biomejs/biome check --apply ./src","release":"changeset publish"},"keywords":["drizzle","orm","sql","sqlite","postgres","pg","postgresql","mysql","database","db"],"author":{"name":"fredericoo"},"main":"dist/index.js","types":"dist/index.d.ts","license":"MIT","exports":{".":{"require":"./dist/index.js","import":"./dist/index.mjs","types":"./dist/index.d.ts"}},"devDependencies":{"@biomejs/biome":"1.7.1","@changesets/cli":"^2.27.1","@types/bun":"^1.1.0","@types/lodash":"^4.17.0","lodash":"^4.17.21","tsup":"^8.0.2","type-testing":"^0.2.0","typescript":"^5.4.5"},"_id":"drizzle-toolbelt@1.2.0","gitHead":"3605cc510a45f324b74a37b4d810a09306b88082","_nodeVersion":"18.20.3","_npmVersion":"10.7.0","dist":{"integrity":"sha512-rSDoRE95PFcx1pTCXzVJECXUGZWzXToPUZgTxwL08AIEGtRiiSi0twg43RxJu/DV6NJpC+ZRlXqB1Ty7kUeHiQ==","shasum":"9294ffd91e4de720943d6890cea11615d4b666b8","tarball":"https://registry.npmjs.org/drizzle-toolbelt/-/drizzle-toolbelt-1.2.0.tgz","fileCount":8,"unpackedSize":155401,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDV2AuH6YOMNxVl9MytWFXU2y0I8hnFeWGu7tQxF49CzAiAF4wU2JYGN50QrtJbxmImPU2+xA87+oe5bIeJZ8b3eCg=="}]},"_npmUser":{"name":"fredericoo","email":"rincofrederico@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/drizzle-toolbelt_1.2.0_1719765293599_0.2692386520706711"},"_hasShrinkwrap":false}},"time":{"created":"2024-04-27T12:31:29.989Z","modified":"2024-06-30T16:34:54.004Z","0.0.0":"2024-04-27T12:31:30.275Z","1.0.0":"2024-04-27T12:39:10.072Z","1.1.0":"2024-04-27T16:33:27.621Z","1.1.1":"2024-04-29T15:55:53.740Z","1.2.0":"2024-06-30T16:34:53.825Z"},"maintainers":[{"name":"fredericoo","email":"rincofrederico@gmail.com"}],"author":{"name":"fredericoo"},"keywords":["drizzle","orm","sql","sqlite","postgres","pg","postgresql","mysql","database","db"],"license":"MIT","readme":"# Drizzle Toolbelt\n\nSet of tools for [drizzle-orm](https://github.com/drizzle-team/drizzle-orm).\n\n## Installation\n\n```bash\nnpm i drizzle-toolbelt\n```\n\n## Usage\n\n### `takeFirst`\n\nTakes first element from array if it exists.\n\n```ts\nimport { db } from \"./db\";\nimport { users } from \"./schema\";\nimport { takeFirst } from \"drizzle-toolbelt\";\n\n\nconst firstUserOrUndefined = await db.select().from(users)\n .then(takeFirst);\n ```\n\n### `takeFirstOrThrow`\n\nTakes first element from array or throws if length is zero.\n\n**With default error**\n\n```ts\nimport { db } from \"./db\";\nimport { users } from \"./schema\";\nimport { takeFirstOrThrow } from \"drizzle-toolbelt\";\n\nconst firstUserOrThrowDefault = await db\n  .select()\n  .from(users)\n  // throw inline\n  .then(takeFirstOrThrow());\n\n// or\n\n// prepare errors\nconst takeFirstOrError = takeFirstOrThrow();\nconst takeFirstOrUnauthorized = takeFirstOrThrow(new UnauthorizedError(\"You cannot view this page.\"));\n\n// and pass it\nconst firstUserOrThrow = await db\n  .select()\n  .from(users)\n  .then(takeFirstOrError);\n\nconst firstUserOrUnauthorized = await db\n  .select()\n  .from(users)\n  .then(takeFirstOrUnauthorized);\n```\n\n### `aggregate`\n\nAggregates rows from a query.\n\nExample:\n```ts\nimport { db } from \"./db\";\nimport { users } from \"./schema\";\nimport { aggregate } from \"drizzle-toolbelt\";\n\nconst usersWithPosts = await db.select({\n  id: users.id,\n  post: posts\n}).from(users)\n.leftJoin(posts.id, eq(posts.author_id, users.id))\n.then(aggregate({ pkey: 'id', fields: { posts: 'post.id' } }));\n ```\n\nThis will:\n- group all users by their id (`pkey`)\n- remove the `post` property from the rows\n- aggregate all posts in the property `posts` (set in `fields`) by their id (`posts.id`)\n\nThe final type will be:\n\n```ts\ntype Aggregated = {\n  id: number;\n  // `post` was removed\n  // `posts` was added as an array of `post`\n  posts: { id: number, …otherPostProperties }[]; \n}\n```\n\n#### Data-first\n\nYou may choose to pass rows in the arguments to call `aggregate` in a stand-alone way.\n\n```ts\nimport { db } from \"./db\";\nimport { users } from \"./schema\";\nimport { aggregate } from \"drizzle-toolbelt\";\n\nconst usersRows = await db.select({\n  id: users.id,\n  post: posts\n}).from(users)\n.leftJoin(posts.id, eq(posts.author_id, users.id))\n\nconst usersWithPosts = aggregate({ rows, pkey: 'id', fields: { posts: 'post.id' }});\n ```\n\n## Contributing\n\nThis project is open to contributions. Feel free to open an issue or a pull request.\n\n## License\n\nMIT","readmeFilename":"readme.md"}