Unverified Commit 2b028891 authored by Tom Ballinger's avatar Tom Ballinger Committed by GitHub

examples: Upgrade Convex example to convex@1.2.1 (#54910)

Co-authored-by: 's avatarLee Robinson <me@leerob.io>
parent 6d9ce62f
...@@ -5,7 +5,7 @@ https://docs.convex.dev/using/writing-convex-functions for more. ...@@ -5,7 +5,7 @@ https://docs.convex.dev/using/writing-convex-functions for more.
A query function that takes two arguments looks like: A query function that takes two arguments looks like:
```javascript ```ts
// functions.js // functions.js
import { query } from './_generated/server' import { query } from './_generated/server'
import { v } from 'convex/values' import { v } from 'convex/values'
...@@ -18,10 +18,13 @@ export const myQueryFunction = query({ ...@@ -18,10 +18,13 @@ export const myQueryFunction = query({
}, },
// Function implementation. // Function implementation.
hander: async ({ db }, { first, second }) => { hander: async (ctx, args) => {
// Read the database as many times as you need here. // Read the database as many times as you need here.
// See https://docs.convex.dev/database/reading-data. // See https://docs.convex.dev/database/reading-data.
const documents = await db.query('tablename').collect() const documents = await ctx.db.query('tablename').collect()
// Arguments passed from the client are properties of the args object.
console.log(args.first, args.second)
// Write arbitrary JavaScript here: filter, aggregate, build derived data, // Write arbitrary JavaScript here: filter, aggregate, build derived data,
// remove non-public properties, or create new objects. // remove non-public properties, or create new objects.
...@@ -32,7 +35,7 @@ export const myQueryFunction = query({ ...@@ -32,7 +35,7 @@ export const myQueryFunction = query({
Using this query function in a React component looks like: Using this query function in a React component looks like:
```javascript ```ts
const data = useQuery(api.functions.myQueryFunction, { const data = useQuery(api.functions.myQueryFunction, {
first: 10, first: 10,
second: 'hello', second: 'hello',
...@@ -41,7 +44,7 @@ const data = useQuery(api.functions.myQueryFunction, { ...@@ -41,7 +44,7 @@ const data = useQuery(api.functions.myQueryFunction, {
A mutation function looks like: A mutation function looks like:
```javascript ```ts
// functions.js // functions.js
import { mutation } from './_generated/server' import { mutation } from './_generated/server'
import { v } from 'convex/values' import { v } from 'convex/values'
...@@ -54,22 +57,22 @@ export const myMutationFunction = mutation({ ...@@ -54,22 +57,22 @@ export const myMutationFunction = mutation({
}, },
// Function implementation. // Function implementation.
hander: async ({ db }, { first, second }) => { hander: async (ctx, args) => {
// Insert or modify documents in the database here. // Insert or modify documents in the database here.
// Mutations can also read from the database like queries. // Mutations can also read from the database like queries.
// See https://docs.convex.dev/database/writing-data. // See https://docs.convex.dev/database/writing-data.
const message = { body: first, author: second } const message = { body: args.first, author: args.second }
const id = await db.insert('messages', message) const id = await ctx.db.insert('messages', message)
// Optionally, return a value from your mutation. // Optionally, return a value from your mutation.
return await db.get(id) return await ctx.db.get(id)
}, },
}) })
``` ```
Using this mutation function in a React component looks like: Using this mutation function in a React component looks like:
```javascript ```ts
const mutation = useMutation(api.functions.myMutationFunction) const mutation = useMutation(api.functions.myMutationFunction)
function handleButtonPress() { function handleButtonPress() {
// fire and forget, the most common way to use mutations // fire and forget, the most common way to use mutations
...@@ -82,6 +85,6 @@ function handleButtonPress() { ...@@ -82,6 +85,6 @@ function handleButtonPress() {
} }
``` ```
The Convex CLI is your friend. See everything it can do by running Use the Convex CLI to push your functions to a deployment. See everything
`npx convex -h` in your project root directory. To learn more, launch the docs the Convex CLI can do by running `npx convex -h` in your project root
with `npx convex docs`. directory. To learn more, launch the docs with `npx convex docs`.
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* *
* THIS CODE IS AUTOMATICALLY GENERATED. * THIS CODE IS AUTOMATICALLY GENERATED.
* *
* Generated by convex@0.19.0. * Generated by convex@1.2.1.
* To regenerate, run `npx convex dev`. * To regenerate, run `npx convex dev`.
* @module * @module
*/ */
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* *
* THIS CODE IS AUTOMATICALLY GENERATED. * THIS CODE IS AUTOMATICALLY GENERATED.
* *
* Generated by convex@0.19.0. * Generated by convex@1.2.1.
* To regenerate, run `npx convex dev`. * To regenerate, run `npx convex dev`.
* @module * @module
*/ */
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* *
* THIS CODE IS AUTOMATICALLY GENERATED. * THIS CODE IS AUTOMATICALLY GENERATED.
* *
* Generated by convex@0.19.0. * Generated by convex@1.2.1.
* To regenerate, run `npx convex dev`. * To regenerate, run `npx convex dev`.
* @module * @module
*/ */
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* *
* THIS CODE IS AUTOMATICALLY GENERATED. * THIS CODE IS AUTOMATICALLY GENERATED.
* *
* Generated by convex@0.19.0. * Generated by convex@1.2.1.
* To regenerate, run `npx convex dev`. * To regenerate, run `npx convex dev`.
* @module * @module
*/ */
...@@ -14,11 +14,11 @@ import { ...@@ -14,11 +14,11 @@ import {
HttpActionBuilder, HttpActionBuilder,
MutationBuilder, MutationBuilder,
QueryBuilder, QueryBuilder,
ActionCtx as GenericActionCtx, GenericActionCtx,
MutationCtx as GenericMutationCtx, GenericMutationCtx,
QueryCtx as GenericQueryCtx, GenericQueryCtx,
DatabaseReader as GenericDatabaseReader, GenericDatabaseReader,
DatabaseWriter as GenericDatabaseWriter, GenericDatabaseWriter,
} from "convex/server"; } from "convex/server";
import type { DataModel } from "./dataModel.js"; import type { DataModel } from "./dataModel.js";
...@@ -73,7 +73,7 @@ export declare const internalMutation: MutationBuilder<DataModel, "internal">; ...@@ -73,7 +73,7 @@ export declare const internalMutation: MutationBuilder<DataModel, "internal">;
* @param func - The action. It receives an {@link ActionCtx} as its first argument. * @param func - The action. It receives an {@link ActionCtx} as its first argument.
* @returns The wrapped action. Include this as an `export` to name it and make it accessible. * @returns The wrapped action. Include this as an `export` to name it and make it accessible.
*/ */
export declare const action: ActionBuilder<"public">; export declare const action: ActionBuilder<DataModel, "public">;
/** /**
* Define an action that is only accessible from other Convex functions (but not from the client). * Define an action that is only accessible from other Convex functions (but not from the client).
...@@ -81,7 +81,7 @@ export declare const action: ActionBuilder<"public">; ...@@ -81,7 +81,7 @@ export declare const action: ActionBuilder<"public">;
* @param func - The function. It receives an {@link ActionCtx} as its first argument. * @param func - The function. It receives an {@link ActionCtx} as its first argument.
* @returns The wrapped function. Include this as an `export` to name it and make it accessible. * @returns The wrapped function. Include this as an `export` to name it and make it accessible.
*/ */
export declare const internalAction: ActionBuilder<"internal">; export declare const internalAction: ActionBuilder<DataModel, "internal">;
/** /**
* Define an HTTP action. * Define an HTTP action.
...@@ -120,7 +120,7 @@ export type MutationCtx = GenericMutationCtx<DataModel>; ...@@ -120,7 +120,7 @@ export type MutationCtx = GenericMutationCtx<DataModel>;
* The action context is passed as the first argument to any Convex action * The action context is passed as the first argument to any Convex action
* function run on the server. * function run on the server.
*/ */
export type ActionCtx = GenericActionCtx; export type ActionCtx = GenericActionCtx<DataModel>;
/** /**
* An interface to read from the database within Convex query functions. * An interface to read from the database within Convex query functions.
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* *
* THIS CODE IS AUTOMATICALLY GENERATED. * THIS CODE IS AUTOMATICALLY GENERATED.
* *
* Generated by convex@0.19.0. * Generated by convex@1.2.1.
* To regenerate, run `npx convex dev`. * To regenerate, run `npx convex dev`.
* @module * @module
*/ */
......
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
"module": "ESNext", "module": "ESNext",
"moduleResolution": "Node", "moduleResolution": "Node",
"isolatedModules": true, "isolatedModules": true,
"noEmit": true "noEmit": true,
"skipLibCheck": true
}, },
"include": ["./**/*"], "include": ["./**/*"],
"exclude": ["./_generated"] "exclude": ["./_generated"]
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
"start": "next start" "start": "next start"
}, },
"dependencies": { "dependencies": {
"convex": "~0.19.0", "convex": "~1.2.1",
"next": "latest", "next": "latest",
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0" "react-dom": "^18.2.0"
...@@ -20,6 +20,6 @@ ...@@ -20,6 +20,6 @@
"@types/react-dom": "18.0.11", "@types/react-dom": "18.0.11",
"@types/react": "18.2.8", "@types/react": "18.2.8",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"typescript": "^4.9.5" "typescript": "^5.0.3"
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment