diff --git a/internal/database/create.go b/internal/database/create.go
index dce0286..e7d7772 100644
--- a/internal/database/create.go
+++ b/internal/database/create.go
@@ -13,8 +13,8 @@ import (
// in the session.
func CreateConnection(c *gin.Context) {
var (
- url string = c.PostForm("db-url")
- database string = c.PostForm("db-database")
+ url string = c.PostForm("db-url")
+ name string = c.PostForm("db-conn-name")
)
session := sessions.Default(c)
@@ -30,7 +30,7 @@ func CreateConnection(c *gin.Context) {
}
}
- connections[database] = url
+ connections[name] = url
conn_bytes, err := json.Marshal(connections)
if err != nil {
@@ -38,9 +38,9 @@ func CreateConnection(c *gin.Context) {
}
session.Set("connections", []byte(conn_bytes))
- session.Set("current", database)
+ session.Set("current", name)
session.Save()
- html := templates.ConnectionsList(connections, database)
+ html := templates.ConnectionsList(connections, name)
c.String(200, html)
}
diff --git a/internal/database/delete.go b/internal/database/delete.go
index b0b7815..073b20e 100644
--- a/internal/database/delete.go
+++ b/internal/database/delete.go
@@ -11,6 +11,7 @@ import (
func DeleteConnections(c *gin.Context) {
session := sessions.Default(c)
+ current, ok := session.Get("current").(string)
connections_bytes, ok := session.Get("connections").([]byte)
if !ok {
fmt.Println("No connections found")
@@ -29,6 +30,21 @@ func DeleteConnections(c *gin.Context) {
}
}
+ for name, url := range connections {
+ newName := c.PostForm(url)
+
+ if name == newName {
+ continue
+ }
+
+ delete(connections, name)
+ connections[newName] = url
+
+ if name == current {
+ session.Set("current", newName)
+ }
+ }
+
connections_bytes, err := json.Marshal(connections)
if err != nil {
fmt.Println(err)
diff --git a/internal/templates/manager.go b/internal/templates/manager.go
index 2a3ffcc..501f0f3 100644
--- a/internal/templates/manager.go
+++ b/internal/templates/manager.go
@@ -16,7 +16,7 @@ const MANAGER string = `
Manage Stored Connections
- Connection data is stored in the browsers session and can be deleted here.
+ Connection data is stored in the browsers session and can be renamed or deleted here.
-
+
+
+
+
- %s
%s
%s
`
const MANAGER_CLOSED string = `
-
+
`
func OpenManager(c *gin.Context) {
@@ -77,7 +79,7 @@ func OpenManager(c *gin.Context) {
var entries string
for name, url := range connections {
- entries += fmt.Sprintf(MANAGER_ENTRY, url, name, "PostgreSQL", url)
+ entries += fmt.Sprintf(MANAGER_ENTRY, url, url, name, "PostgreSQL", url)
}
c.String(200, fmt.Sprintf(MANAGER, entries))
diff --git a/web/static/scripts/modal.js b/web/static/scripts/modal.js
index bd12ae9..99e0980 100644
--- a/web/static/scripts/modal.js
+++ b/web/static/scripts/modal.js
@@ -16,6 +16,11 @@ function ShowModal() {
function HideModal() {
modal.classList.add("hidden");
modal.classList.add("opacity-0");
+
+ // Clear the inputs
+ for (const key in input) {
+ input[key].value = "";
+ }
}
const input = {
@@ -25,6 +30,7 @@ const input = {
username: document.getElementById("db-username"),
password: document.getElementById("db-password"),
database: document.getElementById("db-database"),
+ name: document.getElementById("db-conn-name"),
connectionURL: document.getElementById("db-url")
}
@@ -70,10 +76,17 @@ for (const key in input) {
ParseURL(input);
})
} else {
- input[key].addEventListener("input", () => {
- GenerateURL(input);
- })
+ // If the input changed is the database name, update the connection name as well.
+ // This will create a default connection name based on the database name.
+ if (key == "database") {
+ input[key].addEventListener("input", () => {
+ GenerateURL(input);
+ input.name.value = input[key].value;
+ })
+ } else {
+ input[key].addEventListener("input", () => {
+ GenerateURL(input);
+ })
+ }
}
}
-
-
diff --git a/web/static/styles/main.css b/web/static/styles/main.css
index c0f8439..036b6e9 100644
--- a/web/static/styles/main.css
+++ b/web/static/styles/main.css
@@ -583,6 +583,10 @@ video {
grid-column: span 2 / span 2;
}
+.m-2 {
+ margin: 0.5rem;
+}
+
.mx-1 {
margin-left: 0.25rem;
margin-right: 0.25rem;
@@ -670,6 +674,11 @@ video {
height: 100vh;
}
+.h-fit {
+ height: -moz-fit-content;
+ height: fit-content;
+}
+
.max-h-full {
max-height: 100%;
}
@@ -710,23 +719,10 @@ video {
width: 100%;
}
-.w-fit {
- width: -moz-fit-content;
- width: fit-content;
-}
-
.min-w-full {
min-width: 100%;
}
-.max-w-\[50\%\] {
- max-width: 50%;
-}
-
-.max-w-\[50\%\%\] {
- max-width: 50%%;
-}
-
.max-w-full {
max-width: 100%;
}
@@ -824,10 +820,6 @@ video {
overflow-x: auto;
}
-.overflow-x-hidden {
- overflow-x: hidden;
-}
-
.overflow-y-hidden {
overflow-y: hidden;
}
@@ -919,16 +911,6 @@ video {
background-color: rgb(239 68 68 / var(--tw-bg-opacity));
}
-.bg-red-600 {
- --tw-bg-opacity: 1;
- background-color: rgb(220 38 38 / var(--tw-bg-opacity));
-}
-
-.bg-red-300 {
- --tw-bg-opacity: 1;
- background-color: rgb(252 165 165 / var(--tw-bg-opacity));
-}
-
.bg-opacity-50 {
--tw-bg-opacity: 0.5;
}
@@ -945,6 +927,10 @@ video {
padding: 1.5rem;
}
+.p-1 {
+ padding: 0.25rem;
+}
+
.px-1 {
padding-left: 0.25rem;
padding-right: 0.25rem;
diff --git a/web/templates/index.html b/web/templates/index.html
index b5d3351..f20f1c2 100644
--- a/web/templates/index.html
+++ b/web/templates/index.html
@@ -1,214 +1,230 @@
-
-
-
- Database Query Tool
-
-
-
-
-
+
+
+
+ Database Query Tool
+
+
+
+
+
-
+
-
-
-
-
-
Database Query Tool
-
Connect and query your databases effortlessly.
+
+
+
+
+
Database Query Tool
+
Connect and query your databases effortlessly.
+
+
+
+
+ Add Connection
+
+
+ Manage Connections
+
+
+
+
+
+
+
+
+
+ database
+ loading
+ tables...
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
SQL Query
+
+
+
+
+ Run Query
+
+
+
+
+
+
+
+
+
+
+
+
+
Query running...
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Add New Connection
+
+
+
+
+
+
+
+
-
- Add Connection
-
-
- Manage Connections
-
-
-
-
-
-
-
-
-
- database
- loading tables...
-
-
-
-
-
-
+
+
+ Create Connection
-
-
-
-
-
-
-
-
-
-
-
SQL Query
-
-
-
-
- Run Query
-
-
-
-
-
-
-
-
-
-
-
-
-
Query running...
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Add New Connection
-
-
-
-
+
+ Test Connection
+
-
-
-
-
-
- Create Connection
-
-
- Test Connection
-
-
-
-
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+