Skip to content

Commit a35b54a

Browse files
authored
feat: add "Show create table" sql snippet (#3101)
1 parent 14ec98a commit a35b54a

File tree

6 files changed

+28
-1
lines changed

6 files changed

+28
-1
lines changed

src/containers/Tenant/Query/NewSQL/NewSQL.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ export function NewSQL() {
7979
text: i18n('action.drop-index'),
8080
action: actions.dropTableIndex,
8181
},
82+
{
83+
text: i18n('action.show-create-table'),
84+
action: actions.showCreateTable,
85+
},
8286
],
8387
},
8488
{

src/containers/Tenant/Query/NewSQL/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"action.alter-transfer": "Alter transfer",
3737
"action.drop-transfer": "Drop transfer",
3838
"action.create-streaming-query": "Create streaming query",
39+
"action.show-create-table": "Show Create SQL",
3940
"action.alter-streaming-query-settings": "Alter query settings",
4041
"action.alter-streaming-query-text": "Alter query text",
4142
"action.drop-streaming-query": "Drop query"

src/containers/Tenant/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"actions.manageAutoPartitioning": "Manage auto partitioning...",
4646
"actions.addTableIndex": "Add index...",
4747
"actions.createCdcStream": "Create changefeed...",
48+
"actions.showCreateTable": "Show Create SQL...",
4849
"actions.alterTopic": "Alter topic...",
4950
"actions.selectQuery": "Select query...",
5051
"actions.upsertQuery": "Upsert query...",

src/containers/Tenant/utils/newSQLQueryActions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
grantPrivilegeTemplate,
3131
revokePrivilegeTemplate,
3232
selectQueryTemplate,
33+
showCreateTableTemplate,
3334
updateTableTemplate,
3435
upsertQueryTemplate,
3536
} from './schemaQueryTemplates';
@@ -73,5 +74,6 @@ export const bindActions = (changeUserInput: (input: string) => void) => {
7374
dropGroup: inputQuery(dropGroupTemplate),
7475
addTableIndex: inputQuery(addTableIndex),
7576
dropTableIndex: inputQuery(dropTableIndex),
77+
showCreateTable: inputQuery(showCreateTableTemplate),
7678
};
7779
};

src/containers/Tenant/utils/schemaActions.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {CirclePlus, Copy, DisplayPulse, PlugConnection} from '@gravity-ui/icons';
1+
import {CirclePlus, Code, Copy, DisplayPulse, PlugConnection} from '@gravity-ui/icons';
22
import {Flex, Spin} from '@gravity-ui/uikit';
33
import copy from 'copy-to-clipboard';
44
import type {NavigationTreeNodeType} from 'ydb-ui-components';
@@ -46,6 +46,7 @@ import {
4646
dropViewTemplate,
4747
manageAutoPartitioningTemplate,
4848
selectQueryTemplate,
49+
showCreateTableTemplate,
4950
upsertQueryTemplate,
5051
} from './schemaQueryTemplates';
5152
import type {YdbNavigationTreeProps} from './types';
@@ -128,6 +129,7 @@ const bindActions = (
128129
dropTable: inputQuery(dropTableTemplate),
129130
manageAutoPartitioning: inputQuery(manageAutoPartitioningTemplate),
130131
selectQuery: inputQuery(selectQueryTemplate),
132+
showCreateTable: inputQuery(showCreateTableTemplate),
131133
upsertQuery: inputQuery(upsertQueryTemplate),
132134
createExternalTable: inputQuery(createExternalTableTemplate),
133135
dropExternalTable: inputQuery(dropExternalTableTemplate),
@@ -244,6 +246,7 @@ export const getActions =
244246
},
245247
],
246248
};
249+
247250
let DB_SET: ActionsSet = [[copyItem, connectToDBItem], createEntitiesSet];
248251

249252
const DIR_SET: ActionsSet = [[copyItem], createEntitiesSet];
@@ -263,6 +266,12 @@ export const getActions =
263266
DIR_SET.splice(1, 0, [createDirectoryItem]);
264267
}
265268

269+
const showCreateTableItem = {
270+
text: i18n('actions.showCreateTable'),
271+
action: actions.showCreateTable,
272+
iconStart: <Code />,
273+
};
274+
266275
const ROW_TABLE_SET: ActionsSet = [
267276
[copyItem],
268277
[
@@ -281,6 +290,7 @@ export const getActions =
281290
{text: i18n('actions.addTableIndex'), action: actions.addTableIndex},
282291
{text: i18n('actions.createCdcStream'), action: actions.createCdcStream},
283292
],
293+
[showCreateTableItem],
284294
];
285295
const COLUMN_TABLE_SET: ActionsSet = [
286296
[copyItem],
@@ -290,6 +300,7 @@ export const getActions =
290300
{text: i18n('actions.selectQuery'), action: actions.selectQuery},
291301
{text: i18n('actions.upsertQuery'), action: actions.upsertQuery},
292302
],
303+
[showCreateTableItem],
293304
];
294305

295306
const TOPIC_SET: ActionsSet = [

src/containers/Tenant/utils/schemaQueryTemplates.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ export const selectQueryTemplate = (params?: SchemaQueryParams) => {
159159
FROM ${path}
160160
${filters}LIMIT \${5:10};`;
161161
};
162+
163+
export const showCreateTableTemplate = (params?: SchemaQueryParams) => {
164+
const tablePath = params?.relativePath
165+
? `\`${normalizeParameter(params.relativePath)}\``
166+
: '${2:<my_table>}';
167+
return `SHOW CREATE TABLE ${tablePath};`;
168+
};
169+
162170
export const upsertQueryTemplate = (params?: SchemaQueryParams) => {
163171
const path = params?.relativePath
164172
? `\`${normalizeParameter(params.relativePath)}\``

0 commit comments

Comments
 (0)