Initial sqlite3 compatibility

This commit is contained in:
2018-11-13 00:58:44 +00:00
parent e15ca16d17
commit 80e66d2b32
7 changed files with 123 additions and 170 deletions

9
app.go
View File

@@ -4,7 +4,7 @@ import (
"database/sql"
"flag"
"fmt"
_ "github.com/go-sql-driver/mysql"
_ "github.com/mattn/go-sqlite3"
"html/template"
"net/http"
"os"
@@ -258,7 +258,12 @@ func Serve() {
func connectToDatabase(app *app) {
log.Info("Connecting to database...")
db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=true", app.cfg.Database.User, app.cfg.Database.Password, app.cfg.Database.Host, app.cfg.Database.Port, app.cfg.Database.Database))
if app.cfg.Database.Type != "sqlite3" {
log.Error("This fork of writefreely only supports sqlite3 databases")
os.Exit(1)
}
db, err := sql.Open("sqlite3", app.cfg.Database.Database)
if err != nil {
log.Error("%s", err)
os.Exit(1)