Last active
September 5, 2024 04:47
-
-
Save dankerizer/cd7b45bdc862f5a82639aaac5a6db599 to your computer and use it in GitHub Desktop.
Convert Metabase to any Array Object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type MetabaseDataProps = { | |
data: DataProps; | |
json_query: JSONQuery; | |
status: string; | |
} | |
export type DataProps = { | |
rows: Array<Array<number | string>>; | |
cols: ColProps[]; | |
insights: null; | |
results_timezone: string; | |
} | |
export type ColProps = { | |
display_name: string; | |
source: string; | |
field_ref: Array<FieldRefClass | string>; | |
name: string; | |
base_type: string; | |
effective_type: string; | |
} | |
export type FieldRefClass = { | |
"base-type": string; | |
} | |
export type JSONQuery = { | |
} | |
export function convertMetabaseObjects<T = Record<string,unknown>[]>(data:DataProps) { | |
const columns = data.cols.map(col => col.name); | |
return data.rows.map(row => { | |
const obj = {}; | |
columns.forEach((col, index) => { | |
obj[col] = row[index]; | |
}); | |
return obj as T; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment