@@ -56,13 +56,17 @@ app.use(tableHistory, { name: "userAuditLog" });
5656export default app ;
5757```
5858
59+ To add history to multiple tables, you can call ` app.use ` multiple times with
60+ different names. They will be available in your app as
61+ ` new TableHistory(components.<name>, ...) ` .
62+
5963## Usage
6064
6165``` ts
6266import { components } from " ./_generated/api" ;
6367import { TableHistory } from " @convex-dev/table-history" ;
6468
65- const userAuditLog = new TableHistory (components .userAuditLog , {
69+ const userAuditLog = new TableHistory < DataModel , " users " > (components .userAuditLog , {
6670 serializability: " wallclock" ,
6771});
6872```
@@ -120,11 +124,14 @@ You can configure the serializability of the history table by setting the
120124
121125### ` currentTs ` and ` maxTs ` are required
122126
123- Generate a ` currentTs ` that is stable and recent. Use it for
124- all pages of a ` usePaginatedQuery ` call, by passing it up from the client.
127+ - For ` listSnapshot ` , ` currentTs ` should be a stable recent timestamp.
128+ - If the timestamp isn't recent, the queries might read too much data in
129+ a single page and throw an error.
130+ - For ` listHistory ` and ` listDocumentHistory ` , ` maxTs ` should be stable but
131+ doesn't need to be recent.
125132
126133``` ts
127- const [currentTs] = useState (Date .now ());
134+ const [currentTs] = useState (Date .now ()); // stable and recent
128135const [yesterday] = useState (Date .now () - 24 * 60 * 60 * 1000 );
129136const usersYesterday = usePaginatedQuery (
130137 api .users .listSnapshot ,
@@ -152,14 +159,6 @@ the TableHistory component assumes its own data model is append-only (which is
152159true, except when vacuuming), and takes in a stable recent timestamp. Then it
153160only looks at history entries from before that timestamp.
154161
155- Requirements:
156-
157- - For ` listSnapshot ` , ` currentTs ` should be a stable recent timestamp.
158- - If the timestamp isn't recent, the queries might read too much data in
159- a single page and throw an error.
160- - For ` listHistory ` and ` listDocumentHistory ` , ` maxTs ` should be stable but
161- doesn't need to be recent.
162-
163162### Vacuuming
164163
165164The history table can grow large, so you can use the ` vacuumHistory ` function
@@ -168,4 +167,13 @@ schedule background jobs to delete old history entries.
168167The entries which will be deleted are those which are not visible
169168at snapshots ` >=minTsToKeep ` .
170169
170+ ### Limitations
171+
172+ - No attribution: there is no way to add attribution to a history entry, e.g. which ` ctx.auth `
173+ made the change.
174+ - Workaround: you can add attribution to the document itself.
175+ - No indexes: you can't use an index to change the sort order or get a subset of results.
176+ - Workaround: you can paginate until ` isDone ` returns true, and sort or filter
177+ the results yourself, either on the client or in an action.
178+
171179<!-- END: Include on https://convex.dev/components -->
0 commit comments