---
title: "Data, files and jobs"
description: "Your own tables and functions beside the backend component: live queries in Vue, data rendered on the server, typed refusals, search, counts, checked uploads, share links, retention and background work, on Convex."
canonical_url: "https://nuxt-backend.dev/docs/build/data"
---
# Data, files and jobs

> Your own tables and functions beside the backend component: live queries in Vue, data rendered on the server, typed refusals, search, counts, checked uploads, share links, retention and background work, on Convex.

Version: nuxt-backend 0.6.x · Tab: Build · Kind: landing · Status: stable

Every page: [llms.txt](https://nuxt-backend.dev/llms.txt) · Skill for coding agents: [nuxt-backend](https://nuxt-backend.dev/.well-known/skills/nuxt-backend/SKILL.md)

Commands use npm; use your project's package manager.

- [Try it live in the playground](https://nuxt-backend.dev/playground/strips)

This is the part of the backend you build on. Your tables sit in your own schema, beside the ones the `backend` component keeps, and your functions guard them with an access tier. Pages read them live, render them on the server first, and learn why a call was refused. Around them come what a client app needs next: search, counts, uploads, share links, retention and work that runs in the background. It is two of the package's [capabilities](https://nuxt-backend.dev/docs/start/concepts/capabilities): `data`, the database and what reads it, and `jobs`, the work that runs outside a request. New here? Start with [Your data](https://nuxt-backend.dev/docs/build/data/your-data), then [Query and update data](https://nuxt-backend.dev/docs/build/data/read-write).

It runs on [Convex](https://nuxt-backend.dev/docs/services/convex): the database, its realtime queries, search indexes, file storage and scheduler, and the official Convex components. The package adds the access tiers, typed refusals, checked uploads with EXIF stripping and byte quotas, expiring private URLs, share links and retention rules, and composables that follow one set of [conventions](https://nuxt-backend.dev/docs/reference/nuxt/conventions). Nothing here hides Convex: a plain `query`, `mutation` or `action` is always a valid choice, and counters, caches, queues and migrations come straight from their components.

## How it works

```text
backend/schema.ts      your tables, beside the backend component's own
backend/*.ts           your queries, mutations and actions, each behind an access tier
  ├─ Vue pages         useQuery, useMutation, useAction: live over one WebSocket
  ├─ server render     useAsyncQuery: rendered with the data, then live in the browser
  └─ Nitro routes      fetchQuery, backendAuth(event)
backend/storage.ts     checked uploads, owner records, expiring URLs, share links
backend/crons.ts       your jobs and retention rules; the component runs its own
```

1. **Model.** Declare your tables in `backend/schema.ts`, with account and workspace ids as strings. See [Your data](https://nuxt-backend.dev/docs/build/data/your-data).
2. **Protect.** Declare every function at its tier: signed in, a workspace member, an administrator, a role or a plan's feature. See [Protect backend functions](https://nuxt-backend.dev/docs/build/auth/access/functions) and [Scope tables to a workspace](https://nuxt-backend.dev/docs/build/data/read-write/workspace-scoped).
3. **Read and write.** A page subscribes to a query and re-renders whenever its result changes, in every open tab. A mutation writes in one transaction; an action calls the outside world. See [Query and update data](https://nuxt-backend.dev/docs/build/data/read-write).
4. **Render on the server.** `useAsyncQuery` fetches during the server render, as the signed-in person, and the browser goes live without a second fetch. See [Render data on the server](https://nuxt-backend.dev/docs/build/data/read-write/server-rendering).
5. **Refuse with a reason.** A refusal carries a stable code and its data, which a page reads with `getBackendError`. See [Handle errors](https://nuxt-backend.dev/docs/build/data/read-write/errors).
6. **Search and count.** Search indexes beside your tables, and aggregates and counters that stay fast at any size. See [Search your data](https://nuxt-backend.dev/docs/build/data/read-write/search) and [Keep counts and sums](https://nuxt-backend.dev/docs/build/data/read-write/aggregates).
7. **Store files.** Uploads checked on the server and stripped of location data, stored with their row in one mutation, shown to who may see them and shared by link. See [Files](https://nuxt-backend.dev/docs/build/data/files).
8. **Keep it small.** Delete rows once they pass an age, and run work on a clock, in steps or in bulk. See [Delete old data on a schedule](https://nuxt-backend.dev/docs/build/data/retention) and [Background work](https://nuxt-backend.dev/docs/build/data/jobs).

## Who does what

<table>
<thead>
  <tr>
    <th>
      
    </th>
    
    <th>
      Convex
    </th>
    
    <th>
      The package
    </th>
    
    <th>
      Your app
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      Database
    </td>
    
    <td>
      Tables, indexes, transactions, realtime subscriptions
    </td>
    
    <td>
      The <code>
        backend
      </code>
      
       component's own tables, which it migrates and prunes itself
    </td>
    
    <td>
      <code>
        backend/schema.ts
      </code>
      
       and every table in it
    </td>
  </tr>
  
  <tr>
    <td>
      Functions
    </td>
    
    <td>
      Queries, mutations, actions and HTTP routes
    </td>
    
    <td>
      Access tiers (<code>
        createFunctions
      </code>
      
      ), typed refusals (<code>
        backendError
      </code>
      
      ), the server helpers in Nitro
    </td>
    
    <td>
      Every function in <code>
        backend/
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Search and counts
    </td>
    
    <td>
      Search indexes; the aggregate and sharded counter components
    </td>
    
    <td>
      <code>
        defineSearch
      </code>
      
      , <code>
        useSearch
      </code>
    </td>
    
    <td>
      The indexes and aggregates you declare
    </td>
  </tr>
  
  <tr>
    <td>
      Files
    </td>
    
    <td>
      File storage, upload URLs, <code>
        ctx.storage
      </code>
      
       in mutations
    </td>
    
    <td>
      <code>
        setupStorage
      </code>
      
      : sniffed types, EXIF stripping, file and byte quotas, owner records, expiring URLs, share links, the orphan sweep; <code>
        <UploadField>
      </code>
      
      , over the base module's <code>
        useUploadQueue
      </code>
    </td>
    
    <td>
      What each file is attached to, and who may share what
    </td>
  </tr>
  
  <tr>
    <td>
      Retention
    </td>
    
    <td>
      The scheduler and crons
    </td>
    
    <td>
      <code>
        defineRetention
      </code>
      
      , and the hourly maintenance of the component's own tables
    </td>
    
    <td>
      How long each of your tables keeps its rows
    </td>
  </tr>
  
  <tr>
    <td>
      Background work
    </td>
    
    <td>
      The scheduler, crons, and the workflow, workpool, action cache and migrations components
    </td>
    
    <td>
      <code>
        setupWorkflows
      </code>
      
      , <code>
        useWorkflowStatus
      </code>
    </td>
    
    <td>
      Your jobs
    </td>
  </tr>
</tbody>
</table>

The `backend` component keeps accounts and sessions, workspaces and invitations, the billing cache, gifts, files and their owners, AI request records, the activity trail, flag overrides, email records and account exports. You reach them through the package's functions and composables, never through your schema, and the component deletes what it no longer needs on its own. It never reads or deletes your tables. [How it works](https://nuxt-backend.dev/docs/start/concepts/how-it-works) maps each capability to its component.

## In development and in production

- **In development** the app runs on a dev deployment that `npx nuxt-backend dev` creates on its first run, local or in the cloud. Both capabilities read `test` there: the amber light in `npx nuxt-backend status`. See [Develop on real sandboxes](https://nuxt-backend.dev/docs/develop/sandboxes).
- **In tests** `defineBackendTestApp` from `nuxt-backend/test` registers the scaffold's components for `convex-test`, and the backend mock answers your pages' queries. See [Test your app](https://nuxt-backend.dev/docs/develop/testing).
- **In production** the deployment is a cloud or self-hosted one, and both capabilities read `live`, the green light. Choose its region when you create it: [Convex](https://nuxt-backend.dev/docs/services/convex) explains the cost and the move. See [Deploy](https://nuxt-backend.dev/docs/ship/deploy).
- **Watching it.** `npx nuxt-backend status` and the DevTools Overview tab show both capabilities' state and each maintenance pass. See [Capabilities](https://nuxt-backend.dev/docs/start/concepts/capabilities).

## Which tool to use

<table>
<thead>
  <tr>
    <th>
      You want to
    </th>
    
    <th>
      Use
    </th>
    
    <th>
      Page
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      Add a table of your own, keyed to accounts or workspaces
    </td>
    
    <td>
      <code>
        backend/schema.ts
      </code>
      
      , and a tier from <code>
        createFunctions
      </code>
    </td>
    
    <td>
      <a href="https://nuxt-backend.dev/docs/build/data/your-data">
        Your data
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      Keep each workspace's rows to its members
    </td>
    
    <td>
      The <code>
        workspace
      </code>
      
       tier and an index on <code>
        workspaceId
      </code>
    </td>
    
    <td>
      <a href="https://nuxt-backend.dev/docs/build/data/read-write/workspace-scoped">
        Scope tables to a workspace
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      Show data that updates live, and write it
    </td>
    
    <td>
      <code>
        useQuery
      </code>
      
      , <code>
        useMutation
      </code>
      
      , <code>
        useAction
      </code>
    </td>
    
    <td>
      <a href="https://nuxt-backend.dev/docs/build/data/read-write">
        Query and update data
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      Load a long list a page at a time
    </td>
    
    <td>
      <code>
        usePaginatedQuery
      </code>
    </td>
    
    <td>
      <a href="https://nuxt-backend.dev/docs/build/data/read-write#pagination">
        Query and update data
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      Render a page with its data on the first load
    </td>
    
    <td>
      <code>
        useAsyncQuery
      </code>
      
      , <code>
        useAsyncPaginatedQuery
      </code>
    </td>
    
    <td>
      <a href="https://nuxt-backend.dev/docs/build/data/read-write/server-rendering">
        Render data on the server
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      Show why a call was refused, or refuse one yourself
    </td>
    
    <td>
      <code>
        getBackendError
      </code>
      
      , <code>
        backendError
      </code>
    </td>
    
    <td>
      <a href="https://nuxt-backend.dev/docs/build/data/read-write/errors">
        Handle errors
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      Find rows by the words in a text field
    </td>
    
    <td>
      <code>
        defineSearch
      </code>
      
      , <code>
        useSearch
      </code>
    </td>
    
    <td>
      <a href="https://nuxt-backend.dev/docs/build/data/read-write/search">
        Search your data
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      Show a count or a sum without reading every row
    </td>
    
    <td>
      <code>
        @convex-dev/aggregate
      </code>
      
      , <code>
        @convex-dev/sharded-counter
      </code>
    </td>
    
    <td>
      <a href="https://nuxt-backend.dev/docs/build/data/read-write/aggregates">
        Keep counts and sums
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      Delete rows once they pass an age
    </td>
    
    <td>
      <code>
        defineRetention
      </code>
    </td>
    
    <td>
      <a href="https://nuxt-backend.dev/docs/build/data/retention">
        Delete old data on a schedule
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      Accept uploads under a size, type and byte limit, with location data removed
    </td>
    
    <td>
      <code>
        setupStorage
      </code>
      
      , <code>
        storage.store
      </code>
      
      , <code>
        useUpload
      </code>
      
      , <code>
        <UploadField>
      </code>
    </td>
    
    <td>
      <a href="https://nuxt-backend.dev/docs/build/data/files/checked-uploads">
        Accept checked uploads
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      Show stored images at the size a page needs
    </td>
    
    <td>
      <code>
        <StorageImage>
      </code>
      
      , <code>
        <NuxtImg provider="backend">
      </code>
    </td>
    
    <td>
      <a href="https://nuxt-backend.dev/docs/build/data/files/images">
        Show images
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      Serve a private file for a set time
    </td>
    
    <td>
      <code>
        storage.signedUrl
      </code>
    </td>
    
    <td>
      <a href="https://nuxt-backend.dev/docs/build/data/files/images#serve-a-private-file-for-a-while">
        Show images
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      Let a person share a row by link
    </td>
    
    <td>
      <code>
        storage.shareable
      </code>
      
      , <code>
        useShareLink
      </code>
    </td>
    
    <td>
      <a href="https://nuxt-backend.dev/docs/build/data/files/share-links">
        Share by link
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      Run steps over minutes or days that survive restarts
    </td>
    
    <td>
      <code>
        setupWorkflows
      </code>
      
      , <code>
        useWorkflowStatus
      </code>
    </td>
    
    <td>
      <a href="https://nuxt-backend.dev/docs/build/data/jobs/workflows">
        Run a durable workflow
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      Run a job on a schedule
    </td>
    
    <td>
      <code>
        cronJobs()
      </code>
      
      , <code>
        @convex-dev/crons
      </code>
    </td>
    
    <td>
      <a href="https://nuxt-backend.dev/docs/build/data/jobs/scheduled">
        Schedule jobs
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      Run many jobs a few at a time, with retries
    </td>
    
    <td>
      <code>
        @convex-dev/workpool
      </code>
    </td>
    
    <td>
      <a href="https://nuxt-backend.dev/docs/build/data/jobs/workpool">
        Queue work with a workpool
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      Keep an expensive action's results for a while
    </td>
    
    <td>
      <code>
        @convex-dev/action-cache
      </code>
    </td>
    
    <td>
      <a href="https://nuxt-backend.dev/docs/build/data/jobs/action-cache">
        Cache expensive actions
      </a>
    </td>
  </tr>
  
  <tr>
    <td>
      Change existing documents in batches
    </td>
    
    <td>
      <code>
        @convex-dev/migrations
      </code>
    </td>
    
    <td>
      <a href="https://nuxt-backend.dev/docs/build/data/jobs/migrations">
        Migrate data
      </a>
    </td>
  </tr>
</tbody>
</table>

## What you get

What the package ships for this part of the app today, generated from the code: each name links to its reference entry.

- Components: [`<ConnectionStatus>`](https://nuxt-backend.dev/docs/reference/components/shell#connectionstatus), [`<UploadField>`](https://nuxt-backend.dev/docs/reference/components/shell#uploadfield)
- Composables: [`useConnectionState`](https://nuxt-backend.dev/docs/reference/nuxt/composables#at-a-glance), [`useBackendClient`](https://nuxt-backend.dev/docs/reference/nuxt/composables#at-a-glance), [`useSearch`](https://nuxt-backend.dev/docs/reference/api/use-search), [`useRoomPresence`](https://nuxt-backend.dev/docs/reference/nuxt/composables#at-a-glance), [`useShareLink`](https://nuxt-backend.dev/docs/reference/nuxt/composables#at-a-glance), [`useUploadField`](https://nuxt-backend.dev/docs/reference/nuxt/composables#at-a-glance), [`preparePhoto`](https://nuxt-backend.dev/docs/reference/nuxt/composables#at-a-glance), [`isPhotoFile`](https://nuxt-backend.dev/docs/reference/nuxt/composables#at-a-glance), [`PhotoPrepError`](https://nuxt-backend.dev/docs/reference/nuxt/composables#at-a-glance), [`getBackendError`](https://nuxt-backend.dev/docs/reference/nuxt/composables#at-a-glance), [`useWorkflowStatus`](https://nuxt-backend.dev/docs/reference/api/use-workflow)
- Setup helpers: [`defineRetention`](https://nuxt-backend.dev/docs/reference/api/functions), [`setupPresence`](https://nuxt-backend.dev/docs/reference/api/presence), [`defineSearch`](https://nuxt-backend.dev/docs/reference/api/search), [`setupWorkflows`](https://nuxt-backend.dev/docs/reference/api/workflows), [`setupStorage`](https://nuxt-backend.dev/docs/reference/api/storage)

## In this section

<card-group>
<card icon="i-lucide-table-2" title="Your data" to="https://nuxt-backend.dev/docs/build/data/your-data">

Where your tables go, how they point at accounts and workspaces, and how they join export and erasure.

</card>

<card icon="i-lucide-building-2" title="Scope tables to a workspace" to="https://nuxt-backend.dev/docs/build/data/read-write/workspace-scoped">

Stamp, index and check the active workspace, and gate writes by the member's role.

</card>

<card icon="i-lucide-zap" title="Query and update data" to="https://nuxt-backend.dev/docs/build/data/read-write">

Read live data with `useQuery`, write with `useMutation`, call actions, paginate, and ride out a dropped connection.

</card>

<card icon="i-lucide-server" title="Render data on the server" to="https://nuxt-backend.dev/docs/build/data/read-write/server-rendering">

Pages that arrive with their data, signed-in reads included, and go live in the browser.

</card>

<card icon="i-lucide-octagon-alert" title="Handle errors" to="https://nuxt-backend.dev/docs/build/data/read-write/errors">

Read a refusal's stable code on the client, and refuse from your own functions with the same codes.

</card>

<card icon="i-lucide-search" title="Search your data" to="https://nuxt-backend.dev/docs/build/data/read-write/search">

Search a table's text with a builder checked against your schema, and drive it from an input.

</card>

<card icon="i-lucide-sigma" title="Keep counts and sums" to="https://nuxt-backend.dev/docs/build/data/read-write/aggregates">

Counts and sums from the aggregate component, and counters that take many writers at once.

</card>

<card icon="i-lucide-hourglass" title="Delete old data on a schedule" to="https://nuxt-backend.dev/docs/build/data/retention">

Retention rules in bounded batches, and tokens stored as hashes.

</card>
</card-group>

## Files

<card-group>
<card icon="i-lucide-folder-up" title="Files" to="https://nuxt-backend.dev/docs/build/data/files">

How uploads are checked, owned, shown, shared and swept.

</card>

<card icon="i-lucide-file-check" title="Accept checked uploads" to="https://nuxt-backend.dev/docs/build/data/files/checked-uploads">

`setupStorage`, a photo stored with its row in one mutation, and upload URLs for large files.

</card>

<card icon="i-lucide-image" title="Show images" to="https://nuxt-backend.dev/docs/build/data/files/images">

`<StorageImage>`, `<NuxtImg>` sizes, and expiring private URLs.

</card>

<card icon="i-lucide-link" title="Share by link" to="https://nuxt-backend.dev/docs/build/data/files/share-links">

A link to one row, with a preview card and the sharer's referral code.

</card>

<card icon="i-lucide-trash-2" title="Keep storage clean" to="https://nuxt-backend.dev/docs/build/data/files/cleanup">

Release files, the orphan sweep, and a person's files in export and erasure.

</card>
</card-group>

## Background work

<card-group>
<card icon="i-lucide-timer" title="Background work" to="https://nuxt-backend.dev/docs/build/data/jobs">

Which tool runs work outside a request, and what the component's maintenance already runs.

</card>

<card icon="i-lucide-workflow" title="Run a durable workflow" to="https://nuxt-backend.dev/docs/build/data/jobs/workflows">

Durable multi-step functions, and a run's status live in Vue.

</card>

<card icon="i-lucide-calendar-clock" title="Schedule jobs" to="https://nuxt-backend.dev/docs/build/data/jobs/scheduled">

Fixed jobs in `crons.ts`, and per-person schedules with the crons component.

</card>

<card icon="i-lucide-list-ordered" title="Queue work with a workpool" to="https://nuxt-backend.dev/docs/build/data/jobs/workpool">

Many actions a few at a time, with retries and a callback as each ends.

</card>

<card icon="i-lucide-database-zap" title="Cache expensive actions" to="https://nuxt-backend.dev/docs/build/data/jobs/action-cache">

An action's results kept for a while, with expiry and invalidation.

</card>

<card icon="i-lucide-arrow-right-left" title="Migrate data" to="https://nuxt-backend.dev/docs/build/data/jobs/migrations">

Change existing documents in batches, dry-run first, and resume where a run stopped.

</card>
</card-group>

## Not included

- **Another database.** The data lives in your Convex deployment, which is what makes every query live. The package has no adapter for SQL or another store.
- **Who is online.** Presence is a collaboration feature and no part of the package: the [Roadmap](https://nuxt-backend.dev/docs/start/roadmap) says what to use instead.
- **Wrappers over Convex components.** Counters, aggregates, cached actions, queues and migrations come straight from their components, as the recipes above show.

## Next

- New here? Read [Your data](https://nuxt-backend.dev/docs/build/data/your-data), then [Query and update data](https://nuxt-backend.dev/docs/build/data/read-write).
- Charging for what you built: [Billing](https://nuxt-backend.dev/docs/build/billing). Putting it online: [Ship](https://nuxt-backend.dev/docs/ship).


## Sitemap

See the full [sitemap](https://nuxt-backend.dev/sitemap.md) for all pages.
