> For the complete documentation index, see [llms.txt](https://docs.jetadmin.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.jetadmin.io/api-reference/javascript-sdk/collections.md).

# Collections

Use `jet.collection(resourceName, collectionName)` to access records from a configured resource. Examples assume an authenticated `jet` client from [Getting started](/api-reference/javascript-sdk/getting-started.md). Replace sample collection fields with your own schema.

### List and filter

```typescript
import { Jet, QueryLookup } from '@jet-admin/jet-sdk';

async function listActiveCustomers(jet: Jet) {
  const page = await jet.collection('YOUR_RESOURCE', 'customers').list({
    filters: [
      { field: 'status', lookup: QueryLookup.Exact, value: 'active' },
      { field: 'name', lookup: QueryLookup.IContains, value: 'alex' },
    ],
    pagination: { page: 1, perPage: 25 },
    orderBy: { field: 'created_at', desc: true },
  });
  return { rows: page.results.map(record => record.data), hasMore: page.hasMore };
}
```

`list()` also accepts `search: string` for the resource's search behavior. Searchable fields and supported lookup behavior depend on the resource.

| Option               | Sent to the API                                    |
| -------------------- | -------------------------------------------------- |
| `pagination.page`    | `page`                                             |
| `pagination.perPage` | `_per_page`                                        |
| `orderBy.field`      | `_order_by`; prefixed with `-` when `desc` is true |
| `search`             | `_search`                                          |
| `filters`            | One query parameter per field/lookup combination   |

The SDK supplies no pagination defaults and does not follow pages automatically. Start with page 1 where supported by your resource API. The response contains `results: CollectionRecord[]`, optional `hasMore`, and optional `count`. API `next` and `previous` links are not exposed. Use the resource API's pagination contract if `hasMore` is absent; do not treat an absent value as a guaranteed last page.

#### Filter lookups

| Enum member                | Wire suffix                | Intended use, where supported by the resource |
| -------------------------- | -------------------------- | --------------------------------------------- |
| `Exact`                    | No suffix                  | Equality                                      |
| `Gt`, `Gte`, `Lt`, `Lte`   | `gt`, `gte`, `lt`, `lte`   | Comparisons                                   |
| `In`                       | `in`                       | Membership                                    |
| `IContains`                | `icontains`                | Case-insensitive containment                  |
| `IStartsWith`, `IEndsWith` | `istartswith`, `iendswith` | Case-insensitive prefix/suffix                |
| `IsNull`, `IsEmpty`        | `isnull`, `isempty`        | Null/empty checks                             |
| `CoveredBy`                | `coveredby`                | Resource-specific coverage lookup             |
| `JsonIContains`            | `json_icontains`           | Resource-specific JSON containment            |

Nonempty lookups are joined with a single underscore: `age_gte`, for example. Equality sends only the field name. Values are stringified; dates become ISO strings, objects become JSON strings, arrays remain arrays of converted values, and `undefined` is omitted. Axios handles array query serialization. Confirm the resource's expected format for membership filters.

Two filters with the same field and lookup overwrite the same query parameter; the last value wins. There is no SDK OR-group builder.

### Get, create, update, and delete

The functions below are separate examples; call only the operation your UI intends to perform.

```typescript
import { Jet } from '@jet-admin/jet-sdk';

function customers(jet: Jet) {
  return jet.collection('YOUR_RESOURCE', 'customers');
}

async function getCustomer(jet: Jet, id: string) {
  const record = await customers(jet).getOne({ primaryKey: id });
  return record.data;
}

async function createCustomer(jet: Jet, name: string) {
  return customers(jet).create({ data: { name } });
}

async function updateCustomer(jet: Jet, id: string, name: string) {
  return customers(jet).update({
    primaryKey: id,
    data: { name },
    fields: ['name'],
  });
}

async function deleteCustomer(jet: Jet, id: string) {
  const record = await customers(jet).getOne({ primaryKey: id });
  await customers(jet).delete({ primaryKey: id, record });
}
```

| Method   | Required options                                            | Returns            |
| -------- | ----------------------------------------------------------- | ------------------ |
| `getOne` | `primaryKey: string`                                        | `CollectionRecord` |
| `create` | `data: Record<string, unknown>`                             | `CollectionRecord` |
| `update` | `primaryKey`, `data`; optional `fields: string[]`           | `CollectionRecord` |
| `delete` | `primaryKey`, `record: CollectionRecord`; optional `fields` | `void`             |

`update()` sends PATCH. With `fields`, it picks only those keys from `data`; otherwise it sends all supplied data. This is not a returned-field selection.

The current TypeScript signature requires `record` for deletion, although the implementation uses only `primaryKey`. Its optional `fields` value is also ignored. Deletion removes the record; it does not delete selected fields.

Resource names, collection names, and primary keys are interpolated directly into URLs. Use identifiers matching your API's path format.

### Scope

This version has no collection methods for aggregate, group, raw SQL, bulk edits, or resource reload. Those REST endpoints may exist independently; do not call invented methods such as `collection.aggregate()`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.jetadmin.io/api-reference/javascript-sdk/collections.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
