initial commit

This commit is contained in:
CalvinLiu123
2025-09-10 17:18:18 +07:00
commit 719e856bc4
8 changed files with 301 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
package db
import (
"database/sql"
"fmt"
_ "github.com/lib/pq"
)
const (
host = "202.46.28.160"
port = 45432
user = "5803024003"
password = "pw5803024003"
dbname = "5803024003_db"
)
func InitDB() {
// connection string
psqlconn := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", host, port, user, password, dbname)
// open database
db, err := sql.Open("postgres", psqlconn)
CheckError(err)
// close database
defer db.Close()
// check db
err = db.Ping()
CheckError(err)
fmt.Println("Connected!")
}
func CheckError(err error) {
if err != nil {
panic(err)
}
}
+21
View File
@@ -0,0 +1,21 @@
package db
import (
"time"
)
// Region represents a geographical region (e.g., "West Campus", "Downtown")
type Groups struct {
GroupID int `json:"regionId" db:"region_id"`
GroupName string `json:"name" db:"name"`
}
// Building represents a building within a region
type Tasks struct {
TaskID int `json:"buildingId" db:"building_id"`
TaskName string `json:"name" db:"name"`
TaskDescription int `json:"floorCount,omitempty" db:"floor_count"`
GroupID int `json:"regionId" db:"region_id"`
IsDone bool `json:"isDone" db:"is_done"`
CreatedAt time.Time `json:"createdAt" db:"created_at"`
}