2️⃣
S11. プロパティ要素
11.1 プロパティ要素の分類
- データベースを取得したときの JSON オブジェクト(Property object)
- ページを取得したときの JSON オブジェクト(Property item object)
- データベースを設定するときの JSON オブジェクト (Property schema object)
Start building with the Notion API
Metadata that controls how a database property behaves. Each database property schema object has at least one key which is the property type. This type contains behavior of this property. Possible values of this key are "title", "rich_text", "number", "select", "multi_select", "date", "people", "files", "checkbox", "url", "email", "phone_number", "formula", "relation", "rollup", "created_time", "created_by", "last_edited_time", "last_edited_by".
https://developers.notion.com/reference/property-schema-object
- ページを追加・更新する時の JSON オブジェクト (Property value object)
- データベースを検索するための JSON オブジェクト (Property filter object)
11.2 Property object / Property schema object
プロパティ確認用11.2 で確認するプロパティ確認用データベースです。ブロックハンドル(6点メニュー)から「リンクをコピー」してプロパティ確認用データベースの URL に貼り付けてください。
📝
プロパティ確認用データベースの URL を貼り付けます。
例: https://www.notion.so/hkob/7d16fe15159d40a6b6f8aab255c47e6f?v=7569e5029eb7450eaf6b7e6aae0df1c3
このデータベース URL を用いて、Ruby のデータベースオブジェクトを取得します。取得した JSON の中から
properties キーオブジェクトを取り出しておきます。
11.2.1 設定値がないプロパティ
11.2.2 関数 (formula)
11.2.3 セレクト (select) / マルチセレクト (multi_select)
11.2.4 数値 (number)
11.2.5 リレーション (relation)
11.2.6 ロールアップ (rollup)
"function" に利用可能な関数は以下の通りです。
関数 | 日本語メニュー | 対象の型 | 返り値の型 |
count_all | すべてカウント | すべての型 | 数値 |
count_values | 値の数をカウント | すべての型 | 数値 |
count_unique_values | 一意の値をカウント | 数値・文字列・日付 | 数値 |
count_empty | 未入力をカウント | 数値・文字列・日付 | 数値 |
count_not_empty | 未入力以外をカウント | 数値・文字列・日付 | 数値 |
percent_empty | 未入力の割合 | 数値・文字列・日付 | 数値 |
percent_not_empty | 未入力以外の割合 | 数値・文字列・日付 | 数値 |
checked | チェックあり | ブール値 | 数値 |
unchecked | チェックなし | ブール値 | 数値 |
percent_checked | チェックありの割合 | ブール値 | 数値 |
percent_unchecked | チェックなしの割合 | ブール値 | 数値 |
sum | 合計 | 数値 | 数値 |
average | 平均 | 数値 | 数値 |
median | 中央値 | 数値 | 数値 |
min | 最小 (数値)
最も古い日付 (日付) | 数値
日付 | 数値
日付 |
max | 最大 (数値)
最も新しい日付 (日付) | 数値
日付 | 数値
日付 |
range | 範囲(数値)
日付範囲(日付) | 数値
日付 | 数値
日付範囲 |
show_original | オリジナルを表示する | すべての型 | 配列 |
show_unique | 一意の値を表示する | すべての型 | 配列 |
11.3 Property item object / Property value object
データベース内には二つのページが登録されています。このうち「データ1」ページへのメンションリンクをここに用意しておきました。このページを開き、page URL を取得してください。
データ1 📝
プロパティ確認用ページの URL を貼り付けます。
例: https://www.notion.so/hkob/1-1771b75598ec478a98d3c64b1ae62846
このページ URL を用いて、Ruby のページオブジェクトを取得します。取得した JSON の中から
properties キーオブジェクトを取り出しておきます。
11.3.1 作成者 (created_by) /最終更新者 (last_edited_by)
11.3.2 作成日時 (created_time) /最終更新日時 (last_edited_time)
11.3.3 関数 (formula)
11.3.4 ロールアップ (rollup)
11.3.5 チェックボックス (checkbox)
11.3.6 日付 (date)
11.3.7 メール (email)
11.3.8 ファイル & メディア (files)
11.3.9 マルチセレクト (multi_select)
11.3.10 数値 (number)
11.3.11 ユーザー (people)
11.3.12 電話 (phone_number)
11.3.13 リレーション (relation)
11.3.14 テキスト (rich_text)
11.3.15 セレクト (select)
11.3.16 タイトル (title)
11.3.17 URL (url)
11.4 Filter object
11.4.1 存在・非存在条件
データベース Ruby オブジェクトから PropertyCache オブジェクトを取得しておきます。
11.4.2 一致・不一致条件
11.4.3 包含・非包含条件
11.4.4 開始・終了条件
11.4.5 数値の大小条件
11.4.5 日付の前後条件
日付系プロパティ(date, created_time, last_edited_time)のみ、日付の前後を比較するフィルタが利用できます。まず、特定の日付・時間の前後関係に関するフィルタとして、前(before)、後(after)、今を含む前(on_or_before)、今を含む後(on_or_after)が利用できます。これも日付の場合には、UTC になるので注意が必要です。せっかくなので、ここでは Timestamp filter object の例で説明しています。このように専用のプロパティを用意していなくても、データベースの作成時刻を使って絞り込みをすることが可能です。こちらも before の結果のみ示します。
11.4.6 関数(formula)に対する条件
11.4.7 ロールアップ(rollup)に対する条件
一方、 show_original や show_unique の場合には、複数個の値が存在します。ロールアップの場合には、それらのどれかの値が該当するか (any)、全ての値が該当するか (every)、全ての値が該当しないか (none) を確認することができます。例えばチェックボックスを複数個ロールアップしてきた場合を考えましょう。複数個存在するチェックボックスのいずれかにチェックがされているものを抽出する場合には以下のようになります。
以下、サンプルデータのリレーション先のデータベース
# プロパティ確認用データベースを取得
db = Database.find "プロパティ確認用データベースの URL"
データベースオブジェクトを取得 (Ruby)# データベースプロパティが含まれた Ruby オブジェクト (Property object 確認用)
dps = db.json["properties"]
データベースプロパティ JSON を取得 (Ruby)print JSON.pretty_generate(dps.slice "チェックボックス")
Checkbox property の Property object
Checkbox property の Property objectprint JSON.pretty_generate(dps.slice "関数")
formula property の Property object
formula property の Property objectprint JSON.pretty_generate(dps.slice "セレクト")
select property の Property object
select property の Property objectprint JSON.pretty_generate(dps.slice "数値")
number property の Property object
number property の Property objectprint JSON.pretty_generate(dps.slice "片方向リレーション先")
relation property(single_property) の Property object
relation property(single_property) の Property objectprint JSON.pretty_generate(dps.slice "双方向リレーション先")
relation property(dual_property) の Property object
relation property(dual_property) の Property objectprint JSON.pretty_generate(dps.slice "ロールアップ")
rollup property の Property object
rollup property の Property object
プロパティ確認用ページ(データ1ページ)の URL# プロパティ確認用データベースを取得
page = Page.find "データ 1 ページの URL"
page オブジェクトの取得# ページプロパティが含まれた Ruby オブジェクト (Property item object 確認用)
pps = page.json["properties"]
ページプロパティ JSON を取得print JSON.pretty_generate(pps.slice "作成者")
created_by property の Property item object
created_by property の Property item objectprint JSON.pretty_generate(pps.slice "最終更新者")
last_edited_by property の Property item object
last_edited_by property の Property item objectprint JSON.pretty_generate(pps.slice "作成日時")
created_time property の Property item object
created_time property の Property item objectprint JSON.pretty_generate(pps.slice "最終更新日時")
last_edited_time property の Property item object
last_edited_time property の Property item objectprint JSON.pretty_generate(pps.slice "関数")
formula の Property item object
formula の Property item objectprint JSON.pretty_generate(pps.slice "ロールアップ")
rollup property (count) の Property item object
rollup property (count) の Property item objectprint JSON.pretty_generate(pps.slice "ロールアップ(オリジナル)")
rollup property (show_original) の Property item object
rollup property (show_original) の Property item objectprint JSON.pretty_generate(pps.slice "チェックボックス")
checkbox property の Property item object
checkbox property の Property item objectprint JSON.pretty_generate(pps.slice "日付")
date property の Property item object
date property の Property item objectprint JSON.pretty_generate(pps.slice "メール")
email property の Property item object
email property の Property item objectprint JSON.pretty_generate(pps.slice "ファイル&メディア")
files property の Property item object
files property の Property item objectprint JSON.pretty_generate(pps.slice "マルチセレクト")
multi_select property の Property item object
multi_select property の Property item objectprint JSON.pretty_generate(pps.slice "数値")
number property の Property item object
number property の Property item objectprint JSON.pretty_generate(pps.slice "ユーザー")
people property の Property item object
number property の Property item objectprint JSON.pretty_generate(pps.slice "電話")
phone_number property の Property item object
phone_number property の Property item objectprint JSON.pretty_generate(pps.slice "片方向リレーション先")
relation property の Property item object
relation property の Property item objectprint JSON.pretty_generate(pps.slice "テキスト")
rich_text property の Property item object
rich_text property の Property item objectprint JSON.pretty_generate(pps.slice "セレクト")
select property の Property item object
select property の Property item objectprint JSON.pretty_generate(pps.slice "タイトル")
title property の Property item object
title property の Property item objectprint JSON.pretty_generate(pps.slice "URL")
url property の Property item object
url property の Property item objectps = db.properties
Ruby の PropertyCache オブジェクトprint JSON.pretty_generate(ps["数値"].filter_is_not_empty.filter)
is_not_empty 条件print JSON.pretty_generate(ps["数値"].filter_is_empty.filter)
is_empty 条件print JSON.pretty_generate(ps["URL"].filter_equals("ABC").filter)
equals 条件print JSON.pretty_generate(ps["URL"].filter_does_not_equal("ABC").filter)
does_not_equal 条件print JSON.pretty_generate(ps["日付"].filter_equals(Date.new(2022, 10, 15)).filter)
NotionRubyMapping 拡張print JSON.pretty_generate(ps["タイトル"].filter_contains("ABC").filter)
contains 条件print JSON.pretty_generate(ps["タイトル"].filter_does_not_contain("ABC").filter)
does_not_contain 条件print JSON.pretty_generate(ps["テキスト"].filter_starts_with("ABC").filter)
starts_with 条件print JSON.pretty_generate(ps["テキスト"].filter_ends_with("ABC").filter)
ends_with 条件print JSON.pretty_generate(ps["数値"].filter_greater_than(10).filter)
greater_than 条件print JSON.pretty_generate(ps["数値"].filter_less_than(10).filter)
less_than 条件print JSON.pretty_generate(ps["数値"].filter_greater_than_or_equal_to(10).filter)
greater_than_or_equal_to 条件
greater_than_or_equal_to 条件print JSON.pretty_generate(ps["数値"].filter_less_than_or_equal_to(10).filter)
less_than_or_equal_to 条件print JSON.pretty_generate(db.created_time.filter_before(Time.local(2022, 10, 15, 12, 0, 0)).filter)
before 条件print JSON.pretty_generate(db.created_time.filter_after(Time.local(2022, 10, 15, 12, 0, 0)).filter)
after 条件print JSON.pretty_generate(db.created_time.filter_on_or_before(Time.local(2022, 10, 15, 12, 0, 0)).filter)
on_or_before 条件print JSON.pretty_generate(db.created_time.filter_on_or_after(Time.local(2022, 10, 15, 12, 0, 0)).filter)
on_or_after 条件print JSON.pretty_generate(db.last_edited_time.filter_past_week.filter)
past_week 条件print JSON.pretty_generate(db.last_edited_time.filter_next_week.filter)
next_week 条件print JSON.pretty_generate(db.last_edited_time.filter_past_month.filter)
past_month 条件print JSON.pretty_generate(db.last_edited_time.filter_next_month.filter)
next_month 条件print JSON.pretty_generate(db.last_edited_time.filter_past_year.filter)
past_year 条件print JSON.pretty_generate(db.last_edited_time.filter_next_year.filter)
next_year 条件print JSON.pretty_generate(db.last_edited_time.filter_this_week.filter)
this_week 条件print JSON.pretty_generate(ps["関数"].filter_equals(true, another_type: "checkbox").filter)
Formula filter objectrp = ps["ロールアップ"]
Rollup Property Ruby オブジェクトの取得print JSON.pretty_generate(rp.filter_greater_than(10, another_type: "number").filter)
数値の場合の Rollup filter objectprint JSON.pretty_generate(rp.filter_past_week(another_type: "date").filter)
日付の場合の Rollup filter objectprint JSON.pretty_generate(rp.filter_equals(true, another_type: "checkbox", condition: "any").filter)
Rollup filter object (any)print JSON.pretty_generate(rp.filter_equals(true, another_type: "checkbox", condition: "every").filter)
Rollup filter object (any)print JSON.pretty_generate(rp.filter_equals(true, another_type: "checkbox", condition: "none").filter)
Rollup filter object (none)