1
0
mirror of https://github.com/dstotijn/go-notion.git synced 2025-06-17 00:07:45 +02:00

Remove database property metadata types that are empty

This commit is contained in:
David Stotijn
2021-05-14 18:49:00 +02:00
parent 56b18f60ee
commit 0c31224d6f

View File

@ -18,37 +18,23 @@ type Database struct {
type DatabaseProperties map[string]DatabaseProperty type DatabaseProperties map[string]DatabaseProperty
// Database property types. // Database property metadata types.
type ( type (
TitleDatabaseProperty struct{} NumberMetadata struct {
RichTextDatabaseProperty struct{}
DateDatabaseProperty struct{}
PeopleDatabaseProperty struct{}
FileDatabaseProperty struct{}
CheckboxDatabaseProperty struct{}
URLDatabaseProperty struct{}
EmailDatabaseProperty struct{}
PhoneNumberDatabaseProperty struct{}
CreatedTimeDatabaseProperty struct{}
CreatedByDatabaseProperty struct{}
LastEditedTimeDatabaseProperty struct{}
LastEditedByDatabaseProperty struct{}
NumberDatabaseProperty struct {
Format string `json:"format"` Format string `json:"format"`
} }
SelectDatabaseProperty struct { SelectMetadata struct {
Options []SelectOptions `json:"options"` Options []SelectOptions `json:"options"`
} }
FormulaDatabaseProperty struct { FormulaMetadata struct {
Expression string `json:"expression"` Expression string `json:"expression"`
} }
RelationDatabaseProperty struct { RelationMetadata struct {
DatabaseID string `json:"database_id"` DatabaseID string `json:"database_id"`
SyncedPropName *string `json:"synced_property_name"` SyncedPropName *string `json:"synced_property_name"`
SyncedPropID *string `json:"synced_property_id"` SyncedPropID *string `json:"synced_property_id"`
} }
RollupDatabaseProperty struct { RollupMetadata struct {
RelationPropName string `json:"relation_property_name"` RelationPropName string `json:"relation_property_name"`
RelationPropID string `json:"relation_property_id"` RelationPropID string `json:"relation_property_id"`
RollupPropName string `json:"rollup_property_name"` RollupPropName string `json:"rollup_property_name"`
@ -67,25 +53,33 @@ type DatabaseProperty struct {
ID string `json:"id"` ID string `json:"id"`
Type string `json:"type"` Type string `json:"type"`
Title *TitleDatabaseProperty `json:"title"` Number *NumberMetadata `json:"number"`
RichText *RichTextDatabaseProperty `json:"rich_text"` Select *SelectMetadata `json:"select"`
Number *NumberDatabaseProperty `json:"number"` MultiSelect *SelectMetadata `json:"multi_select"`
Select *SelectDatabaseProperty `json:"select"` Formula *FormulaMetadata `json:"formula"`
MultiSelect *SelectDatabaseProperty `json:"multi_select"` Relation *RelationMetadata `json:"relation"`
Date *DateDatabaseProperty `json:"date"` Rollup *RollupMetadata `json:"rollup"`
People *PeopleDatabaseProperty `json:"people"` }
File *FileDatabaseProperty `json:"file"`
Checkbox *CheckboxDatabaseProperty `json:"checkbox"` // Metadata returns the underlying property metadata, based on its `type` field.
URL *URLDatabaseProperty `json:"url"` // When type is unknown/unmapped or doesn't have additional properies, `nil` is returned.
Email *EmailDatabaseProperty `json:"email"` func (prop DatabaseProperty) Metadata() interface{} {
PhoneNumber *PhoneNumberDatabaseProperty `json:"phone_number"` switch prop.Type {
Formula *FormulaDatabaseProperty `json:"formula"` case "number":
Relation *RelationDatabaseProperty `json:"relation"` return prop.Number
Rollup *RollupDatabaseProperty `json:"rollup"` case "select":
CreatedTime *CreatedTimeDatabaseProperty `json:"created_time"` return prop.Select
CreatedBy *CreatedByDatabaseProperty `json:"created_by"` case "multi_select":
LastEditedTime *LastEditedTimeDatabaseProperty `json:"last_edited_time"` return prop.MultiSelect
LastEditedBy *LastEditedByDatabaseProperty `json:"last_edited_by"` case "formula":
return prop.Formula
case "relation":
return prop.Relation
case "rollup":
return prop.Rollup
default:
return nil
}
} }
func (c *Client) FindDatabaseByID(id string) (db Database, err error) { func (c *Client) FindDatabaseByID(id string) (db Database, err error) {