💽

Database and page access sample

A linked view of the test database is placed at the bottom of this page. A link to the method reference is provided at the end of the description.
  1. Preparation (instance → self.instance → NotionCache, create_client → create_client(notion_token, wait: 0.1))
    1. require "notion_ruby_mapping" include NotionRubyMapping token = ENV["NOTION_API_TOKEN"] database_id = "c37a2c66e3aa4a0da44773de3b80c253" # ENV["DATABASE_ID"] NotionCache.instance.create_client token
  1. Retrieve a database (find → self.find(id, dry_run: false))
    1. db = Database.find database_id => #<NotionRubyMapping::Database:0x0000000104f6cb10
  1. Obtain properties (properties → properties → PropertyCache)
    1. title_property = db.properties["Title"] => #<NotionRubyMapping::TitleProperty:0x0000000106f7d288 ... select_property = db.properties["SelectTitle"] => #<NotionRubyMapping::SelectProperty:0x00000001055b3320 ...
  1. Query database without filter (query_database → query_database(query = nil, dry_run: false) → List)
    1. all_pages = db.query_database => #<NotionRubyMapping::List:0x0000000106f9c890 ...
  1. Count all_pages (Enumerable → each { |item| ... } → self each → Enumerator)
    1. all_pages.count => 6
  1. Obtain all page title (Enumerable → each { |item| ... } → self each → Enumerator, title → title → String)
    1. all_pages.map(&:title) => ["", "JKL", "MNO", "DEF", "GHI", "ABC"]
  1. Query database with filter (query_database → query_database(query = nil, dry_run: false) → List, filter_equals → , ascending → ascending(property) )
    1. select3_pages = db.query_database select_property.filter_equals("Select 3").ascending(title_property) => #<NotionRubyMapping::List:0x000000010889ef28 ...
  1. Count select3_pages (Enumerable → each { |item| ... } → self each → Enumerator)
    1. select3_pages.count => 2
  1. Obtain select3_pages title (Enumerable → each { |item| ... } → self each → Enumerator, title → title → String)
    1. select3_pages.map(&:title) => ["ABC", "MNO"]
  1. Obtain the first page (Enumerable → each { |item| ... } → self each → Enumerator)
    1. abc_page = select3_pages.first => #<NotionRubyMapping::Page:0x0000000108494860
  1. Obtain the multi_select_names of the page (properties → properties → PropertyCache, multi_select_names → multi_select_names → Array)
    1. abc_page.properties["MultiSelectTitle"].multi_select_names
 
 
Sample tableSample table
Sample table
Title
TextTitle
NumberTitle
SelectTitle
MultiSelectTitle
DateTitle
UserTitle
File&MediaTitle
CheckboxTitle
UrlTitle
MailTitle
TelTitle
CreatedTimeTitle
CreatedByTitle
LastEditedTimeTitle
LastEditedByTitle
FormulaTitle
RelationTitle
RollupTitle
ID
def
1.41421356
Select 3
Multi Select 2
Multi Select 1
Feb 25, 2022 01:23
https://img.icons8.com/ios-filled/250/000000/mac-os.png
CheckboxTitle
Feb 7, 2022 09:29 PM
Sep 1, 2022 04:35 AM
Sep 19, 2024 11:36 PM
3
abc
notion_ruby_mapping_test_datanotion_ruby_mapping_test_data
notion_ruby_mapping_test_data
Feb 21, 2022 Feb 22, 2022 09:00 高専HP
Sample tableSample table
Sample table
2
Select 2
Multi Select 2
Feb 11, 2022 → Feb 12, 2022
nr.png
CheckboxTitle
Feb 7, 2022 09:29 PM
Mar 17, 2022 12:43 PM
Sep 19, 2024 11:36 PM
2
CheckboxTitle
Feb 7, 2022 09:29 PM
Mar 16, 2022 12:38 PM
Sep 19, 2024 11:36 PM
1
CheckboxTitle
Mar 10, 2022 04:13 AM
Mar 10, 2022 04:13 AM
Sep 19, 2024 11:36 PM
4
new text
3.1415926535
Select 3
Multi Select 2
Mar 14, 2022
https://img.icons8.com/ios-filled/250/000000/mac-os.png
CheckboxTitle
Mar 10, 2022 04:13 AM
Sep 1, 2022 05:03 AM
Sep 19, 2024 11:36 PM
5