Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Database Creation #135

Merged
merged 58 commits into from
Jun 16, 2023
Merged

Database Creation #135

merged 58 commits into from
Jun 16, 2023

Conversation

johguentner
Copy link
Member

@johguentner johguentner commented Apr 28, 2023

Adding multiple ways to create a new database within the Notion API

$scheme = PropertyBuilder::bulk()
                ->title('MyTitle') // required
                ->richText('MyText')
                ->checkbox('...')
                ->status()
                ->number()
                ->date()
                ->url()
                ->email()
                ->phoneNumber()
                ->people()
                ->files()
                ->createdBy()
                ->createdTime()
                ->lastEditedBy()
                ->lastEditedTime()
                ->formula('Testing', 'prop("MultiSelect")')
                ->select('Select', [
                    [
                        'name' => 'option 1 select',
                        'color' => 'blue'
                    ]
                ])->multiSelect('MultiSelect', [
                    [
                        'name' => 'option 1 multiselect',
                        'color' => 'yellow'
                    ]
                ]);

 $databaseEntity = Notion::databases()
                  ->build()
                  ->inline()
                  ->title('Inline Test DB 1')
                  ->add($scheme)
                  ->createInPage('1c682e7371ec4399be1cc015686c67c6');

To keep it a bit more similar to Laravel migrations, it's also possible to do it like this:

$databaseEntity = Notion::databases()
                  ->build()
                  ->title('Test DB 2')
                  ->scheme(function ($table){
                      $table->title('My Title');
                      $table->richText('My Text');
                      $table->date('My Date');
                  })
                  ->createInPage('1c682e7371ec4399be1cc015686c67c6');

To keep things simple, it's also possible to use the PropertyBuilder::class.

$props = collect([
     PropertyBuilder::title(),
     PropertyBuilder::richText(),
     ...
]);

$databaseEntity = Notion::databases()
                  ->build()
                  ->title('Test DB 3')
                  ->add($props) //add multiple props
                  ->add(PropertyBuilder::date('My Date')) //add single props
                  ->createInPage('1c682e7371ec4399be1cc015686c67c6');

Polish of PestHttpRecorder::class

  • remove adding the query/payload to the snapshot filename
  • instead add short hash of query/payload to the snapshot filename
  • or (if given) allow user to set a specific name for the upcoming request
  • additionally writing header, method and payload to the snapshot

johguentner and others added 12 commits February 6, 2023 16:06
- some entities have parents or expose user-ids, without additional information
- by resolving these within the "endpoint" (not a real notion enpoint) ``Resolve::class``, the additional information can be easily obtained
- why `HasTitle` trait is not used within `Page::class`
- class for building Notion databases and their properties
@what-the-diff
Copy link

what-the-diff bot commented Apr 28, 2023

PR Summary

  • Added a new builder for creating databases
    Introduced a new way to create databases, making it more efficient and organized
  • Refactored the database endpoint to use the builder and added create method
    Improved the database endpoint by using the new builder, and added a method for creating databases
  • Moved shared title property to a trait
    A common property (title) used by multiple entities is now in a shared location for better organization and code reuse
  • Fixed typos in documentation and code comments
    Improved the clarity of documentation and comments by fixing errors
  • Updated the comment for new Filter behavior
    Provided up-to-date information on how the Filter behaves

@johguentner
Copy link
Member Author

Hey @farez,

just wanted to double check, if this goes into the direction you hoped regarding database creation (example of current possibilities with these new changes):

$databaseEntity = Notion::databases()
                ->build()
                ->inline() // just don't use, if you want it to be as subpage
                ->title('Title of Database')
                ->addTitleProperty() // required (that's why it's an extra function for ease of use)
                ->addProperty('Description', PropertyBuilder::richText())
                ->addProperty('Number', PropertyBuilder::number('dollar'))
                ->addRawProperty('Special Property', [ /* raw for unsupported/future properties */ ])
                ->createInPage('2c682e7372ec4399be1cc015686c69c6');

@farez
Copy link
Contributor

farez commented Apr 29, 2023 via email

johguentner and others added 3 commits April 29, 2023 22:04
- fix missing parent type
- refactor method names to shorter and (hopefully) more readable
- introduce `DatabaseSchemeBuilder::class`, which allows a more eloquent definition of a new database structure (similar to Laravel migrations)
- allow to add multiple properties at the same time (bulk)
- add all further properties (listed within the Notion API docs)
@johguentner johguentner changed the title Feature/database creation database creation Apr 29, 2023
@johguentner
Copy link
Member Author

johguentner commented Apr 29, 2023

Hello Johannes! Ah that looks awesome. Should work well. An idea: have a shortcut method called addProperties() that takes an array of property definitions. Saves calling addProperty lots of times. Thanks man. Look forward to using this. Farez

Thank you for your input @farez !
I updated the description above to show all possibilities.
After I add the final touches + especially testing, I'll push this as v1.1.0

@johguentner johguentner changed the title database creation Database Creation Apr 29, 2023
- remove adding query to file-name
- instead add short hash of query to file-name
- or (if given) allow user to set a specific name for upcoming query
- additionally save header, method and payload within the snapshot
* @param string $name
* @return DatabaseBuilder
*/
public function addTitle(string $name = 'Name')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing return type? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's right there, isn't it ?

@johguentner johguentner requested a review from mechelon June 10, 2023 12:59
@johguentner johguentner merged commit 207e873 into dev Jun 16, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants