Skip to content

Commit 617ef5e

Browse files
committed
fix: snippets
1 parent 8af383c commit 617ef5e

File tree

4 files changed

+38
-41
lines changed

4 files changed

+38
-41
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ export function NewSQL() {
5050
text: i18n('action.select-rows'),
5151
action: actions.selectQuery,
5252
},
53-
{
54-
text: i18n('action.select-from-external-table'),
55-
action: actions.selectQueryFromExternalTable,
56-
},
5753
{
5854
text: i18n('action.delete-rows'),
5955
action: actions.deleteRows,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"action.update-table": "Update table",
88
"action.alter-table": "Alter table",
99
"action.select-rows": "Select from a table",
10-
"action.select-from-external-table": "Select from external table",
1110
"action.delete-rows": "Delete rows",
1211
"action.drop-table": "Drop table",
1312
"action.add-index": "Add index",

src/containers/Tenant/utils/newSQLQueryActions.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export const bindActions = (changeUserInput: (input: string) => void) => {
4343
upsertQuery: inputQuery(upsertQueryTemplate),
4444
createExternalTable: inputQuery(createExternalTableTemplate),
4545
dropExternalTable: inputQuery(dropExternalTableTemplate),
46-
selectQueryFromExternalTable: inputQuery(selectQueryTemplate),
4746
createTopic: inputQuery(createTopicTemplate),
4847
alterTopic: inputQuery(alterTopicTemplate),
4948
dropTopic: inputQuery(dropTopicTemplate),

src/containers/Tenant/utils/schemaQueryTemplates.ts

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ PARTITION BY HASH(id)
6060
WITH (STORE = COLUMN)`;
6161
};
6262
export const createAsyncReplicationTemplate = () => {
63-
return `CREATE OBJECT secret_name (TYPE SECRET) WITH value="secret_value";
63+
return `-- docs: https://ydb.tech/docs/en/yql/reference/syntax/create-async-replication
64+
CREATE OBJECT secret_name (TYPE SECRET) WITH value="secret_value";
6465
6566
CREATE ASYNC REPLICATION my_replication
66-
FOR \${1:<table_name>} AS \${2:local_table_name} --[, \`/remote_database/another_table_name\` AS \`another_local_table_name\` ...]
67+
FOR \${1:<original_table>} AS \${2:replica_table} --[, \`/remote_database/another_table_name\` AS \`another_local_table_name\` ...]
6768
WITH (
6869
CONNECTION_STRING="grpcs://mydb.ydb.tech:2135/?database=/\${3:<remote_database>}",
6970
TOKEN_SECRET_NAME = "secret_name"
@@ -81,24 +82,27 @@ export const alterTableTemplate = (params?: SchemaQueryParams) => {
8182
ALTER TABLE ${path}
8283
-- RENAME TO new_table_name
8384
-- DROP COLUMN some_existing_column
84-
ADD COLUMN numeric_column Int32;`;
85+
\${2:ADD COLUMN numeric_column Int32};`;
8586
};
8687
export const selectQueryTemplate = (params?: SchemaQueryParams) => {
87-
const path = params?.relativePath ? `\`${params?.relativePath}\`` : '${1:<my_table>}';
88-
const columns = params?.tableData?.map((column) => '`' + column.name + '`').join(', ') || '*';
88+
const path = params?.relativePath ? `\`${params?.relativePath}\`` : '${2:<my_table>}';
89+
const columns =
90+
params?.tableData?.map((column) => '`' + column.name + '`').join(', ') || '${1:*}';
8991

9092
return `SELECT ${columns}
91-
FROM ${path}
92-
LIMIT 10;`;
93+
FROM ${path}
94+
WHERE \${3:Key1 = 1}
95+
ORDER BY \${4:Key1}
96+
LIMIT \${5:10};`;
9397
};
9498
export const upsertQueryTemplate = (params?: SchemaQueryParams) => {
9599
const path = params?.relativePath ? `\`${params?.relativePath}\`` : '${1:<my_table>}';
96100
const columns =
97-
params?.tableData?.map((column) => `\`${column.name}\``).join(', ') || `id, name`;
98-
101+
params?.tableData?.map((column) => `\`${column.name}\``).join(', ') || '${2:id, name}';
102+
const values = params?.tableData ? '${3: }' : '${3:1, "foo"}';
99103
return `UPSERT INTO ${path}
100-
( ${columns} )
101-
VALUES ( );`;
104+
( ${columns} )
105+
VALUES ( ${values} );`;
102106
};
103107

104108
export const dropExternalTableTemplate = (params?: SchemaQueryParams) => {
@@ -191,7 +195,8 @@ export const dropAsyncReplicationTemplate = (params?: SchemaQueryParams) => {
191195

192196
export const alterAsyncReplicationTemplate = (params?: SchemaQueryParams) => {
193197
const path = params?.relativePath ? `\`${params?.relativePath}\`` : '${1:<my_replication>}';
194-
return `ALTER ASYNC REPLICATION ${path} SET (STATE = "DONE", FAILOVER_MODE = "FORCE");`;
198+
return `-- docs: https://ydb.tech/docs/en/yql/reference/syntax/alter-async-replication
199+
ALTER ASYNC REPLICATION ${path} SET (STATE = "DONE", FAILOVER_MODE = "FORCE");`;
195200
};
196201

197202
export const addTableIndex = (params?: SchemaQueryParams) => {
@@ -202,19 +207,20 @@ export const addTableIndex = (params?: SchemaQueryParams) => {
202207
export const dropTableIndex = (params?: SchemaQueryParams) => {
203208
const indexName = params?.relativePath.split('/').pop();
204209
const path = params?.relativePath.split('/').slice(0, -1).join('/');
205-
return `ALTER TABLE \`${path || '${1:<my_table>}'}\` DROP INDEX ${indexName || '${2:<index_name>}'};`;
210+
const pathSnippet = path ? `\`${path}\`` : '${1:<my_table>}';
211+
return `ALTER TABLE ${pathSnippet} DROP INDEX ${indexName || '${2:<index_name>}'};`;
206212
};
207213

208214
export const createCdcStreamTemplate = (params?: SchemaQueryParams) => {
209215
const path = params?.relativePath ? `\`${params?.relativePath}\`` : '${1:<my_table>}';
210-
return `-- docs: https://ydb.tech/docs/en/yql/reference/syntax/create_changefeed
216+
return `-- docs: https://ydb.tech/docs/en/yql/reference/syntax/alter_table/changefeed
211217
ALTER TABLE ${path} ADD CHANGEFEED \${2:changefeed_name} WITH (
212-
MODE = \${3:mode}, -- KEYS_ONLY, UPDATES, NEW_IMAGE, OLD_IMAGE, or NEW_AND_OLD_IMAGES
213-
FORMAT = \${4:format}, -- JSON or DEBEZIUM_JSON
214-
VIRTUAL_TIMESTAMPS = \${5:virtualTimestamps}, -- true or false
215-
RETENTION_PERIOD = \${6:retentionPeriod}, -- Interval value, e.g., Interval('PT24H')
216-
TOPIC_MIN_ACTIVE_PARTITIONS = \${7:topicMinActivePartitions},
217-
INITIAL_SCAN = \${8:initialScan} -- true or false
218+
MODE = \${3:'UPDATES'}, -- KEYS_ONLY, UPDATES, NEW_IMAGE, OLD_IMAGE, or NEW_AND_OLD_IMAGES
219+
FORMAT = \${4:'JSON'}, -- JSON or DEBEZIUM_JSON
220+
VIRTUAL_TIMESTAMPS = \${5:TRUE}, -- true or false
221+
RETENTION_PERIOD = \${6:Interval('PT12H')}, -- Interval value, e.g., Interval('PT24H')
222+
-- TOPIC_MIN_ACTIVE_PARTITIONS: The number of topic partitions. By default, the number of topic partitions is equal to the number of table partitions
223+
INITIAL_SCAN = \${8:TRUE} -- true or false
218224
)
219225
220226
-- MODE options:
@@ -233,7 +239,7 @@ CREATE GROUP \${1:group_name}
233239

234240
export const createUserTemplate = () => {
235241
return `-- docs: https://ydb.tech/docs/en/yql/reference/syntax/create-user
236-
CREATE USER \${1:user_name} [option]
242+
CREATE USER \${1:user_name} PASSWORD \${2:'password'}
237243
-- user_name: The name of the user. It may contain lowercase Latin letters and digits.
238244
-- option: The password of the user:
239245
-- PASSWORD 'password' creates a user with the password password. The ENCRYPTED option is always enabled.
@@ -244,20 +250,20 @@ export const deleteRowsTemplate = (params?: SchemaQueryParams) => {
244250
const path = params?.relativePath ? `\`${params?.relativePath}\`` : '${1:<my_table>}';
245251
return `-- docs: https://ydb.tech/docs/en/yql/reference/syntax/delete
246252
DELETE FROM ${path}
247-
WHERE Key1 == \${2:key1} AND Key2 >= \${3:key2};`;
253+
WHERE \${2:Key1 = 1};`;
248254
};
249255

250256
export const dropGroupTemplate = () => {
251257
return `-- docs: https://ydb.tech/docs/en/yql/reference/syntax/drop-group
252-
DROP GROUP [ IF EXISTS ] \${1:<group_name>} [, ...]
258+
DROP GROUP \${1:<group_name>}
253259
254260
-- IF EXISTS: Suppress an error if the group doesn't exist.
255261
-- group_name: The name of the group to be deleted.`;
256262
};
257263

258264
export const dropUserTemplate = () => {
259265
return `-- docs: https://ydb.tech/docs/en/yql/reference/syntax/drop-user
260-
DROP USER [ IF EXISTS ] \${1:<user_name>} [, ...]
266+
DROP USER \${1:<user_name>}
261267
262268
-- IF EXISTS: Suppress an error if the user doesn't exist.
263269
-- user_name: The name of the user to be deleted.`;
@@ -267,11 +273,9 @@ export const grantPrivilegeTemplate = (params?: SchemaQueryParams) => {
267273
const path = params?.relativePath
268274
? `\`${params?.relativePath}\``
269275
: '${2:<path_to_scheme_object>}';
270-
return `
271-
GRANT \${1:<permission_name>} [, ...] | ALL [PRIVILEGES]
272-
ON ${path} [, ...]
273-
TO \${3:<role_name>} [, ...]
274-
[WITH GRANT OPTION]
276+
return `GRANT \${1:<permission_name>}
277+
ON ${path}
278+
TO \${3:<role_name>}
275279
276280
-- permission_name: The name of the access right to schema objects that needs to be assigned.
277281
-- path_to_scheme_object: The path to the schema object for which rights are being granted.
@@ -286,10 +290,9 @@ export const revokePrivilegeTemplate = (params?: SchemaQueryParams) => {
286290
const path = params?.relativePath
287291
? `\`${params?.relativePath}\``
288292
: '${2:<path_to_scheme_object>}';
289-
return `
290-
REVOKE [GRANT OPTION FOR] \${1:<permission_name>} [, ...] | ALL [PRIVILEGES]
291-
ON ${path} [, ...]
292-
FROM \${3:<role_name>} [, ...]
293+
return `REVOKE \${1:<permission_name>}
294+
ON ${path}
295+
FROM \${3:<role_name>}
293296
294297
-- permission_name: The name of the access right to schema objects that needs to be revoked.
295298
-- path_to_scheme_object: The path to the schema object from which rights are being revoked.
@@ -303,8 +306,8 @@ export const updateTableTemplate = (params?: SchemaQueryParams) => {
303306
const path = params?.relativePath ? `\`${params?.relativePath}\`` : '${1:<my_table>}';
304307
return `-- docs: https://ydb.tech/docs/en/yql/reference/syntax/update
305308
UPDATE ${path}
306-
SET Value1 = YQL::ToString(\${2:value2} + 1), Value2 = \${3:value2} - 1
307-
WHERE Key1 > \${4:key1};`;
309+
SET \${2:Column1 = 'foo', Column2 = 'bar'}
310+
WHERE \${3:Key1 = 1};`;
308311
};
309312

310313
export const dropTableTemplate = (params?: SchemaQueryParams) => {

0 commit comments

Comments
 (0)