@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.
- package/.turbo/turbo-build.log +7 -7
- package/README.md +138 -29
- package/package.json +3 -3
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @aurios/mizzle@1.1.
|
|
2
|
+
> @aurios/mizzle@1.1.4 build /home/runner/work/mizzle/mizzle/packages/mizzle
|
|
3
3
|
> tsup
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m 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
|
[34mCLI[39m Cleaning output folder
|
|
11
11
|
[34mESM[39m Build start
|
|
12
12
|
[32mESM[39m [1mdist/index.js [22m[32m2.32 KB[39m
|
|
13
|
-
[32mESM[39m [1mdist/
|
|
13
|
+
[32mESM[39m [1mdist/columns.js [22m[32m299.00 B[39m
|
|
14
14
|
[32mESM[39m [1mdist/snapshot.js [22m[32m193.00 B[39m
|
|
15
|
+
[32mESM[39m [1mdist/table.js [22m[32m144.00 B[39m
|
|
15
16
|
[32mESM[39m [1mdist/chunk-TOYV2M4M.js [22m[32m866.00 B[39m
|
|
16
17
|
[32mESM[39m [1mdist/diff.js [22m[32m147.00 B[39m
|
|
17
|
-
[32mESM[39m [1mdist/chunk-AQVECMXP.js [22m[32m2.38 KB[39m
|
|
18
18
|
[32mESM[39m [1mdist/introspection.js [22m[32m1.47 KB[39m
|
|
19
|
+
[32mESM[39m [1mdist/chunk-AQVECMXP.js [22m[32m2.38 KB[39m
|
|
19
20
|
[32mESM[39m [1mdist/db.js [22m[32m166.00 B[39m
|
|
20
|
-
[32mESM[39m [1mdist/chunk-NPPZW6VT.js [22m[32m9.59 KB[39m
|
|
21
21
|
[32mESM[39m [1mdist/transaction-RE7LXTGV.js [22m[32m193.00 B[39m
|
|
22
|
+
[32mESM[39m [1mdist/chunk-NPPZW6VT.js [22m[32m9.59 KB[39m
|
|
22
23
|
[32mESM[39m [1mdist/chunk-UM3YF5EC.js [22m[32m15.21 KB[39m
|
|
23
24
|
[32mESM[39m [1mdist/chunk-GPYZK4WY.js [22m[32m1.12 KB[39m
|
|
24
25
|
[32mESM[39m [1mdist/chunk-DU7UPWBW.js [22m[32m5.17 KB[39m
|
|
25
|
-
[32mESM[39m
|
|
26
|
-
[32mESM[39m ⚡️ Build success in 50ms
|
|
26
|
+
[32mESM[39m ⚡️ Build success in 45ms
|
|
27
27
|
[34mDTS[39m Build start
|
|
28
|
-
[32mDTS[39m ⚡️ Build success in
|
|
28
|
+
[32mDTS[39m ⚡️ Build success in 3819ms
|
|
29
29
|
[32mDTS[39m [1mdist/index.d.ts [22m[32m3.84 KB[39m
|
|
30
30
|
[32mDTS[39m [1mdist/diff.d.ts [22m[32m485.00 B[39m
|
|
31
31
|
[32mDTS[39m [1mdist/introspection.d.ts [22m[32m258.00 B[39m
|
package/README.md
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 🌧️ mizzle
|
|
2
2
|
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
|
|
7
|
+

|
|
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
|
-
##
|
|
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
|
-
##
|
|
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
|
-
###
|
|
126
|
+
### Query
|
|
26
127
|
|
|
27
|
-
|
|
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
|
-
|
|
130
|
+
#### Insert Data
|
|
35
131
|
|
|
36
|
-
```
|
|
37
|
-
//
|
|
38
|
-
import {
|
|
132
|
+
```typescript
|
|
133
|
+
// api/jedi/new.ts
|
|
134
|
+
import { jedi } from "$lib/schema.ts";
|
|
39
135
|
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
136
|
+
const newJedi = await db
|
|
137
|
+
.insert(jedi)
|
|
138
|
+
.values({
|
|
139
|
+
name: "Luke Skywalker",
|
|
140
|
+
homeworld: "Tatooine",
|
|
141
|
+
})
|
|
142
|
+
.returning();
|
|
44
143
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
name: string("name"),
|
|
48
|
-
email: string("email"),
|
|
49
|
-
});
|
|
144
|
+
console.log(newJedi.id); // The auto-generated UUID
|
|
145
|
+
```
|
|
50
146
|
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
##
|
|
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
|
+
"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/
|
|
83
|
-
"@repo/
|
|
82
|
+
"@repo/typescript-config": "0.0.0",
|
|
83
|
+
"@repo/vitest-config": "0.0.0"
|
|
84
84
|
},
|
|
85
85
|
"scripts": {
|
|
86
86
|
"check": "tsc --noEmit",
|