Skip to content
Niko Table

Drizzle ORM + Nuqs

The Drizzle ORM server-side table with its state kept in the URL via nuqs, so views can be shared and bookmarked.

This is the Drizzle ORM table with its state stored in the URL via nuqs. Use it when users should be able to share, bookmark or reload a filtered, sorted or paginated view.

  • Same backend. The query code (buildWhere, buildOrderBy, computeFacets) does not change.
  • Different state source. Local useState becomes useQueryStates.

For the details, read the Drizzle ORM guide (SQL layer) and the Server-Side Nuqs Table (URL layer). This page only shows how they combine.

The demo runs this guide’s Drizzle code against a mocked query builder in your browser. It shows the Generated SQL for the current view.

  • Filter or sort, then reload. The URL restores the view.
  • The Category and Brand facets use server-computed counts. They narrow to values still in the results.
drizzle-nuqs-state.tsx
Product Name
Category
Brand
Price
Stock
Rating
In Stock
Release Date
Generated SQL
Filter, search, and sort the table — this is the statement the guide's Drizzle code produces for the current view (the demo executes it with a mocked query builder in your browser).
Loading...
Params: []
0 matching rows, showing 0Executing...

Install the DataTable core and add-ons for this example:

pnpm dlx shadcn@latest add @niko-table/data-table @niko-table/data-table-pagination @niko-table/data-table-search-filter @niko-table/data-table-view-menu @niko-table/data-table-sort-menu @niko-table/data-table-filter-menu @niko-table/data-table-column-sort @niko-table/data-table-faceted-filter @niko-table/data-table-column-faceted-filter @niko-table/data-table-column-slider-filter @niko-table/data-table-column-date-filter

Install additional dependencies:

pnpm add @tanstack/react-query nuqs

First time using @niko-table? See the Installation Guide to set up the registry.

Only the state layer changes. The data fetch, buildWhere, buildOrderBy, computeFacets and the API route stay the same.

  • State lives in the URL. useQueryStates replaces the useState slices for page, sorting, filters, search and column visibility. It uses the same parsers as the Server-Side Nuqs Table.
  • The query key is the URL. TanStack Query keys off the URL state.
    • A shared link hits the same cache entry.
    • An SSR page can run the same query from the incoming search params.
  • filterId is stripped on write (serializeFiltersForUrl) and regenerated on read (normalizeFiltersFromUrl). This keeps URLs short.
  • Filter rules split by type. The advanced menu’s AND rules live in the filters param. OR and MIXED rules move to the global param.

The Category and Brand facets get their options from the server (computeFacets). They need server counts, not counts from the client:

<DataTableFacetedFilter
accessorKey="category"
title="Category"
options={categoryFacetOptions} // server counts, count-0 dropped, selection pinned
multiple
dynamicCounts={false} // don't recount from the client's current page
limitToFilteredRows={false} // don't narrow from client rows either
/>

The client only holds the current page, so the server must count and narrow.

  • dynamicCounts={false} and limitToFilteredRows={false} turn off the client-side passes.
  • The example narrows the list itself. It drops count === 0 options but keeps any selected value so you can still remove it.

✅ Use Drizzle ORM + Nuqs when:

  • You use the Drizzle ORM server-side table
  • Views must be shareable, bookmarkable, or survive a refresh
  • You want SSR to render the first paint from the URL search params

❌ Consider other options when:

  • A clean URL matters more than shareability: use the Drizzle ORM guide as is
  • You do not use Drizzle: the Server-Side Nuqs Table shows the same URL layer over a database-agnostic API