From cc2c55b20f62ce0698d0b3360dd093268de9cb90 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Sat, 10 Apr 2021 17:03:00 +0200 Subject: [PATCH] generate script menu for collections --- .../web/src/appobj/DatabaseObjectAppObject.svelte | 11 +++++++++++ packages/web/src/utility/applyScriptTemplate.ts | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/packages/web/src/appobj/DatabaseObjectAppObject.svelte b/packages/web/src/appobj/DatabaseObjectAppObject.svelte index 4202837c..984f6046 100644 --- a/packages/web/src/appobj/DatabaseObjectAppObject.svelte +++ b/packages/web/src/appobj/DatabaseObjectAppObject.svelte @@ -206,6 +206,17 @@ label: 'Export', isExport: true, }, + { + divider: true, + }, + { + label: 'JS: dropCollection()', + scriptTemplate: 'dropCollection', + }, + { + label: 'JS: find()', + scriptTemplate: 'findCollection', + }, ], }; diff --git a/packages/web/src/utility/applyScriptTemplate.ts b/packages/web/src/utility/applyScriptTemplate.ts index 083de618..c6dc82ed 100644 --- a/packages/web/src/utility/applyScriptTemplate.ts +++ b/packages/web/src/utility/applyScriptTemplate.ts @@ -45,6 +45,12 @@ export default async function applyScriptTemplate(scriptTemplate, extensions, pr if (procedureInfo) dmp.put('^execute %f', procedureInfo); return dmp.s; } + if (scriptTemplate == 'dropCollection') { + return `db.collection('${props.pureName}').drop()`; + } + if (scriptTemplate == 'findCollection') { + return `db.collection('${props.pureName}').find()`; + } return null; }