/* * This file is part of sdbapi * Copyright (C) 2022 Jonni Liljamo * * Licensed under GPL-3.0-only. * See LICENSE for licensing information. */ package db import ( "api/models" "log" "gorm.io/driver/postgres" "gorm.io/gorm" ) var DbConn *gorm.DB var DbError error func Connect(connString string) error { DbConn, DbError = gorm.Open(postgres.Open(connString), &gorm.Config{}) if DbError != nil { return DbError } log.Println("database connection established") return nil } func Migrate() { log.Println("running migrations") DbConn.AutoMigrate(&models.User{}) DbConn.AutoMigrate(&models.Game{}) DbConn.AutoMigrate(&models.Action{}) DbConn.AutoMigrate(&models.GameData{}) }