@@ -7,8 +7,8 @@ A query function that takes two arguments looks like:
77
88``` ts
99// functions.js
10- import { query } from " ./_generated/server" ;
11- import { v } from " convex/values" ;
10+ import { query } from ' ./_generated/server'
11+ import { v } from ' convex/values'
1212
1313export const myQueryFunction = query ({
1414 // Validators for arguments.
@@ -21,33 +21,33 @@ export const myQueryFunction = query({
2121 handler : async (ctx , args ) => {
2222 // Read the database as many times as you need here.
2323 // See https://docs.convex.dev/database/reading-data.
24- const documents = await ctx .db .query (" tablename" ).collect ();
24+ const documents = await ctx .db .query (' tablename' ).collect ()
2525
2626 // Arguments passed from the client are properties of the args object.
27- console .log (args .first , args .second );
27+ console .log (args .first , args .second )
2828
2929 // Write arbitrary JavaScript here: filter, aggregate, build derived data,
3030 // remove non-public properties, or create new objects.
31- return documents ;
31+ return documents
3232 },
33- });
33+ })
3434```
3535
3636Using this query function in a React component looks like:
3737
3838``` ts
3939const data = useQuery (api .functions .myQueryFunction , {
4040 first: 10 ,
41- second: " hello" ,
42- });
41+ second: ' hello' ,
42+ })
4343```
4444
4545A mutation function looks like:
4646
4747``` ts
4848// functions.js
49- import { mutation } from " ./_generated/server" ;
50- import { v } from " convex/values" ;
49+ import { mutation } from ' ./_generated/server'
50+ import { v } from ' convex/values'
5151
5252export const myMutationFunction = mutation ({
5353 // Validators for arguments.
@@ -61,27 +61,27 @@ export const myMutationFunction = mutation({
6161 // Insert or modify documents in the database here.
6262 // Mutations can also read from the database like queries.
6363 // 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 );
64+ const message = { body: args .first , author: args .second }
65+ const id = await ctx .db .insert (' messages' , message )
6666
6767 // Optionally, return a value from your mutation.
68- return await ctx .db .get (id );
68+ return await ctx .db .get (id )
6969 },
70- });
70+ })
7171```
7272
7373Using this mutation function in a React component looks like:
7474
7575``` ts
76- const mutation = useMutation (api .functions .myMutationFunction );
76+ const mutation = useMutation (api .functions .myMutationFunction )
7777function handleButtonPress() {
7878 // fire and forget, the most common way to use mutations
79- mutation ({ first: " Hello!" , second: " me " });
79+ mutation ({ first: ' Hello!' , second: ' me ' })
8080 // OR
8181 // use the result once the mutation has completed
82- mutation ({ first: " Hello!" , second: " me " }).then ((result ) =>
82+ mutation ({ first: ' Hello!' , second: ' me ' }).then ((result ) =>
8383 console .log (result ),
84- );
84+ )
8585}
8686```
8787
0 commit comments