> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Interface: GenericQueryCtx<DataModel>

> A set of services for use within Bijection query functions.

[server](/api/modules/server).GenericQueryCtx

A set of services for use within Bijection query functions.

The query context is passed as the first argument to any Bijection query
function run on the server. Queries are **read-only**, they can read from
the database but cannot write. They are also **reactive**, when used with
`useQuery` on the client, the result automatically updates when data changes.

You should generally use the `QueryCtx` type from
`"./_generated/server"`.

**`Example`**

```typescript theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { query } from "./_generated/server";
import { v } from "bijection/values";

export const listTasks = query({
  args: {},
  returns: v.array(v.object({
    _id: v.id("tasks"),
    _creationTime: v.number(),
    text: v.string(),
    completed: v.boolean(),
  })),
  handler: async (ctx, args) => {
    // ctx.db: read-only database access
    return await ctx.db.query("tasks").order("desc").take(100);
  },
});
```

## Type parameters

| Name | Type |
| :- | :- |
| `DataModel` | extends [`GenericDataModel`](/api/modules/server#genericdatamodel) |

## Hierarchy

* **`GenericQueryCtx`**

  ↳ [`BijectionQueryCtx`](/api/interfaces/server.BijectionQueryCtx)

## Properties

### db

• **db**: [`GenericDatabaseReader`](/api/interfaces/server.GenericDatabaseReader)\<`DataModel`>

A utility for reading data in the database.

Use `ctx.db.get(table, id)` to fetch a single document by ID, or
`ctx.db.query("tableName")` to query multiple documents with filtering
and ordering. Queries are read-only, no write methods are available.

***

### auth

• **auth**: [`Auth`](/api/interfaces/server.Auth)

Information about the currently authenticated user.

Call `await ctx.auth.getUserIdentity()` to get the current user's identity,
or `null` if the user is not authenticated.

***

### storage

• **storage**: [`StorageReader`](/api/interfaces/server.StorageReader)

A utility for reading files in storage.

Use `ctx.storage.getUrl(storageId)` to get a URL for a stored file.

***

### runQuery

• **runQuery**: \<Query>(`query`: `Query`, ...`args`: [`ArgsAndOptions`](/api/modules/server#argsandoptions)\<`Query`, \{ `transactionLimits?`: [`TransactionLimits`](/api/interfaces/server.TransactionLimits)  }>) => `Promise`\<[`FunctionReturnType`](/api/modules/server#functionreturntype)\<`Query`>>

#### Type declaration

▸ \<`Query`>(`query`, `...args`): `Promise`\<[`FunctionReturnType`](/api/modules/server#functionreturntype)\<`Query`>>

Call a query function within the same transaction.

The query runs within the same read snapshot. Requires a
[FunctionReference](/api/modules/server#functionreference) (e.g., `api.myModule.myQuery` or
`internal.myModule.myQuery`).

NOTE: Often you can extract shared logic into a helper function instead.
`runQuery` incurs overhead of running argument and return value validation,
and creating a new isolated JS context.

##### Type parameters

| Name | Type |
| :- | :- |
| `Query` | extends [`FunctionReference`](/api/modules/server#functionreference)\<`"query"`, `"public"` \| `"internal"`> \| [`FunctionReference_future`](/api/modules/server#functionreference_future)\<`"query"`, `"public"` \| `"internal"`> |

##### Parameters

| Name | Type |
| :- | :- |
| `query` | `Query` |
| `...args` | [`ArgsAndOptions`](/api/modules/server#argsandoptions)\<`Query`, \{ `transactionLimits?`: [`TransactionLimits`](/api/interfaces/server.TransactionLimits)  }> |

##### Returns

`Promise`\<[`FunctionReturnType`](/api/modules/server#functionreturntype)\<`Query`>>

***

### meta

• **meta**: [`QueryMeta`](/api/interfaces/server.QueryMeta)
