Skip to content

Commit

Permalink
use SHOW CREATE TABLE in Copy schema to clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
insmac committed Jan 7, 2025
1 parent 0469576 commit 68de709
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions packages/web-console/src/scenes/Schema/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ import { Panel } from "../../components/Panel"
import { QuestContext } from "../../providers"
import { eventBus } from "../../modules/EventBus"
import { EventType } from "../../modules/EventBus/types"
import { formatTableSchemaQueryResult } from "./formatTableSchemaQueryResult"
import { Toolbar } from "./Toolbar/toolbar"
import { SchemaContext } from "./SchemaContext"
import { useLocalStorage } from "../../providers/LocalStorageProvider"
Expand Down Expand Up @@ -151,10 +150,8 @@ const Schema = ({
const dispatch = useDispatch()
const [scrollAtTop, setScrollAtTop] = useState(true)
const scrollerRef = useRef<HTMLDivElement | null>(null)
const [copied, setCopied] = useState(false)
const [query, setQuery] = useState("")
const [filterSuspendedOnly, setFilterSuspendedOnly] = useState(false)
const [columns, setColumns] = useState<QuestDB.InformationSchemaColumn[]>()
const { autoRefreshTables, updateSettings } = useLocalStorage()
const [selectOpen, setSelectOpen] = useState(false)
const [selectedTables, setSelectedTables] = useState<string[]>([])
Expand Down Expand Up @@ -198,15 +195,16 @@ const Schema = ({
const fetchColumns = async () => {
const queries = [
"information_schema.questdb_columns()",
"information_schema.columns()" // fallback for older servers
"information_schema.columns()", // fallback for older servers
]

for (const query of queries) {
try {
const response = await quest.query<QuestDB.InformationSchemaColumn>(query)
const response = await quest.query<QuestDB.InformationSchemaColumn>(
query,
)

if (response?.type === QuestDB.Type.DQL) {
setColumns(response.data)
dispatch(actions.query.setColumns(response.data))
return
}
Expand All @@ -218,27 +216,17 @@ const Schema = ({
dispatchState({ view: View.error })
}


const copySchemasToClipboard = async () => {
if (!tables) return
let tablesWithError: string[] = []
const ddls = await Promise.all(
selectedTables.map(async (table) => {
try {
const columnResponse = await quest.showColumns(table)
const tableData = tables.find((t) => t.table_name === table)
if (
tableData &&
columnResponse.type === QuestDB.Type.DQL &&
columnResponse.data.length > 0
) {
return formatTableSchemaQueryResult(
tableData.table_name,
tableData.partitionBy,
columnResponse.data,
tableData.walEnabled,
tableData.dedup,
)
const tableDDLResponse = await quest.query<{ ddl: string }>(
`SHOW CREATE TABLE ${table}`,
)
if (tableDDLResponse && tableDDLResponse.type === QuestDB.Type.DQL) {
return tableDDLResponse.data[0].ddl
}
} catch (error) {
tablesWithError.push(table)
Expand Down

0 comments on commit 68de709

Please sign in to comment.