O
OOR
文档
OOR
文档
简介
Getting Started
安装
快速开始
Query Flow
Core Concepts
Suffix
Schema
Condition Tree
Adapters
SQLite
PostgreSQL / MySQL
Elasticsearch
Integrations
Drizzle Integration
ES Client

#Schema

schema 和 read 用来约束 query input。

#schema

TypeScript
import { schema } from 'oor'
import { z } from 'zod'

const query = schema({
  id: z.number(),
  title: z.string(),
  active: z.boolean(),
  createdAt: z.date()
})

const input = query.parse({
  idIn: [1, 2, 3],
  titleLike: 'oor',
  activeNot: true,
  createdAtDay: '2026-04-08',
  page: '2',
  size: '10'
})

它会同时做:

  • 类型推导
  • 值归一化
  • suffix 合法性校验

#read

TypeScript
import { read } from 'oor'
import { z } from 'zod'

const input = read(
  {
    id: z.number(),
    title: z.string()
  },
  {
    titleStartWith: 'oo'
  }
)

#例子

这些会报错:

TypeScript
read({ age: z.number() }, { ageLike: 'x' })
read({ active: z.boolean() }, { activeLike: 'x' })
read({ createdAt: z.date() }, { createdAtLike: 'x' })

#推荐顺序

  1. 先 schema(...).parse(...)
  2. 再交给 makeNode、querySql、esBody 或 withTable

#下一步

  • Condition Tree
  • SQLite 适配器
  • Elasticsearch 适配器
  • schema
  • read
  • 例子
  • 推荐顺序
  • 下一步