Go server draft

This commit is contained in:
Imbus 2024-02-12 12:40:49 +01:00
parent 51faa74cd8
commit 29d5885b67
7 changed files with 148 additions and 0 deletions

View file

@ -0,0 +1,32 @@
package database
import (
"os"
"github.com/jmoiron/sqlx"
_ "github.com/mattn/go-sqlite3"
)
func DbConnect() *sqlx.DB {
// Check for the environment variable
dbpath := os.Getenv("SQLITE_DB_PATH")
// Default to something reasonable
if dbpath == "" {
dbpath = "./db.sqlite3"
}
// Open the database
// db, err := sqlx.Connect("sqlite3", ":memory:")
db, err := sqlx.Connect("sqlite3", dbpath)
if err != nil {
panic(err)
}
err = db.Ping()
if err != nil {
panic(err)
}
return db
}

View file

@ -0,0 +1,10 @@
package database
import (
"testing"
)
func TestDbConnect(t *testing.T) {
db := DbConnect()
_ = db
}