{#if dbSelector} {@render dbSelector()} {/if} {#if dbSupportsSchemas && !multiSelectMode} e.stopPropagation()} onchange={() => toggleSchemaSelection(schemaKey)} /> {/if} {schemaKey} {schemaTables.length}
{#each schemaTables as tableKey} {@const isDisabled = isTableDisabled(schemaKey, tableKey)} {@const isChecked = isTableSelected(schemaKey, tableKey) || isDisabled} {@const isCurrentPreview = selected.schemaKey === schemaKey && selected.tableKey === tableKey}
{ selected.schemaKey = schemaKey selected.tableKey = tableKey toggleTableSelection(schemaKey, tableKey) }} onkeydown={(e) => { if (e.key === 'Enter' || e.key === ' ') { selected.schemaKey = schemaKey selected.tableKey = tableKey toggleTableSelection(schemaKey, tableKey) } }} > e.stopPropagation()} onchange={() => toggleTableSelection(schemaKey, tableKey)} />

{tableKey}

{/each} {/each} {:else} {#each filteredTableKeys as tableKey} {/each} {/if} {#if !multiSelectMode} {/if}
{#if tableKey && colDefs?.[tableKey]?.length} {@const dbTableOps = dbTableOpsFactory({ colDefs: colDefs[tableKey], tableKey })} {/if}
(askingForConfirmation = undefined)} on:confirmed={askingForConfirmation?.onConfirm ?? (() => {})} /> (dbTableEditorState = { open: false })} > (dbTableEditorState = { open: false })} title={dbTableEditorState.alterTableKey ? `Alter ${dbTableEditorState.alterTableKey}` : 'Create a new table'} > {#key dbTableEditorState.alterTableKey} {#if !dbTableEditorState.alterTableKey || dbTableEditorAlterTableData.current} { if (dbTableEditorState.alterTableKey && dbTableEditorAlterTableData.current) { let diff = diffTableEditorValues(dbTableEditorAlterTableData.current, values) await dbSchemaOps.onAlter({ schema: selected.schemaKey, values: diff }) } else { await dbSchemaOps.onCreate({ values, schema: selected.schemaKey }) } refresh?.() sendUserToast( dbTableEditorState.alterTableKey ? dbTableEditorState.alterTableKey + ' updated!' : values.name + ' created!' ) dbTableEditorState = { open: false } }} {dbType} computePreview={({ values }) => { if (dbTableEditorState.alterTableKey && dbTableEditorAlterTableData.current) { let diff = diffTableEditorValues(dbTableEditorAlterTableData.current, values) let queries = dbSchemaOps.previewAlterSql({ values: diff, schema: selected.schemaKey }) let alert = !dbSupportsTransactionalDdl(dbType) ? { title: capitalize(dbType) + ' does not support transactional DDL', body: 'Any of these statements failing may leave your database in an intermediate state.' } : undefined return { sql: queries.join('\n'), ...(alert ? { alert } : {}) } } else { return { sql: dbSchemaOps.previewCreateSql({ values, schema: selected.schemaKey }) } } }} computeBtnProps={({ values }) => { if (dbTableEditorState.alterTableKey && dbTableEditorAlterTableData.current) { let diff = diffTableEditorValues(dbTableEditorAlterTableData.current, values) let queries = dbSchemaOps.previewAlterSql({ values: diff, schema: selected.schemaKey }) if (!queries.length) { return { text: 'No changes detected', disabled: true } } return { text: `Alter table (${pluralize(queries.length, 'change')} detected)` } } else { return { text: 'Create table' } } }} /> {:else if dbTableEditorAlterTableData.loading || !colDefs} {:else}

Failed to load table definition.

{dbTableEditorAlterTableData.error}

{/if} {/key}
{ newSchemaDialogOpen = false newSchemaName = '' }} > { newSchemaDialogOpen = false newSchemaName = '' }} title="Create a new schema" >
{ if (e.key === 'Enter' && sanitizedNewSchemaName && !schemaAlreadyExists) { askingForConfirmation = { confirmationText: `Create ${sanitizedNewSchemaName}`, type: 'reload', title: `This will run 'CREATE SCHEMA ${sanitizedNewSchemaName}' on your database. Are you sure?`, open: true, id: 'db-create-schema-confirmation-modal', onConfirm: async () => { askingForConfirmation && (askingForConfirmation.loading = true) try { await dbSchemaOps.onCreateSchema({ schema: sanitizedNewSchemaName }) refresh?.() selected.schemaKey = sanitizedNewSchemaName newSchemaDialogOpen = false newSchemaName = '' } finally { askingForConfirmation = undefined } } } } }} /> {#if schemaAlreadyExists}

Schema "{sanitizedNewSchemaName}" already exists

{:else}

Only letters, numbers, and underscores are allowed.

{/if}
{#snippet actions()} {/snippet}