Skip to content

Commit

Permalink
add metadata column
Browse files Browse the repository at this point in the history
  • Loading branch information
judell committed Sep 24, 2023
1 parent f66919e commit c288875
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions odbc/table_code_odbc.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,25 @@ func tableODBC(ctx context.Context, connection *plugin.Connection) (*plugin.Tabl
return nil, err
}

// Assume all columns can be used as key columns (qualifiers)
keyColumns := getKeyColumns(cols)
// Add the _metadata column to the list of columns
cols = append(cols, &plugin.Column{
Name: "_metadata",
Type: proto.ColumnType_JSON,
Transform: transform.FromField("_metadata"),
Description: "Metadata related to the data source",
})

return &plugin.Table{
Name: strings.ToLower(dsn) + "_" + tablename,
Description: dsn + ":" + tablename,
List: &plugin.ListConfig{
Hydrate: listODBC,
KeyColumns: keyColumns,
Hydrate: listODBC,
},
Columns: cols,
}, nil
}


// Define a function to get key columns from the list of columns
func getKeyColumns(columns []*plugin.Column) plugin.KeyColumnSlice {

Check failure on line 111 in odbc/table_code_odbc.go

View workflow job for this annotation

GitHub Actions / golangci_lint_workflow / lint

func `getKeyColumns` is unused (unused)
var keyCols plugin.KeyColumnSlice
Expand Down Expand Up @@ -195,6 +200,12 @@ func fetchFromDatabase(ctx context.Context, dsn string, tablename string, quals
}

m := make(map[string]interface{})

m["_metadata"] = map[string]interface{}{
"connection_name": "odbc",
"dsn": dsn,
}

for i, colName := range columns {
val := colPtrs[i].(*interface{})
m[helpers.EscapePropertyName(colName)] = *val
Expand Down

0 comments on commit c288875

Please sign in to comment.