v0.4.0 f6d8405

README.md RawHistoryFolder

Welcome to your Convex functions directory!

Write your Convex functions here. See https://docs.convex.dev/functions for more.

A query function that takes two arguments looks like:

// convex/myFunctions.ts
import { query } from './_generated/server';
import { v } from 'convex/values';

export const myQueryFunction = query({
	// Validators for arguments.
	args: {
		first: v.number(),
		second: v.string()
	},

	// Function implementation.
	handler: async (ctx, args) => {
		// Read the database as many times as you need here.
		// See https://docs.convex.dev/database/reading-data.
		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.
		return documents;
	}
});

Using this query function in a React component looks like:

const data = useQuery(api.myFunctions.myQueryFunction, {
	first: 10,
	second: 'hello'
});

A mutation function looks like:

// convex/myFunctions.ts
import { mutation } from './_generated/server';
import { v } from 'convex/values';

export const myMutationFunction = mutation({
	// Validators for arguments.
	args: {
		first: v.string(),
		second: v.string()
	},

	// Function implementation.
	handler: 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: args.first, author: args.second };
		const id = await ctx.db.insert('messages', message);

		// Optionally, return a value from your mutation.
		return await ctx.db.get('messages', id);
	}
});

Using this mutation function in a React component looks like:

const mutation = useMutation(api.myFunctions.myMutationFunction);
function handleButtonPress() {
	// fire and forget, the most common way to use mutations
	mutation({ first: 'Hello!', second: 'me' });
	// OR
	// use the result once the mutation has completed
	mutation({ first: 'Hello!', second: 'me' }).then((result) => console.log(result));
}

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.

source
1# Welcome to your Convex functions directory!
2
3Write your Convex functions here.
4See https://docs.convex.dev/functions for more.
5
6A query function that takes two arguments looks like:
7
8```ts
9// convex/myFunctions.ts
10import { query } from './_generated/server';
11import { v } from 'convex/values';
12
13export const myQueryFunction = query({
14	// Validators for arguments.
15	args: {
16		first: v.number(),
17		second: v.string()
18	},
19
20	// Function implementation.
21	handler: async (ctx, args) => {
22		// Read the database as many times as you need here.
23		// See https://docs.convex.dev/database/reading-data.
24		const documents = await ctx.db.query('tablename').collect();
25
26		// Arguments passed from the client are properties of the args object.
27		console.log(args.first, args.second);
28
29		// Write arbitrary JavaScript here: filter, aggregate, build derived data,
30		// remove non-public properties, or create new objects.
31		return documents;
32	}
33});
34```
35
36Using this query function in a React component looks like:
37
38```ts
39const data = useQuery(api.myFunctions.myQueryFunction, {
40	first: 10,
41	second: 'hello'
42});
43```
44
45A mutation function looks like:
46
47```ts
48// convex/myFunctions.ts
49import { mutation } from './_generated/server';
50import { v } from 'convex/values';
51
52export const myMutationFunction = mutation({
53	// Validators for arguments.
54	args: {
55		first: v.string(),
56		second: v.string()
57	},
58
59	// Function implementation.
60	handler: async (ctx, args) => {
61		// Insert or modify documents in the database here.
62		// Mutations can also read from the database like queries.
63		// See https://docs.convex.dev/database/writing-data.
64		const message = { body: args.first, author: args.second };
65		const id = await ctx.db.insert('messages', message);
66
67		// Optionally, return a value from your mutation.
68		return await ctx.db.get('messages', id);
69	}
70});
71```
72
73Using this mutation function in a React component looks like:
74
75```ts
76const mutation = useMutation(api.myFunctions.myMutationFunction);
77function handleButtonPress() {
78	// fire and forget, the most common way to use mutations
79	mutation({ first: 'Hello!', second: 'me' });
80	// OR
81	// use the result once the mutation has completed
82	mutation({ first: 'Hello!', second: 'me' }).then((result) => console.log(result));
83}
84```
85
86Use the Convex CLI to push your functions to a deployment. See everything
87the Convex CLI can do by running `npx convex -h` in your project root
88directory. To learn more, launch the docs with `npx convex docs`.

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 3

Tags 8

↑↓ moveenter openesc close