mirror of
https://github.com/arkorty/Reduce.git
synced 2026-03-18 00:47:10 +00:00
overhaul
This commit is contained in:
34
backend/store.go
Normal file
34
backend/store.go
Normal 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{})
|
||||
}
|
||||
Reference in New Issue
Block a user