Thin MongoDB ODM built for Standard Schema
mongodb zod deno

remove definemodel

+11 -27
+3 -3
README.md
··· 38 38 ```ts 39 39 // src/schemas/user.ts 40 40 import { z } from "zod"; 41 - import { defineModel } from "mizzleorm"; 41 + import { defineModel } from "@nozzle/nozzle"; 42 42 43 - export const userSchema = defineModel(z.object({ 43 + export const userSchema = z.object({ 44 44 name: z.string(), 45 45 email: z.string().email(), 46 46 age: z.number().int().positive().optional(), 47 47 createdAt: z.date().default(() => new Date()), 48 - })); 48 + }); 49 49 50 50 export type User = z.infer<typeof userSchema>; 51 51 ```
+2 -5
deno.json
··· 1 1 { 2 - "name": "mizzleorm", 2 + "name": "@nozzle/nozzle", 3 3 "version": "0.1.0", 4 4 "exports": "./mod.ts", 5 5 "license": "MIT", 6 6 "tasks": { 7 7 "build": "tsc", 8 - "test": "deno run --allow-run --allow-read scripts/test.ts --all", 9 8 "test:mock": "deno test tests/mock_test.ts", 10 - "test:integration": "deno test --allow-net --allow-read --allow-write --allow-env --allow-sys tests/main_test.ts", 11 - "test:watch": "deno run --allow-run --allow-read scripts/test.ts --mock --watch", 12 - "example": "deno run --allow-net --allow-read --allow-write --allow-env --allow-sys examples/user.ts" 9 + "test:watch": "deno run -A scripts/test.ts --mock --watch" 13 10 }, 14 11 "imports": { 15 12 "zod": "jsr:@zod/zod@^4.0.17",
+2 -3
examples/user.ts
··· 2 2 import { ObjectId } from "mongodb"; 3 3 import { 4 4 connect, 5 - defineModel, 6 5 disconnect, 7 6 type InferModel, 8 7 type InsertType, ··· 10 9 } from "../mod.ts"; 11 10 12 11 // 1. Define your schema using Zod 13 - const userSchema = defineModel(z.object({ 12 + const userSchema = z.object({ 14 13 name: z.string(), 15 14 email: z.string().email(), 16 15 age: z.number().int().positive().optional(), 17 16 createdAt: z.date().default(() => new Date()), 18 - })); 17 + }); 19 18 20 19 // Infer the TypeScript type from the Zod schema 21 20 type User = InferModel<typeof userSchema>;
+1 -1
mod.ts
··· 1 - export { defineModel, type InferModel, type InsertType } from "./schema.ts"; 1 + export { type InferModel, type InsertType } from "./schema.ts"; 2 2 export { connect, disconnect } from "./client.ts"; 3 3 export { Model } from "./model.ts";
-4
schema.ts
··· 1 1 import type { z } from "zod"; 2 2 import type { ObjectId } from "mongodb"; 3 3 4 - export function defineModel<T extends z.ZodObject>(schema: T) { 5 - return schema; 6 - } 7 - 8 4 export type InferModel<T extends z.ZodObject> = z.infer<T> & { 9 5 _id?: ObjectId; 10 6 };
+3 -11
tests/main_test.ts
··· 1 1 import { assertEquals, assertExists, assertRejects } from "jsr:@std/assert"; 2 2 import { z } from "zod"; 3 - import { 4 - connect, 5 - defineModel, 6 - disconnect, 7 - type InferModel, 8 - type InsertType, 9 - Model, 10 - } from "../mod.ts"; 3 + import { connect, disconnect, type InsertType, Model } from "../mod.ts"; 11 4 import { ObjectId } from "mongodb"; 12 5 13 - const userSchema = defineModel(z.object({ 6 + const userSchema = z.object({ 14 7 name: z.string(), 15 8 email: z.email(), 16 9 age: z.number().int().positive().optional(), 17 10 createdAt: z.date().default(() => new Date()), 18 - })); 11 + }); 19 12 20 - type User = InferModel<typeof userSchema>; 21 13 type UserInsert = InsertType<typeof userSchema>; 22 14 23 15 let UserModel: Model<typeof userSchema>;