Skip to content

Commit 2a15d1f

Browse files
Merge pull request #99 from monarch-orm/docs-improvements
Improve documentation
2 parents 6cbf5de + b31eb83 commit 2a15d1f

8 files changed

Lines changed: 303 additions & 174 deletions

File tree

docs/.vitepress/config.mts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export default defineConfig({
88
nav: [
99
{ text: "Home", link: "/" },
1010
{ text: "Guide", link: "/guide/getting-started" },
11-
{ text: "API", link: "/api/" },
1211
],
1312

1413
sidebar: [
@@ -17,16 +16,13 @@ export default defineConfig({
1716
items: [
1817
{ text: "Getting Started", link: "/guide/getting-started" },
1918
{ text: "Schemas", link: "/guide/schemas" },
19+
{ text: "Queries & Mutations", link: "/guide/queries-and-mutations" },
20+
{ text: "Query Builders", link: "/guide/query-builders" },
2021
{ text: "Types", link: "/guide/types" },
21-
{ text: "Queries", link: "/guide/queries" },
22+
{ text: "Relations", link: "/guide/relations" },
2223
{ text: "Operators", link: "/guide/operators" },
23-
{ text: "Aggregations & Relations", link: "/guide/aggregation-and-relations" },
2424
],
2525
},
26-
{
27-
text: "API Reference",
28-
items: [{ text: "Collection Methods", link: "/api/" }],
29-
},
3026
],
3127

3228
socialLinks: [{ icon: "github", link: "https://github.com/monarch-orm/monarch" }],

docs/guide/getting-started.md

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,55 @@
44

55
## Installation
66

7-
NPM:
8-
```bash
7+
::: code-group
8+
9+
```bash [npm]
910
npm install monarch-orm
1011
```
1112

12-
Or Yarn:
13-
```bash
13+
```bash [pnpm]
14+
pnpm add monarch-orm
15+
```
16+
17+
```bash [yarn]
1418
yarn add monarch-orm
1519
```
1620

17-
Or PNPM:
18-
```bash
19-
pnpm add monarch-orm
21+
```bash [bun]
22+
bun add monarch-orm
2023
```
2124

25+
:::
26+
2227
## Basic Usage
2328

2429
```typescript
2530
import { createClient, createDatabase, createSchema, defineSchemas } from "monarch-orm";
2631
import { boolean, number, string } from "monarch-orm/types";
2732

2833
const UserSchema = createSchema("users", {
29-
name: string().nullable(),
30-
email: string().lowercase().optional(),
31-
age: number().optional().default(10),
34+
name: string(),
35+
email: string(),
36+
age: number().default(10),
3237
isVerified: boolean(),
3338
});
3439

35-
const client = createClient(/** db uri **/)
3640
const schemas = defineSchemas({
3741
UserSchema,
3842
});
3943

40-
const { collections } = createDatabase(client.db(), schemas);
44+
const client = createClient("mongodb://localhost:27017/monarch-example");
45+
const db = createDatabase(client.db(), schemas);
4146

42-
const newUser = await collections.users
47+
const newUser = await db.collections.users
4348
.insertOne({
4449
name: "anon",
4550
email: "anon@gmail.com",
4651
age: 0,
4752
isVerified: true,
4853
});
4954

50-
const users = await collections.users.find({});
55+
const users = await db.collections.users.find({});
5156
```
5257

5358
## Quick Start
@@ -72,7 +77,7 @@ const schemas = defineSchemas({
7277
UserSchema,
7378
});
7479

75-
const { collections } = createDatabase(client.db(), schemas);
80+
const db = createDatabase(client.db(), schemas);
7681
```
7782

7883
### Inserting Documents
Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
1-
# API Documentation
1+
# Queries & Mutations
22

3-
This page provides a comprehensive list of all collection methods available in Monarch ORM.
3+
Once your database is initialized, every collection becomes available under `db.collections`. This object provides a fully type-safe gateway to interact with your MongoDB database.
44

5-
## Queries
5+
This page serves as an API reference for the core methods you can call directly on a collection instance to insert, update, delete, or retrieve data.
6+
7+
## Accessing Collections
8+
9+
You don't need to manually instantiate or wrap collections. Just access them directly off the `db.collections` object. Because of your schemas, Monarch knows exactly what data shapes are valid.
10+
11+
```typescript
12+
// Access your "users" collection
13+
// The collection is strictly typed!
14+
await db.collections.users.insertOne({ name: "Alice" });
15+
```
16+
17+
---
618

7-
Collections expose typed query methods.
19+
## Mutations
20+
21+
Mutations allow you to add, modify, or delete documents. All mutations immediately execute against the database.
822

923
### `insertOne(data)`
1024

@@ -28,6 +42,12 @@ await db.collections.users.insertMany([
2842
]);
2943
```
3044

45+
---
46+
47+
## Queries
48+
49+
Queries retrieve data from the database. Unlike mutations, queries like `.find()` return a lazy builder that isn't executed until you `await` it.
50+
3151
### `find(filter?)`
3252

3353
Returns a query for multiple documents. It supports `select()`, `omit()`, `sort()`, `limit()`, `skip()`, `options()`, `cursor()`, and `populate()`.

docs/guide/queries.md

Lines changed: 0 additions & 114 deletions
This file was deleted.

0 commit comments

Comments
 (0)