> ## Documentation Index
> Fetch the complete documentation index at: https://confect.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Writing

> Insert, modify, and delete documents in the database.

The `DatabaseWriter` service is used to insert, modify, and delete documents in the database.

```ts theme={null}
import * as Effect from "effect/Effect";
import { DatabaseWriter } from "./confect/_generated/services";

Effect.gen(function* () {
  const writer = yield* DatabaseWriter;

  return yield* writer.table("notes").insert({
    title: "My first note",
    text: "This is my first note",
  });
});
```

## Methods

### Insert

Insert a new document.

```ts theme={null}
writer.table("notes").insert({
  title: "My first note",
  text: "This is my first note",
});
```

### Patch

Shallow merge the provided object with the existing document. New fields are added. Existing fields are overwritten. Fields set to `undefined` are removed.

```ts theme={null}
writer.table("notes").patch(noteId, {
  title: "Patched title",
  author: "John Doe",
  text: undefined,
});
```

### Replace

Replace the entire document.

```ts theme={null}
writer.table("notes").replace(noteId, {
  title: "Replaced title",
  text: "I'm replacing the whole document",
});
```

### Delete

Delete the document with the given ID.

```ts theme={null}
writer.table("notes").delete(noteId);
```
