v0.7.0

QUERY 運算式

最後更新

本頁說明 QUERY 如何依欄位篩選 JSON 文件、其運算式文法,以及如何在 Go 中建立相同的 filter。

QUERY

QUERY active = true
QUERY profile.level >= 3
QUERY role = admin AND active = true LIMIT 20
QUERY (role = admin OR role = editor) AND NOT disabled = true

只有具已預熱解析快取的 JSON 項目會被評估。條件讀取點記法欄位,以 utils.Vtoa 呈現(1.0 變為 1,true 維持 true),再以運算子比較。欄位不存在時條件為 false,NE 亦同。

每行結果為 key: <raw JSON>,而非只有鍵。

運算式文法

expression := or
or         := and ( OR and )*
and        := not ( AND not )*
not        := NOT not | primary
primary    := "(" expression ")" | field operator value

程式化篩選

f := filter.And{
    filter.GTE{Field: "profile.level", Value: "3"},
    filter.Not{filter.EQ{Field: "disabled", Value: "true"}},
}
rows := torii.Query(f, 20)

parsed, err := filter.AtoFilter("role = admin OR role = editor")
型別 種類
And、Or []Filter
Not [1]Filter
Cond{Field, Op, Value} 通用條件
EQ、NE、GT、GTE、GE、LT、LTE、LE、LIKE {Field, Value} 簡寫

相關頁面

EN