Skip to content

Commit

Permalink
refactor(table.go): modify CreateOntologyTableFields function to retu…
Browse files Browse the repository at this point in the history
…rn a boolean status along with error

The CreateOntologyTableFields function now returns a boolean status
along with the error. This change provides more information about the
function's execution, specifically whether the fields were created in
the table or not.
  • Loading branch information
cybersiddhu committed Feb 21, 2024
1 parent 43d0498 commit 3dd1d30
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions internal/baserow/database/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,27 @@ func CreateTableField(args *CreateFieldProperties) error {
return nil
}

func CreateOntologyTableFields(args *OntologyTableFieldsProperties) error {
func CreateOntologyTableFields(
args *OntologyTableFieldsProperties,
) (bool, error) {
logger := args.Logger
bclient := args.Client
authCtx := args.Ctx
ok := false
tlist, resp, err := bclient.
DatabaseTableFieldsApi.
ListDatabaseTableFields(authCtx, int32(args.TableId)).
Execute()
if err != nil {
return fmt.Errorf("error in getting list of table fields %s", err)
return ok, fmt.Errorf("error in getting list of table fields %s", err)
}
defer resp.Body.Close()
if len(tlist) != 0 {
logger.Debug("fields exists in the database table")
return nil
return ok, nil
}
logger.Debug("need to create fields in the table")
ok = true
for field, fieldType := range args.FieldMap {
err := CreateTableField(&CreateFieldProperties{
Client: bclient,
Expand All @@ -89,10 +93,10 @@ func CreateOntologyTableFields(args *OntologyTableFieldsProperties) error {
FieldType: fieldType,
})
if err != nil {
return err
return ok, err
}
logger.Infof("created field %s", field)
}

return nil
return ok, nil
}

0 comments on commit 3dd1d30

Please sign in to comment.