Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/skoshx/pentagon
Prisma-like ORM built on top of Deno KV. Allows you to write your database schemas and relations using Zod schemas, and run queries using familiar syntax from Prisma.
https://github.com/skoshx/pentagon
deno denokv orm prisma typescript
Last synced: 1 day ago
JSON representation
Prisma-like ORM built on top of Deno KV. Allows you to write your database schemas and relations using Zod schemas, and run queries using familiar syntax from Prisma.
- Host: GitHub
- URL: https://github.com/skoshx/pentagon
- Owner: skoshx
- License: mit
- Created: 2023-05-14T01:48:14.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-12-20T21:32:25.000Z (11 months ago)
- Last Synced: 2024-10-28T12:17:20.072Z (13 days ago)
- Topics: deno, denokv, orm, prisma, typescript
- Language: TypeScript
- Homepage: https://dash.deno.com/playground/pentagon-demo
- Size: 127 KB
- Stars: 154
- Watchers: 3
- Forks: 4
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
Sponsored by
[![Flytrap](https://www.useflytrap.com/brand/flytrap-white-bg-1-8.svg)](https://www.useflytrap.com/?utm_campaign=github_repo&utm_medium=referral&utm_content=pentagon&utm_source=github)
A better way to understand your production bugs.
See all the data flowing through your code leading up to bugs. Flytrap allows you to fix bugs in production in a matter of minutes, instead of days.# pentagon
[![Test Github Action][github-actions-test-src]][github-actions-test-href]
[![Lint Github Action][github-actions-lint-src]][github-actions-lint-href]> Prisma like ORM built on top of Deno KV. Allows you to write your database
> schemas and relations using Zod schemas, and run queries using familiar syntax
> from Prisma.## Features
- No codegen required, everything is inferred using Zod and TypeScript
- All same functions as Prisma supported (not all yet implemented)
- Support for `include`
- Support for `select`
- ~~Pagination~~ (todo)## 💻 Example usage
```typescript
import { z } from "https://deno.land/x/[email protected]/mod.ts";
import { createPentagon } from "https://deno.land/x/pentagon/mod.ts";
const kv = await Deno.openKv();export const User = z.object({
id: z.string().uuid().describe("primary"),
createdAt: z.date(),
name: z.string(),
});export const Order = z.object({
id: z.string().uuid().describe("primary"),
createdAt: z.date(),
name: z.string(),
userId: z.string().uuid(),
});const db = createPentagon(kv, {
users: {
schema: User,
relations: {
myOrders: ["orders", [Order], "id", "userId"],
},
},
orders: {
schema: Order,
relations: {
user: ["users", User, "userId", "id"],
},
},
});// Now we have unlocked the magic of Pentagon
const user = await db.users.findFirst({
where: { name: "John Doe" },
select: { name: true, id: true },
});// We can also do `include` queries, fully typed!
const userWithOrders = await db.users.findFirst({
where: { name: "John Doe" },
include: {
myOrders: true, // 👈 if we want the whole object
/* myOrders: { name: true }, 👈 if we want just some parts to be included */
},
});
```## Relations
Defining relations works by defining the `relations` key in the table
definition. This allows us to `include` the values of relations, the same way as
we are familiar with from Prisma.The type signature
[RelationDefinition](https://github.com/skoshx/pentagon/blob/fae437d373df89a1610a998e940c92213d3134b3/src/types.ts#LL56C24-L56C24)
explains what each of the array values represent.Basically, we have `[relation name, schema, local key, foreign key]`.
For instance, a many-to-one relation could look like this:
```typescript
users: {
schema: User,
relations: {
myOrders: ["orders", [Order], undefined, "userId"],
},
},
orders: {
schema: Order,
relations: {
user: ["users", User, "userId", "id"],
},
},
```## 💻 Development
Help is always appreciated, especially with getting the types right! Here's how
you can contribute:- Clone this repository
- Fix types / add feature
- Run the tests using `deno test --unstable`
- Open PR## Running tests
```bash
$ deno test --unstable
```## License
Made with ❤️ in Helsinki, Finland.
Published under [MIT License](./LICENSE.md).
[github-actions-test-href]: https://github.com/skoshx/pentagon/actions/workflows/test.yml
[github-actions-lint-href]: https://github.com/skoshx/pentagon/actions/workflows/lint.yml[github-actions-test-src]: https://github.com/skoshx/pentagon/actions/workflows/test.yml/badge.svg
[github-actions-lint-src]: https://github.com/skoshx/pentagon/actions/workflows/lint.yml/badge.svg