This commit is contained in:
Arkaprabha Chakraborty
2025-12-14 05:33:05 +05:30
parent 25ead1d8bd
commit 43c516a005
37 changed files with 1037 additions and 523 deletions

34
backend/store.go Normal file
View File

@@ -0,0 +1,34 @@
package main
import (
"fmt"
"time"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
"os"
)
type CodeURLMap struct {
Code string `gorm:"primary_key" json:"code"`
LURL string `json:"lurl" gorm:"column:lurl"`
CreatedAt time.Time `json:"created_at"`
}
var db *gorm.DB
func init() {
var err error
dbPath := os.Getenv("DB_PATH")
if dbPath == "" {
dbPath = "reduce.db"
}
db, err = gorm.Open("sqlite3", dbPath)
if err != nil {
panic(fmt.Sprintf("Failed to connect to database: %v", err))
}
// Auto-migrate database
db.AutoMigrate(&CodeURLMap{})
}