@@ -190,6 +190,9 @@ document.getElementById("driver").addEventListener("input", function () {
190190const paramsBody = document . getElementById ( "additionalParamsBody" ) ;
191191const paramsEmpty = document . getElementById ( "additionalParamsEmpty" ) ;
192192
193+ const envVarsBody = document . getElementById ( "envVarsBody" ) ;
194+ const envVarsEmpty = document . getElementById ( "envVarsEmpty" ) ;
195+
193196// Handle database type selection
194197const dbTypeWidget = document . getElementById ( "dbTypeWidget" ) ;
195198const dbTypeHidden = document . getElementById ( "databaseType" ) ;
@@ -434,6 +437,75 @@ function collectAdditionalParameters() {
434437 return result ;
435438}
436439
440+ // --- Environment Variables ---
441+ function refreshEnvVarsEmptyState ( ) {
442+ envVarsEmpty . style . display =
443+ envVarsBody . children . length === 0 ? "block" : "none" ;
444+ }
445+
446+ function createEnvVarRow ( key = "" , value = "" ) {
447+ const row = document . createElement ( "tr" ) ;
448+
449+ const keyCell = document . createElement ( "td" ) ;
450+ const keyInput = document . createElement ( "input" ) ;
451+ keyInput . className = "param-input" ;
452+ keyInput . value = key ;
453+ keyCell . appendChild ( keyInput ) ;
454+
455+ const valueCell = document . createElement ( "td" ) ;
456+ const valueInput = document . createElement ( "input" ) ;
457+ valueInput . className = "param-input" ;
458+ valueInput . value = value ;
459+ valueCell . appendChild ( valueInput ) ;
460+
461+ const actionCell = document . createElement ( "td" ) ;
462+ const deleteBtn = document . createElement ( "button" ) ;
463+ deleteBtn . type = "button" ;
464+ deleteBtn . className = "secondary icon-btn" ;
465+ deleteBtn . textContent = "x" ;
466+ deleteBtn . title = "Delete environment variable" ;
467+ deleteBtn . setAttribute ( "aria-label" , "Delete environment variable" ) ;
468+ deleteBtn . addEventListener ( "click" , ( ) => {
469+ row . remove ( ) ;
470+ refreshEnvVarsEmptyState ( ) ;
471+ } ) ;
472+ actionCell . appendChild ( deleteBtn ) ;
473+
474+ row . appendChild ( keyCell ) ;
475+ row . appendChild ( valueCell ) ;
476+ row . appendChild ( actionCell ) ;
477+ envVarsBody . appendChild ( row ) ;
478+ refreshEnvVarsEmptyState ( ) ;
479+ }
480+
481+ function loadInitialEnvVars ( ) {
482+ const initialEnvVars = initial . connection . envVars || { } ;
483+ Object . entries ( initialEnvVars ) . forEach ( ( [ key , value ] ) => {
484+ createEnvVarRow ( String ( key || "" ) , String ( value || "" ) ) ;
485+ } ) ;
486+ refreshEnvVarsEmptyState ( ) ;
487+ }
488+
489+ function collectEnvVars ( ) {
490+ const result = { } ;
491+ const rows = Array . from ( envVarsBody . querySelectorAll ( "tr" ) ) ;
492+ for ( const row of rows ) {
493+ const inputs = row . querySelectorAll ( "input" ) ;
494+ if ( inputs . length < 2 ) {
495+ continue ;
496+ }
497+
498+ const key = inputs [ 0 ] . value . trim ( ) ;
499+ if ( ! key ) {
500+ continue ;
501+ }
502+
503+ result [ key ] = inputs [ 1 ] . value ;
504+ }
505+
506+ return result ;
507+ }
508+
437509function updateConnectionString ( ) {
438510 const host = document . getElementById ( "host" ) . value . trim ( ) || "localhost" ;
439511 const port = document . getElementById ( "port" ) . value . trim ( ) ;
@@ -525,6 +597,7 @@ async function copyConnectionString() {
525597}
526598
527599loadInitialParams ( ) ;
600+ loadInitialEnvVars ( ) ;
528601updateConnectionString ( ) ;
529602
530603// When user directly edits connection string, mark it to preserve the value
@@ -537,6 +610,10 @@ document.getElementById("addParam").addEventListener("click", () => {
537610 updateConnectionString ( ) ;
538611} ) ;
539612
613+ document . getElementById ( "addEnvVar" ) . addEventListener ( "click" , ( ) => {
614+ createEnvVarRow ( "" , "" ) ;
615+ } ) ;
616+
540617document
541618 . getElementById ( "copyConnectionString" )
542619 . addEventListener ( "click" , ( ) => {
@@ -616,6 +693,7 @@ saveBtn.addEventListener("click", () => {
616693 connectionString : realConnectionString ,
617694 databaseType : selectedDbType || undefined ,
618695 additionalParameters,
696+ envVars : collectEnvVars ( ) ,
619697 } ;
620698
621699 vscode . postMessage ( { command : "save" , data } ) ;
0 commit comments