From 6138cfc2daaeabb51467466e7e4ad054be89d674 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Thu, 10 Mar 2022 17:54:57 +0100 Subject: [PATCH] redis add item prepare --- .../web/src/dbkeyvalue/DbKeyItemDetail.svelte | 32 +++++++++++ .../web/src/modals/DbKeyAddItemModal.svelte | 36 ++++++++++++ packages/web/src/tabs/DbKeyDetailTab.svelte | 57 +++++++++++-------- .../dbgate-plugin-redis/src/backend/driver.js | 6 +- 4 files changed, 106 insertions(+), 25 deletions(-) create mode 100644 packages/web/src/dbkeyvalue/DbKeyItemDetail.svelte create mode 100644 packages/web/src/modals/DbKeyAddItemModal.svelte diff --git a/packages/web/src/dbkeyvalue/DbKeyItemDetail.svelte b/packages/web/src/dbkeyvalue/DbKeyItemDetail.svelte new file mode 100644 index 00000000..8e927d97 --- /dev/null +++ b/packages/web/src/dbkeyvalue/DbKeyItemDetail.svelte @@ -0,0 +1,32 @@ + + +
+ {#each keyInfo.tableColumns as column} +
{column.name}
+
+ +
+ {/each} +
+ + diff --git a/packages/web/src/modals/DbKeyAddItemModal.svelte b/packages/web/src/modals/DbKeyAddItemModal.svelte new file mode 100644 index 00000000..2bdab700 --- /dev/null +++ b/packages/web/src/modals/DbKeyAddItemModal.svelte @@ -0,0 +1,36 @@ + + + + + + Add item + + + + + + handleSubmit(e.detail)} /> + + + + diff --git a/packages/web/src/tabs/DbKeyDetailTab.svelte b/packages/web/src/tabs/DbKeyDetailTab.svelte index d112beab..31dda687 100644 --- a/packages/web/src/tabs/DbKeyDetailTab.svelte +++ b/packages/web/src/tabs/DbKeyDetailTab.svelte @@ -22,6 +22,8 @@ import { showModal } from '../modals/modalTools'; import InputTextModal from '../modals/InputTextModal.svelte'; import _ from 'lodash'; + import DbKeyItemDetail from '../dbkeyvalue/DbKeyItemDetail.svelte'; + import DbKeyAddItemModal from '../modals/DbKeyAddItemModal.svelte'; export let conid; export let database; @@ -34,6 +36,7 @@ $: key = $activeDbKeysStore[`${conid}:${database}`]; let refreshToken = 0; + let editedValue = null; function handleChangeTtl(keyInfo) { showModal(InputTextModal, { @@ -65,8 +68,23 @@ } function refresh() { + editedValue = null; refreshToken += 1; } + + async function saveString() { + await apiCall('database-connections/call-method', { + conid, + database, + method: 'set', + args: [key, editedValue], + }); + refresh(); + } + + async function addItem(keyInfo) { + showModal(DbKeyAddItemModal, { keyInfo }); + } {#await apiCall('database-connections/load-key-info', { conid, database, key, refreshToken })} @@ -82,6 +100,12 @@ handleChangeTtl(keyInfo)} /> + {#if keyInfo.type == 'string'} + + {/if} + {#if keyInfo.addMethod} + addItem(keyInfo)} /> + {/if} @@ -98,17 +122,17 @@ }} /> -
- {#each keyInfo.tableColumns as column} -
{column.name}
-
- -
- {/each} -
+ + + {:else} - + { + editedValue = e.detail; + }} + /> {/if} @@ -137,21 +161,6 @@ align-self: center; } - .props { - flex: 1; - display: flex; - flex-direction: column; - } - - .colname { - margin: 10px; - } - - .colvalue { - position: relative; - flex: 1; - } - .key-name { flex-grow: 1; display: flex; diff --git a/plugins/dbgate-plugin-redis/src/backend/driver.js b/plugins/dbgate-plugin-redis/src/backend/driver.js index 399f5101..aa7b6829 100644 --- a/plugins/dbgate-plugin-redis/src/backend/driver.js +++ b/plugins/dbgate-plugin-redis/src/backend/driver.js @@ -163,18 +163,22 @@ const driver = { break; case 'list': res.tableColumns = [{ name: 'value' }]; + res.addMethod = 'rpush'; break; case 'set': res.tableColumns = [{ name: 'value' }]; res.keyColumn = 'value'; + res.addMethod = 'sadd'; break; case 'zset': - res.tableColumns = [{ name: 'value' }, { name: 'score' }]; + res.tableColumns = [{ name: 'score' }, { name: 'value' }]; res.keyColumn = 'value'; + res.addMethod = 'zadd'; break; case 'hash': res.tableColumns = [{ name: 'key' }, { name: 'value' }]; res.keyColumn = 'key'; + res.addMethod = 'hset'; break; }