Getting Started
Installation
Section titled “Installation”bun add agnostic-queryThen install only the adapters you need:
# For runtime validationbun add zod # optionalbun add valibot # optional
# For ORM adaptersbun add drizzle-orm # optionalbun add @tanstack/db # optional
# For Kysely adapterbun add kysely # optionalFirst QuerySchema
Section titled “First QuerySchema”Define your shape as a TypeScript interface or type, then build a query with the aq builder:
import { aq } from 'agnostic-query'
type User = { name: string age: number status: string}
const schema = aq<User>() .where('name', '=', 'Alice') .where('age', '>=', 18) .where('status', 'in', ['active', 'pending']) .orderBy('name', 'asc') .limit(20) .toJSON()The output is a plain JSON object:
// schema → {// where: {// op: 'and',// conditions: [// { field: ['name'], op: '=', value: 'Alice' },// { field: ['age'], op: '>=', value: 18 },// { field: ['status'], op: 'in', values: ['active', 'pending'] },// ],// },// orderBy: [{ field: ['name'], direction: 'asc' }],// limit: 20,// }Import Paths
Section titled “Import Paths”// Core types & builderimport { aq, QuerySchema, QueryWhere, QueryOrderBy, findWhere, newComparisonWhere, newWhere } from 'agnostic-query'
// Zod validationimport { createWhereSchema } from 'agnostic-query/zod'
// Valibot validationimport { createWhereSchema } from 'agnostic-query/valibot'
// Drizzle adapterimport { toDrizzle, toDrizzleWhere, toDrizzleOrderBy } from 'agnostic-query/drizzle/pg'
// db0 adapterimport { toDb0 } from 'agnostic-query/db0/pg'
// TanStack DB adapterimport { fromTanDbWhere, fromTanDbOrderBy } from 'agnostic-query/tanstack-db'
// Kysely adapterimport { fromKysely, toKyselyWhere, toKyselyOrderBy } from 'agnostic-query/kysely/pg'
// SQL adapterimport { toSql, toSqlWhere, toSqlOrderBy } from 'agnostic-query/sql/pg'