server.js
These exports are not directly available in the convex
package!
Instead you must run npx convex dev
to create convex/_generated/server.js
and convex/_generated/server.d.ts
.
Generated utilities for implementing server-side Convex query and mutation functions.
Functions
query
▸ query(func
): RegisteredQuery
Define a query in this Convex app's public API.
This function will be allowed to read your Convex database and will be accessible from the client.
This is an alias of queryGeneric
that is
typed for your app's data model.
Parameters
Name | Description |
---|---|
func | The query function. It receives a QueryCtx as its first argument. |
Returns
The wrapped query. Include this as an export
to name it and make it
accessible.
internalQuery
▸ internalQuery(func
):
RegisteredQuery
Define a query that is only accessible from other Convex functions (but not from the client).
This function will be allowed to read from your Convex database. It will not be accessible from the client.
This is an alias of
internalQueryGeneric
that is typed
for your app's data model.
Parameters
Name | Description |
---|---|
func | The query function. It receives a QueryCtx as its first argument. |
Returns
The wrapped query. Include this as an export
to name it and make it
accessible.
mutation
▸ mutation(func
):
RegisteredMutation
Define a mutation in this Convex app's public API.
This function will be allowed to modify your Convex database and will be accessible from the client.
This is an alias of mutationGeneric
that is typed for your app's data model.
Parameters
Name | Description |
---|---|
func | The mutation function. It receives a MutationCtx as its first argument. |
Returns
The wrapped mutation. Include this as an export
to name it and make it
accessible.
internalMutation
▸ internalMutation(func
):
RegisteredMutation
Define a mutation that is only accessible from other Convex functions (but not from the client).
This function will be allowed to read and write from your Convex database. It will not be accessible from the client.
This is an alias of
internalMutationGeneric
that is
typed for your app's data model.
Parameters
Name | Description |
---|---|
func | The mutation function. It receives a MutationCtx as its first argument. |
Returns
The wrapped mutation. Include this as an export
to name it and make it
accessible.
action
▸ action(func
): RegisteredAction
Define an action in this Convex app's public API.
An action is a function which can execute any JavaScript code, including
non-deterministic code and code with side-effects, like calling third-party
services. They can be run in Convex's JavaScript environment or in Node.js using
the "use node"
directive. They can interact with the database indirectly by
calling queries and mutations using the ActionCtx
.
This is an alias of actionGeneric
that is
typed for your app's data model.
Parameters
Name | Description |
---|---|
func | The action function. It receives an ActionCtx as its first argument. |
Returns
The wrapped function. Include this as an export
to name it and make it
accessible.
internalAction
▸ internalAction(func
):
RegisteredAction
Define an action that is only accessible from other Convex functions (but not from the client).
This is an alias of
internalActionGeneric
that is
typed for your app's data model.
Parameters
Name | Description |
---|---|
func | The action function. It receives an ActionCtx as its first argument. |
Returns
The wrapped action. Include this as an export
to name it and make it
accessible.
httpAction
▸
httpAction(func: (ctx: ActionCtx, request: Request) => Promise<Response>
):
PublicHttpAction
Parameters
Name | Type | Description |
---|---|---|
func | (ctx: ActionCtx, request: Request) => Promise<Response> | The function. It receives an ActionCtx as its first argument and a Request as its second argument. |
Returns
The wrapped function. Import this function from convex/http.js
and route it to
hook it up.
Types
QueryCtx
Ƭ QueryCtx: Object
A set of services for use within Convex query functions.
The query context is passed as the first argument to any Convex query function run on the server.
This differs from the MutationCtx because all of the services are read-only.
This is an alias of GenericQueryCtx
that is typed for your app's data model.
Type declaration
Name | Type |
---|---|
db | DatabaseReader |
auth | Auth |
storage | StorageReader |
MutationCtx
Ƭ MutationCtx: Object
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.
This is an alias of
GenericMutationCtx
that is typed
for your app's data model.
Type declaration
Name | Type |
---|---|
db | DatabaseWriter |
auth | Auth |
storage | StorageWriter |
scheduler | Scheduler |
ActionCtx
Ƭ ActionCtx: Object
A set of services for use within Convex action functions.
The action context is passed as the first argument to any Convex action function run on the server.
This is an alias of ActionCtx
that is typed
for your app's data model.
Type declaration
Name | Type |
---|---|
runQuery | (name : string , args ?: Record<string, Value> ) => Promise<Value> |
runMutation | (name : string , args ?: Record<string, Value> ) => Promise<Value> |
runAction | (name : string , args ?: Record<string, Value> ) => Promise<Value> |
auth | Auth |
scheduler | Scheduler |
storage | StorageActionWriter |
vectorSearch | (tableName : string , indexName : string , query : VectorSearchQuery ) => Promise<Array<{ _id: Id, _score: number }>> |
DatabaseReader
An interface to read from the database within Convex query functions.
This is an alias of
GenericDatabaseReader
that is
typed for your app's data model.
DatabaseWriter
An interface to read from and write to the database within Convex mutation functions.
This is an alias of
GenericDatabaseWriter
that is
typed for your app's data model.