Skip to main content

Interface: GenericMutationCtx<DataModel>

server.GenericMutationCtx

A set of services for use within Convex mutation functions.

The mutation context is passed as the first argument to any Convex mutation function run on the server.

If you're using code generation, use the MutationCtx type in convex/_generated/server.d.ts which is typed for your data model.

Type parameters

NameType
DataModelextends GenericDataModel

Properties

db

db: GenericDatabaseWriter<DataModel>

A utility for reading and writing data in the database.

Defined in

server/registration.ts:50


auth

auth: Auth

Information about the currently authenticated user.

Defined in

server/registration.ts:55


storage

storage: StorageWriter

A utility for reading and writing files in storage.

Defined in

server/registration.ts:60


scheduler

scheduler: Scheduler

A utility for scheduling Convex functions to run in the future.

Defined in

server/registration.ts:65


runQuery

runQuery: <Query>(query: Query, ...args: OptionalRestArgs<Query>) => Promise<FunctionReturnType<Query>>

Type declaration

▸ <Query>(query, ...args): Promise<FunctionReturnType<Query>>

Call a query function within the same transaction.

NOTE: often you can call the query's function directly instead of using this. runQuery incurs overhead of running argument and return value validation, and creating a new isolated JS context.

Type parameters
NameType
Queryextends FunctionReference<"query", "public" | "internal">
Parameters
NameType
queryQuery
...argsOptionalRestArgs<Query>
Returns

Promise<FunctionReturnType<Query>>

Defined in

server/registration.ts:74


runMutation

runMutation: <Mutation>(mutation: Mutation, ...args: OptionalRestArgs<Mutation>) => Promise<FunctionReturnType<Mutation>>

Type declaration

▸ <Mutation>(mutation, ...args): Promise<FunctionReturnType<Mutation>>

Call a mutation function within the same transaction.

NOTE: often you can call the mutation's function directly instead of using this. runMutation incurs overhead of running argument and return value validation, and creating a new isolated JS context.

The mutation runs in a sub-transaction, so if the mutation throws an error, all of its writes will be rolled back. Additionally, a successful mutation's writes will be serializable with other writes in the transaction.

Type parameters
NameType
Mutationextends FunctionReference<"mutation", "public" | "internal">
Parameters
NameType
mutationMutation
...argsOptionalRestArgs<Mutation>
Returns

Promise<FunctionReturnType<Mutation>>

Defined in

server/registration.ts:90