Skip to content

Commit c943043

Browse files
authored
Merge pull request #2 from get-convex/lee/example-insert
[table history] example of insert and delete
2 parents 023278b + 79a4fab commit c943043

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ async function patchDocument(ctx: MutationCtx, documentId: Id<"documents">, patc
7777
const document = await ctx.db.get(documentId);
7878
await documentAuditLog.update(ctx, documentId, document);
7979
}
80+
81+
async function insertDocument(ctx: MutationCtx, documentId: Id<"documents">, newDoc: WithoutSystemFields<Doc<"documents">>) {
82+
const documentId = await ctx.db.insert("documents", newDoc);
83+
const document = await ctx.db.get(documentId);
84+
await documentAuditLog.update(ctx, documentId, document);
85+
}
86+
87+
async function deleteDocument(ctx: MutationCtx, documentId: Id<"documents">) {
88+
await ctx.db.delete(documentId);
89+
await documentAuditLog.update(ctx, documentId, null);
90+
}
8091
```
8192

8293
Or attach a [trigger](https://www.npmjs.com/package/convex-helpers#triggers) to automatically write to the history table when a mutation changes a document:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"email": "support@convex.dev",
88
"url": "https://github.com/ldanilek/table-history/issues"
99
},
10-
"version": "0.1.1",
10+
"version": "0.1.2",
1111
"license": "Apache-2.0",
1212
"keywords": [
1313
"convex",

0 commit comments

Comments
 (0)