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.
A query function that takes two arguments looks like:
```javascript
```ts
// functions.js
import { query } from './_generated/server'
import { v } from 'convex/values'
......@@ -18,10 +18,13 @@ export const myQueryFunction = query({
},
// Function implementation.
hander: async ({ db }, { first, second }) => {
hander: async (ctx, args) => {
// Read the database as many times as you need here.
// 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,
// remove non-public properties, or create new objects.
......@@ -32,7 +35,7 @@ export const myQueryFunction = query({
Using this query function in a React component looks like:
```javascript
```ts
const data = useQuery(api.functions.myQueryFunction, {
first: 10,
second: 'hello',
......@@ -41,7 +44,7 @@ const data = useQuery(api.functions.myQueryFunction, {
A mutation function looks like:
```javascript
```ts
// functions.js
import { mutation } from './_generated/server'
import { v } from 'convex/values'
......@@ -54,22 +57,22 @@ export const myMutationFunction = mutation({
},
// Function implementation.
hander: async ({ db }, { first, second }) => {
hander: async (ctx, args) => {
// Insert or modify documents in the database here.
// Mutations can also read from the database like queries.
// See https://docs.convex.dev/database/writing-data.
const message = { body: first, author: second }
const id = await db.insert('messages', message)
const message = { body: args.first, author: args.second }
const id = await ctx.db.insert('messages', message)
// 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:
```javascript
```ts
const mutation = useMutation(api.functions.myMutationFunction)
function handleButtonPress() {
// fire and forget, the most common way to use mutations
......@@ -82,6 +85,6 @@ function handleButtonPress() {
}
```
The Convex CLI is your friend. See everything it can do by running
`npx convex -h` in your project root directory. To learn more, launch the docs
with `npx convex docs`.
Use the Convex CLI to push your functions to a deployment. See everything
the Convex CLI can do by running `npx convex -h` in your project root
directory. To learn more, launch the docs with `npx convex docs`.
......@@ -4,7 +4,7 @@
*
* THIS CODE IS AUTOMATICALLY GENERATED.
*
* Generated by convex@0.19.0.
* Generated by convex@1.2.1.
* To regenerate, run `npx convex dev`.
* @module
*/
......
......@@ -4,7 +4,7 @@
*
* THIS CODE IS AUTOMATICALLY GENERATED.
*
* Generated by convex@0.19.0.
* Generated by convex@1.2.1.
* To regenerate, run `npx convex dev`.
* @module
*/
......
......@@ -4,7 +4,7 @@
*
* THIS CODE IS AUTOMATICALLY GENERATED.
*
* Generated by convex@0.19.0.
* Generated by convex@1.2.1.
* To regenerate, run `npx convex dev`.
* @module
*/
......
......@@ -4,7 +4,7 @@
*
* THIS CODE IS AUTOMATICALLY GENERATED.
*
* Generated by convex@0.19.0.
* Generated by convex@1.2.1.
* To regenerate, run `npx convex dev`.
* @module
*/
......@@ -14,11 +14,11 @@ import {
HttpActionBuilder,
MutationBuilder,
QueryBuilder,
ActionCtx as GenericActionCtx,
MutationCtx as GenericMutationCtx,
QueryCtx as GenericQueryCtx,
DatabaseReader as GenericDatabaseReader,
DatabaseWriter as GenericDatabaseWriter,
GenericActionCtx,
GenericMutationCtx,
GenericQueryCtx,
GenericDatabaseReader,
GenericDatabaseWriter,
} from "convex/server";
import type { DataModel } from "./dataModel.js";
......@@ -73,7 +73,7 @@ export declare const internalMutation: MutationBuilder<DataModel, "internal">;
* @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.
*/
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).
......@@ -81,7 +81,7 @@ export declare const action: ActionBuilder<"public">;
* @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.
*/
export declare const internalAction: ActionBuilder<"internal">;
export declare const internalAction: ActionBuilder<DataModel, "internal">;
/**
* Define an HTTP action.
......@@ -120,7 +120,7 @@ export type MutationCtx = GenericMutationCtx<DataModel>;
* The action context is passed as the first argument to any Convex action
* 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.
......
......@@ -4,7 +4,7 @@
*
* THIS CODE IS AUTOMATICALLY GENERATED.
*
* Generated by convex@0.19.0.
* Generated by convex@1.2.1.
* To regenerate, run `npx convex dev`.
* @module
*/
......
......@@ -16,7 +16,8 @@
"module": "ESNext",
"moduleResolution": "Node",
"isolatedModules": true,
"noEmit": true
"noEmit": true,
"skipLibCheck": true
},
"include": ["./**/*"],
"exclude": ["./_generated"]
......
......@@ -10,7 +10,7 @@
"start": "next start"
},
"dependencies": {
"convex": "~0.19.0",
"convex": "~1.2.1",
"next": "latest",
"react": "^18.2.0",
"react-dom": "^18.2.0"
......@@ -20,6 +20,6 @@
"@types/react-dom": "18.0.11",
"@types/react": "18.2.8",
"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