Skip to content

Commit f8c788d

Browse files
nipunn1313beeman
authored andcommitted
convex-backend PR 48: Add schema to Pagination demo (#34671)
This PR adds the `schema.ts` to the Pagination demo. ---- By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. Co-authored-by: Bram Borggreve <[email protected]> GitOrigin-RevId: 65ba5e9b332a52e2531f750ae6943b77072040e4
1 parent dca8234 commit f8c788d

File tree

5 files changed

+35
-21
lines changed

5 files changed

+35
-21
lines changed

npm-packages/demos/pagination/convex/_generated/dataModel.d.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,29 @@
88
* @module
99
*/
1010

11-
import { AnyDataModel } from "convex/server";
11+
import type {
12+
DataModelFromSchemaDefinition,
13+
DocumentByName,
14+
TableNamesInDataModel,
15+
SystemTableNames,
16+
} from "convex/server";
1217
import type { GenericId } from "convex/values";
13-
14-
/**
15-
* No `schema.ts` file found!
16-
*
17-
* This generated code has permissive types like `Doc = any` because
18-
* Convex doesn't know your schema. If you'd like more type safety, see
19-
* https://docs.convex.dev/using/schemas for instructions on how to add a
20-
* schema file.
21-
*
22-
* After you change a schema, rerun codegen with `npx convex dev`.
23-
*/
18+
import schema from "../schema.js";
2419

2520
/**
2621
* The names of all of your Convex tables.
2722
*/
28-
export type TableNames = string;
23+
export type TableNames = TableNamesInDataModel<DataModel>;
2924

3025
/**
3126
* The type of a document stored in Convex.
27+
*
28+
* @typeParam TableName - A string literal type of the table name (like "users").
3229
*/
33-
export type Doc = any;
30+
export type Doc<TableName extends TableNames> = DocumentByName<
31+
DataModel,
32+
TableName
33+
>;
3434

3535
/**
3636
* An identifier for a document in Convex.
@@ -42,8 +42,10 @@ export type Doc = any;
4242
*
4343
* IDs are just strings at runtime, but this type can be used to distinguish them from other
4444
* strings when type checking.
45+
*
46+
* @typeParam TableName - A string literal type of the table name (like "users").
4547
*/
46-
export type Id<TableName extends TableNames = TableNames> =
48+
export type Id<TableName extends TableNames | SystemTableNames> =
4749
GenericId<TableName>;
4850

4951
/**
@@ -55,4 +57,4 @@ export type Id<TableName extends TableNames = TableNames> =
5557
* This type is used to parameterize methods like `queryGeneric` and
5658
* `mutationGeneric` to make them type-safe.
5759
*/
58-
export type DataModel = AnyDataModel;
60+
export type DataModel = DataModelFromSchemaDefinition<typeof schema>;

npm-packages/demos/pagination/convex/messages.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ export const listWithTransformation = query({
4747
});
4848
// @snippet end listWithTransformation
4949

50-
export const send = mutation(async (ctx, args) => {
51-
const { body, author } = args;
52-
await ctx.db.insert("messages", { body, author });
50+
export const send = mutation({
51+
args: { body: v.string(), author: v.string() },
52+
handler: async (ctx, args) => {
53+
const { body, author } = args;
54+
await ctx.db.insert("messages", { body, author });
55+
},
5356
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { defineSchema, defineTable } from "convex/server";
2+
import { v } from "convex/values";
3+
4+
export default defineSchema({
5+
messages: defineTable({
6+
author: v.string(),
7+
body: v.string(),
8+
}),
9+
});

npm-packages/demos/pagination/src/_listingWithArgument.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function App() {
1313
);
1414
return (
1515
<div>
16-
{results?.map(({ _id, text }) => <div key={_id}>{text}</div>)}
16+
{results?.map(({ _id, body }) => <div key={_id}>{body}</div>)}
1717
<button onClick={() => loadMore(5)} disabled={status !== "CanLoadMore"}>
1818
Load More
1919
</button>

npm-packages/demos/pagination/src/_simpleListing.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function App() {
1313
);
1414
return (
1515
<div>
16-
{results?.map(({ _id, text }) => <div key={_id}>{text}</div>)}
16+
{results?.map(({ _id, body }) => <div key={_id}>{body}</div>)}
1717
<button onClick={() => loadMore(5)} disabled={status !== "CanLoadMore"}>
1818
Load More
1919
</button>

0 commit comments

Comments
 (0)