Tested sqlite db

This commit is contained in:
kolaente 2017-12-01 11:33:40 +01:00
parent b84bfa563c
commit b0219e9052
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
4 changed files with 11 additions and 5 deletions

3
.gitignore vendored
View File

@ -7,4 +7,5 @@ frontend/dist/
frontend/npm-debug.log* frontend/npm-debug.log*
frontend/yarn-debug.log* frontend/yarn-debug.log*
frontend/yarn-error.log* frontend/yarn-error.log*
config.ini config.ini
db.db

View File

@ -2,6 +2,7 @@ package models
import ( import (
"fmt" "fmt"
//_ "github.com/mattn/go-sqlite3" // Because.
_ "github.com/go-sql-driver/mysql" // Because. _ "github.com/go-sql-driver/mysql" // Because.
"github.com/go-xorm/core" "github.com/go-xorm/core"
"github.com/go-xorm/xorm" "github.com/go-xorm/xorm"
@ -13,6 +14,7 @@ func getEngine() (*xorm.Engine, error) {
connStr := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8&parseTime=true", connStr := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8&parseTime=true",
Config.Database.User, Config.Database.Password, Config.Database.Host, Config.Database.Database) Config.Database.User, Config.Database.Password, Config.Database.Host, Config.Database.Database)
return xorm.NewEngine("mysql", connStr) return xorm.NewEngine("mysql", connStr)
//return xorm.NewEngine("sqlite3", "./db.db")
} }
// SetEngine sets the xorm.Engine // SetEngine sets the xorm.Engine
@ -22,6 +24,11 @@ func SetEngine() (err error) {
return fmt.Errorf("Failed to connect to database: %v", err) return fmt.Errorf("Failed to connect to database: %v", err)
} }
// Cache
cacher := xorm.NewLRUCacher(xorm.NewMemoryStore(), 1000)
x.SetDefaultCacher(cacher)
x.SetMapper(core.GonicMapper{}) x.SetMapper(core.GonicMapper{})
// Sync dat shit // Sync dat shit

View File

@ -5,6 +5,7 @@ import (
"net/http" "net/http"
"git.mowie.cc/konrad/Library/models" "git.mowie.cc/konrad/Library/models"
"fmt"
) )
// BookList is the handler to list books // BookList is the handler to list books
@ -16,6 +17,7 @@ func BookList(c echo.Context) error {
list, err := models.ListBooks(search) list, err := models.ListBooks(search)
if err != nil { if err != nil {
fmt.Println(err)
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting books"}) return c.JSON(http.StatusInternalServerError, models.Message{"Error getting books"})
} }

4
vendor/vendor.json vendored
View File

@ -36,10 +36,6 @@
"path": "github.com/go-ini/iniv1.28.2", "path": "github.com/go-ini/iniv1.28.2",
"revision": "" "revision": ""
}, },
{
"path": "github.com/go-sql-driver/go-sqlite3",
"revision": ""
},
{ {
"checksumSHA1": "fSlTr0rwLji0DfsUOKYLkGUkiWo=", "checksumSHA1": "fSlTr0rwLji0DfsUOKYLkGUkiWo=",
"path": "github.com/go-sql-driver/mysql", "path": "github.com/go-sql-driver/mysql",