Files
uzdb/internal/models/connection.go
loveuer 9874561410 refactor: Flatten directory structure
Move project files from uzdb/ subdirectory to root directory for cleaner project structure.

Changes:
- Move frontend/ to root
- Move internal/ to root
- Move build/ to root
- Move all config files (go.mod, wails.json, etc.) to root
- Remove redundant uzdb/ subdirectory nesting

Project structure is now:
├── frontend/        # React application
├── internal/        # Go backend
├── build/           # Wails build assets
├── doc/             # Design documentation
├── main.go          # Entry point
└── ...

🤖 Generated with Qoder
2026-04-04 07:14:00 -07:00

86 lines
3.0 KiB
Go

package models
import (
"time"
)
// ConnectionType represents the type of database connection
type ConnectionType string
const (
// ConnectionTypeMySQL represents MySQL database
ConnectionTypeMySQL ConnectionType = "mysql"
// ConnectionTypePostgreSQL represents PostgreSQL database
ConnectionTypePostgreSQL ConnectionType = "postgres"
// ConnectionTypeSQLite represents SQLite database
ConnectionTypeSQLite ConnectionType = "sqlite"
)
// UserConnection represents a user's database connection configuration
// This model is stored in the local SQLite database
type UserConnection struct {
ID string `gorm:"type:varchar(36);primaryKey" json:"id"`
Name string `gorm:"type:varchar(100);not null" json:"name"`
Type ConnectionType `gorm:"type:varchar(20);not null" json:"type"`
Host string `gorm:"type:varchar(255)" json:"host,omitempty"`
Port int `gorm:"type:integer" json:"port,omitempty"`
Username string `gorm:"type:varchar(100)" json:"username,omitempty"`
Password string `gorm:"type:text" json:"password"` // Encrypted password
Database string `gorm:"type:varchar(255)" json:"database"`
SSLMode string `gorm:"type:varchar(50)" json:"ssl_mode,omitempty"`
Timeout int `gorm:"type:integer;default:30" json:"timeout"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
// For SQLite connections, Database field contains the file path
}
// TableName returns the table name for UserConnection
func (UserConnection) TableName() string {
return "user_connections"
}
// CreateConnectionRequest represents a request to create a new connection
type CreateConnectionRequest struct {
Name string `json:"name" binding:"required"`
Type ConnectionType `json:"type" binding:"required"`
Host string `json:"host"`
Port int `json:"port"`
Username string `json:"username"`
Password string `json:"password"`
Database string `json:"database" binding:"required"`
SSLMode string `json:"ssl_mode"`
Timeout int `json:"timeout"`
}
// UpdateConnectionRequest represents a request to update an existing connection
type UpdateConnectionRequest struct {
Name string `json:"name"`
Type ConnectionType `json:"type"`
Host string `json:"host"`
Port int `json:"port"`
Username string `json:"username"`
Password string `json:"password"`
Database string `json:"database"`
SSLMode string `json:"ssl_mode"`
Timeout int `json:"timeout"`
}
// Validate validates the connection request
func (r *CreateConnectionRequest) Validate() error {
switch r.Type {
case ConnectionTypeMySQL, ConnectionTypePostgreSQL:
if r.Host == "" {
return ErrValidationFailed
}
if r.Port <= 0 || r.Port > 65535 {
return ErrValidationFailed
}
case ConnectionTypeSQLite:
if r.Database == "" {
return ErrValidationFailed
}
}
return nil
}