filter_greater_than_or_equal_to: NotionRubyMapping 解説 (75)

はじめに

NotionRubyMapping 解説の第74回目です。今日は数値プロパティにおいてある値より大きいか等しい場合だけを抽出する filter_greater_than_or_equal_to を確認してみます。以前使っていたデータベースを取得します。

parent

irb(main):002> db = Database.find "https://www.notion.so/hkob/cad035c49e5346e78331cb5d05cbc754?v=a03e96ed79ad4d35808e7a08583396a0&pvs=4"
=> NotionRubyMapping::Database-cad035c49e5346e78331cb5d05cbc754

query_database のみ

まず何もフィルタをかけないデータベースの検索で件数が3件になることを確認します。

irb(main):003> db.query_database.count
=> 3

NumberProperty

filter_greater_than_or_equal_to は指定された値よりも大きいか等しいものを抽出するものです。これは特に問題ないと思います。

irb(main):004> dps = db.properties
=> PropertyCache
irb(main):005> db.query_database(dps["Number"].filter_greater_than_or_equal_to 3).count
=> 1

FormulaProperty

FormulaProperty の場合には、Formula の型を教えてあげる必要があります。今回は number 型なので、another_type に number を追加で渡します。

irb(main):006> db.query_database(dps["Formula"].filter_greater_than_or_equal_to 3, another_type: "number").count
=> 3

RollupProperty

RollupProperty の場合には、Formula と同様に another_type が必要です。また、返り値が配列の場合には、condition も必要になります。condition には every, any, none が存在します。

irb(main):007> db.query_database(dps["Rollup"].filter_greater_than_or_equal_to 3, condition: "every", another_type: "number").count
=> 0
irb(main):008> db.query_database(dps["Rollup"].filter_greater_than_or_equal_to 3, condition: "any", another_type: "number").count
=> 1
irb(main):009> db.query_database(dps["Rollup"].filter_greater_than_or_equal_to 3, condition: "none", another_type: "number").count
=> 2

おわりに

今日は、filter_greater_than_or_equal_to を解説しました。また、これまで解説していなかった Formula と Rollup プロパティにおける追加指定の説明も同時に実施しました。

NumberProperty のマニュアルはこちらです。その他のプロパティもここから見てください。

NumberProperty

NotionRubyMapping解説