Azpect3120 83dafb8a08 FEAT: Enum support all over!
Enum table is generated below the Tables tree. Enums cannot be queried
since I don't know what I would want them to query so right now its just
for viewing. However, enum types are now displayed properly in the table
tree. I still don't know how strong the support will be for other kinds
of DBs that aren't PSQL.
2024-08-15 13:28:43 -07:00

43 lines
891 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)+EnumTree(c))
}