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

#Condition Tree

condition 是 oor 的中间层。

同一份条件树可以继续交给 SQL、ES 或 Drizzle。

#Node 结构

TypeScript
type Node = {
  link: 'AND' | 'OR'
  items: Array<Node | Atom>
}

type Atom = {
  field: string
  op:
    | 'Equal'
    | 'Not'
    | 'More'
    | 'MoreEqual'
    | 'Less'
    | 'LessEqual'
    | 'Like'
    | 'StartWith'
    | 'EndWith'
    | 'In'
    | 'NotIn'
    | 'Between'
    | 'IsNull'
    | 'NotNull'
  value: unknown
}

#makeNode

TypeScript
import { makeNode } from 'oor'

const node = makeNode({
  statusIn: ['active', 'pending'],
  ageMin: 18
})

默认会得到一棵 AND 条件树。

#withSoft

TypeScript
import { withSoft } from 'oor'

const node = withSoft(
  {
    link: 'OR',
    items: [
      { field: 'status', op: 'Equal', value: 'active' },
      { field: 'status', op: 'Equal', value: 'pending' }
    ]
  },
  {
    soft: {
      mode: 'flag',
      field: 'isDeleted',
      del: true,
      keep: false
    }
  }
)

#soft

  • flag: isDeleted = false
  • time: deletedAt IS NULL

#page 和 sort

TypeScript
import { page, sort } from 'oor'

const p = page({ page: 2, size: 10 })
const s = sort({ sort: 'createdAt', order: 'desc' })
  • page 默认每页 15
  • 支持 _start / _count 和 page / size
  • 支持 _order / _by 和 sort / order
  • meta.page.size、meta.sort 可作为默认值
TypeScript
makeNode(input, meta, { skipSoft: true })
withSoft(node, meta, { skipSoft: true })

#下一步

  • Schema
  • SQLite
  • Drizzle 插件
  • Node 结构
  • makeNode
  • withSoft
  • soft
  • page 和 sort
  • 下一步