({
database,
filterValueList,
includeColumn,
}: {
database: Database;
filterValueList?: string[];
includeColumn: boolean;
})
| 117 | }; |
| 118 | |
| 119 | export const getSchemaOrTableTreeOptions = ({ |
| 120 | database, |
| 121 | filterValueList, |
| 122 | includeColumn, |
| 123 | }: { |
| 124 | database: Database; |
| 125 | filterValueList?: string[]; |
| 126 | includeColumn: boolean; |
| 127 | }) => { |
| 128 | if (getInstanceResource(database).engine === Engine.MONGODB) { |
| 129 | // do not support table level select for MongoDB. |
| 130 | return []; |
| 131 | } |
| 132 | const databaseMetadata = useAppStore |
| 133 | .getState() |
| 134 | .getCachedDatabaseMetadata(database.name); |
| 135 | if (!databaseMetadata) { |
| 136 | return undefined; |
| 137 | } |
| 138 | if (hasSchemaProperty(getInstanceResource(database).engine)) { |
| 139 | const schemaNodes = databaseMetadata.schemas.map( |
| 140 | (schema): DatabaseTreeOption<"schemas"> => { |
| 141 | const value = `${database.name}/schemas/${schema.name}`; |
| 142 | const schemaNode: DatabaseTreeOption<"schemas"> = { |
| 143 | level: "schemas", |
| 144 | value, |
| 145 | label: schema.name, |
| 146 | children: getTableTreeOptions({ |
| 147 | prefix: value, |
| 148 | tableList: schema.tables, |
| 149 | filterValueList, |
| 150 | includeColumn, |
| 151 | }), |
| 152 | isLeaf: true, |
| 153 | }; |
| 154 | if (schemaNode.children && schemaNode.children.length > 0) { |
| 155 | schemaNode.isLeaf = false; |
| 156 | } |
| 157 | return schemaNode; |
| 158 | } |
| 159 | ); |
| 160 | return filterValueList |
| 161 | ? schemaNodes.filter((node) => |
| 162 | filterValueList.some( |
| 163 | (value) => value.split("/tables/")[0] === node.value |
| 164 | ) |
| 165 | ) |
| 166 | : schemaNodes; |
| 167 | } else { |
| 168 | return getTableTreeOptions({ |
| 169 | prefix: `${database.name}/schemas/`, |
| 170 | tableList: flatten( |
| 171 | databaseMetadata.schemas.map((schema) => schema.tables) |
| 172 | ), |
| 173 | filterValueList, |
| 174 | includeColumn, |
| 175 | }); |
| 176 | } |
no test coverage detected