@aurios/mizzle 1.1.3 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
 
2
- > @aurios/mizzle@1.1.3 build /home/runner/work/mizzle/mizzle/packages/mizzle
2
+ > @aurios/mizzle@1.1.4 build /home/runner/work/mizzle/mizzle/packages/mizzle
3
3
  > tsup
4
4
 
5
5
  CLI Building entry: {"index":"src/index.ts","columns":"src/columns/index.ts","table":"src/core/table.ts","snapshot":"src/core/snapshot.ts","diff":"src/core/diff.ts","introspection":"src/core/introspection.ts","db":"src/db.ts"}
@@ -10,22 +10,22 @@
10
10
  CLI Cleaning output folder
11
11
  ESM Build start
12
12
  ESM dist/index.js 2.32 KB
13
- ESM dist/table.js 144.00 B
13
+ ESM dist/columns.js 299.00 B
14
14
  ESM dist/snapshot.js 193.00 B
15
+ ESM dist/table.js 144.00 B
15
16
  ESM dist/chunk-TOYV2M4M.js 866.00 B
16
17
  ESM dist/diff.js 147.00 B
17
- ESM dist/chunk-AQVECMXP.js 2.38 KB
18
18
  ESM dist/introspection.js 1.47 KB
19
+ ESM dist/chunk-AQVECMXP.js 2.38 KB
19
20
  ESM dist/db.js 166.00 B
20
- ESM dist/chunk-NPPZW6VT.js 9.59 KB
21
21
  ESM dist/transaction-RE7LXTGV.js 193.00 B
22
+ ESM dist/chunk-NPPZW6VT.js 9.59 KB
22
23
  ESM dist/chunk-UM3YF5EC.js 15.21 KB
23
24
  ESM dist/chunk-GPYZK4WY.js 1.12 KB
24
25
  ESM dist/chunk-DU7UPWBW.js 5.17 KB
25
- ESM dist/columns.js 299.00 B
26
- ESM ⚡️ Build success in 50ms
26
+ ESM ⚡️ Build success in 45ms
27
27
  DTS Build start
28
- DTS ⚡️ Build success in 5003ms
28
+ DTS ⚡️ Build success in 3819ms
29
29
  DTS dist/index.d.ts 3.84 KB
30
30
  DTS dist/diff.d.ts 485.00 B
31
31
  DTS dist/introspection.d.ts 258.00 B
package/README.md CHANGED
@@ -1,8 +1,24 @@
1
- # @aurios/mizzle
1
+ # 🌧️ mizzle
2
2
 
3
+ ![NPM Last Update](https://img.shields.io/npm/last-update/%40aurios%2Fmizzle?style=flat&color=0EA5E9)
4
+ ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/realfakenerd/mizzle/release.yml?style=flat&color=0EA5E9)
5
+ ![GitHub License](https://img.shields.io/github/license/realfakenerd/mizzle?style=flat&color=0EA5E9)
6
+
7
+ ![NPM Downloads](https://img.shields.io/npm/dw/%40aurios%2Fmizzle?style=flat&color=0EA5E9)
3
8
  A Drizzle-like ORM for DynamoDB. Mizzle provides a type-safe, fluent API for interacting with DynamoDB, supporting relational queries, batch operations, and transactions.
4
9
 
5
- ## Installation
10
+ ## Key Features
11
+
12
+ - **Type-Safe Schema Definition**: Define your tables and entities with strict TypeScript types.
13
+ - **Fluent Query Builder**: precise API for `insert`, `select`, `update`, and `delete` operations.
14
+ - **Relational Queries**: Query related entities with `db.query`.
15
+ - **Batch Operations**: `batchGet` and `batchWrite` support.
16
+ - **Transactions**: Atomic operations using `db.transaction`.
17
+ - **Automatic Type Inference**: `InferSelectModel` and `InferInsertModel` utilities.
18
+
19
+ > Skip this with the [way less boring docs](https://mizzle-docs.vercel.app)
20
+
21
+ ## 🚀 Installation
6
22
 
7
23
  ```bash
8
24
  npm install @aurios/mizzle
@@ -10,48 +26,141 @@ npm install @aurios/mizzle
10
26
  bun add @aurios/mizzle
11
27
  ```
12
28
 
13
- ## Usage
29
+ ## Get Started
30
+
31
+ ### Defining the Table
32
+
33
+ In DynamoDB, you first need a physical table. Mizzle separates the definition of the physical table structure (PK, SK, Indexes) from the logical entities that live within it and with this making your database well organized and easier to reason about.
34
+
35
+ ```ts
36
+ import { dynamoTable, string } from "@aurios/mizzle";
37
+
38
+ // This matches your actual DynamoDB table configuration
39
+ export const myTable = dynamoTable("JediOrder", {
40
+ pk: string("pk"), // The partition key attribute name
41
+ sk: string("sk"), // The sort key attribute name (optional)
42
+ });
43
+ ```
44
+
45
+ ### Defining the Entity
46
+
47
+ An Entity represents your data model (e.g., an user, an item on an user). You map the Entity to a Physical Table and define how its keys are generated, so every entity looks kinda like an separated table.
48
+
49
+ ```ts
50
+ import { dynamoEntity, string, uuid, number, enum, date, prefixKey, staticKey } from "@aurios/mizzle";
51
+
52
+ export const jedi = dynamoEntity(
53
+ myTable,
54
+ "Jedi",
55
+ {
56
+ id: uuid(), // Automatically generates a v7 UUID
57
+ name: string(),
58
+ homeworld: string()
59
+ },
60
+ (cols) => ({
61
+ // PK will look like "JEDI#<uuid>"
62
+ pk: prefixKey("JEDI#", cols.id),
63
+ // SK will be a static string "PROFILE"
64
+ sk: staticKey("PROFILE"),
65
+ }),
66
+ );
67
+
68
+ export const jediRank = dynamoEntity(
69
+ myTable,
70
+ 'JediRank',
71
+ {
72
+ jediId: uuid(),
73
+ position: string().default('initiate'),
74
+ joinedCouncilDate: string(),
75
+ },
76
+ (cols) => ({
77
+ // Same as the jedi so they can be related
78
+ pk: prefixKey('JEDI#', cols.jediId),
79
+ // RANK#initiate
80
+ sk: prefixKey('RANK#', cols.position),
81
+ })
82
+ )
83
+ ```
84
+
85
+ > The UUID V7 was chosen for better sorting, since the values are time-sortable with 1 millisecond precision.
86
+
87
+ ### Define the Relations
88
+
89
+ Relationships in Mizzle are established using the defineRelations function. This step creates a logical map of how your entities interact, enabling you to perform powerful relational queries—such as fetching a Jedi along with their entire rank history—in a single operation.
90
+
91
+ ```ts
92
+ import { defineRelations } from "@aurios/mizzle";
93
+ import * as schema from "./schema";
94
+
95
+ export const relations = defineRelations(schema, (r) => ({
96
+ jedi: {
97
+ // A Jedi could've a lot of ranks throughout his year
98
+ ranks: r.many.jediRank({
99
+ fields: [r.jedi.id],
100
+ references: [r.jediRank.jediId],
101
+ }),
102
+ },
103
+ jediRank: {
104
+ // Every registry points to one Jedi only
105
+ member: r.one.jedi({
106
+ fields: [r.jediRank.jediId],
107
+ references: [r.jedi.id],
108
+ }),
109
+ },
110
+ }));
111
+ ```
14
112
 
15
113
  ### Initialization
16
114
 
115
+ Initialize the mizzle client by passing it an instance of the standard AWS DynamoDBClient and the relations we just defined.
116
+
17
117
  ```ts
18
118
  import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
19
119
  import { mizzle } from "@aurios/mizzle";
120
+ import { relations } from "./relations";
20
121
 
21
- const client = new DynamoDBClient({});
22
- const db = mizzle(client);
122
+ const client = new DynamoDBClient({ region: "us-east-1" });
123
+ export const db = mizzle({ client, relations });
23
124
  ```
24
125
 
25
- ### Key Features
126
+ ### Query
26
127
 
27
- - **Type-Safe Schema Definition**: Define your tables and entities with strict TypeScript types.
28
- - **Fluent Query Builder**: precise API for `insert`, `select`, `update`, and `delete` operations.
29
- - **Relational Queries**: Query related entities with `db.query`.
30
- - **Batch Operations**: `batchGet` and `batchWrite` support.
31
- - **Transactions**: Atomic operations using `db.transaction`.
32
- - **Automatic Type Inference**: `InferSelectModel` and `InferInsertModel` utilities.
128
+ Now you can use the fluent API to interact with your data in the best way possible.
33
129
 
34
- ### Example
130
+ #### Insert Data
35
131
 
36
- ```ts
37
- // Define your schema (simplified)
38
- import { dynamoTable, dynamoEntity, string } from "@aurios/mizzle";
132
+ ```typescript
133
+ // api/jedi/new.ts
134
+ import { jedi } from "$lib/schema.ts";
39
135
 
40
- const myTable = dynamoTable("my-app-table", {
41
- pk: string("pk"),
42
- sk: string("sk"),
43
- });
136
+ const newJedi = await db
137
+ .insert(jedi)
138
+ .values({
139
+ name: "Luke Skywalker",
140
+ homeworld: "Tatooine",
141
+ })
142
+ .returning();
44
143
 
45
- const users = dynamoEntity(myTable, "users", {
46
- id: string("id"),
47
- name: string("name"),
48
- email: string("email"),
49
- });
144
+ console.log(newJedi.id); // The auto-generated UUID
145
+ ```
50
146
 
51
- // Query
52
- const result = await db.select().from(users).where(eq(users.id, "123"));
147
+ #### Select Data
148
+
149
+ Mizzle intelligently routes your request to `GetItem`, `Query`, or `Scan` based on the filters you provide.
150
+
151
+ ```typescript
152
+ // /api/jedi/get.ts
153
+ import { jedi } from "$lib/schema.ts";
154
+ import { eq } from "@aurios/mizzle";
155
+
156
+ // This will use GetItem because both PK and SK are fully resolved
157
+ const user = await db.select().from(jedi).where(eq(jedi.id, "some-uuid")).execute();
53
158
  ```
54
159
 
55
- ## License
160
+ ## Mizzling
161
+
162
+ This will work if you already has a DynamoDB table with data in it. If you want to create a new table with the schema you defined, you can use the [`mizzling`](https://www.npmjs.com/package/@aurios/mizzling) CLI.
163
+
164
+ ## 📄 License
56
165
 
57
- MIT
166
+ This project is licensed under the MIT License.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aurios/mizzle",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "a drizzle-like orm for dynamoDB",
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -79,8 +79,8 @@
79
79
  "devDependencies": {
80
80
  "tsup": "^8.5.1",
81
81
  "@repo/shared": "0.0.3",
82
- "@repo/vitest-config": "0.0.0",
83
- "@repo/typescript-config": "0.0.0"
82
+ "@repo/typescript-config": "0.0.0",
83
+ "@repo/vitest-config": "0.0.0"
84
84
  },
85
85
  "scripts": {
86
86
  "check": "tsc --noEmit",