Azpect3120 276a6be7b9 FEAT: Table tree is now displayed!
Has no functionality yet, but that's next. And not sure how it works
when switching connections.
2024-08-07 18:08:40 -07:00

43 lines
879 B
Go

package database
import (
"encoding/json"
"fmt"
"github.com/Azpect3120/Web-Database-Viewer/internal/templates"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
)
// Change the current connection in the session
func ChangeConnection(c *gin.Context) {
conn := c.PostForm("connected-database")
session := sessions.Default(c)
conn_bytes, ok := session.Get("connections").([]byte)
if !ok {
c.String(200, templates.ConnectionsList(nil, ""))
return
}
var connections map[string]string
if err := json.Unmarshal(conn_bytes, &connections); err != nil {
c.String(200, templates.ConnectionsList(nil, ""))
fmt.Println(err)
return
}
var name string
for n, c := range connections {
if c == conn {
name = n
break
}
}
session.Set("current", name)
session.Save()
c.String(200, templates.ConnectionsList(connections, name)+TableTree(c))
}