データベースを 作成 したり 更新 したりするときに、 formula
プロパティを作成できるようになった。便利だとは思うのだが、実際にデータベース自体を何度も作成・更新することってあるかな?
とりあえず、テストのためにこのデータベースに数式を一つ入れてみる。有用な計算できるのは日付くらいなので、何日まえか計算する式を作ってみる。
#!/bin/sh
curl --location --request PATCH '<https://api.notion.com/v1/databases/c63c00ad-201d-4bed-82b0-18dfca9b6ba0>' \\
--header 'Authorization: Bearer '"$NOTION_API_KEY"'' \\
--header 'Content-Type: application/json' \\
--header 'Notion-Version: 2021-08-16' \\
--data '{
"properties": {
"経過日数": {
"formula": { "expression": "dateBetween(now(), prop(\\"日付\\"), \\"days\\")" }
}
}
}'
これによって、経過日数というプロパティができており、今日(11月10日)の状態で「81」という値が計算できていた。帰ってきた JSON にも経過日数のプロパティが確認できる。
{
"object": "database",
"id": "c63c00ad-201d-4bed-82b0-18dfca9b6ba0",
"cover": null,
"icon": null,
"created_time": "2021-11-08T21:41:00.000Z",
"last_edited_time": "2021-11-10T11:07:00.000Z",
"title": [
{
"type": "text",
"text": {
"content": "Changelogs",
"link": null
},
"annotations": {
"bold": false,
"italic": false,
"strikethrough": false,
"underline": false,
"code": false,
"color": "default"
},
"plain_text": "Changelogs",
"href": null
}
],
"properties": {
"開示?": {
"id": "%3BfBx",
"name": "開示?",
"type": "checkbox",
"checkbox": {}
},
"日付": {
"id": "%3CWbe",
"name": "日付",
"type": "date",
"date": {}
},
"原題": {
"id": "%3FMR%7D",
"name": "原題",
"type": "rich_text",
"rich_text": {}
},
"URL": {
"id": "o%3A~F",
"name": "URL",
"type": "url",
"url": {}
},
"タグ": {
"id": "tUJV",
"name": "タグ",
"type": "multi_select",
"multi_select": {
"options": [
{
"id": "fcb7bc23-a43d-4ff1-967f-db59a6125492",
"name": "ADDED",
"color": "green"
},
{
"id": "05f3b6b1-b6f1-49a2-bbdb-955cfb4d36f4",
"name": "IMPROVED",
"color": "gray"
}
]
}
},
"経過日数": {
"id": "~Xof",
"name": "経過日数",
"type": "formula",
"formula": {
"expression": "dateBetween(now(), prop(\\"日付\\"), \\"days\\")"
}
},
"名前": {
"id": "title",
"name": "名前",
"type": "title",
"title": {}
}
},
"parent": {
"type": "page_id",
"page_id": "6a8efd66-5f69-4b39-96c3-089f680003e0"
},
"url": "<https://www.notion.so/c63c00ad201d4bed82b018dfca9b6ba0>"
}