Use sqlx instead of sql. Rewrite of most clusterfucks incoming

This commit is contained in:
Howl 2016-08-15 13:37:03 +02:00
parent c3b56164f5
commit e41be44397
5 changed files with 11 additions and 29 deletions

View File

@ -1,7 +1,6 @@
package app
import (
"database/sql"
"fmt"
"git.zxq.co/ripple/rippleapi/app/internals"
@ -11,15 +10,16 @@ import (
"github.com/getsentry/raven-go"
"github.com/gin-gonic/contrib/gzip"
"github.com/gin-gonic/gin"
"github.com/jmoiron/sqlx"
)
var (
db *sql.DB
db *sqlx.DB
cf common.Conf
)
// Start begins taking HTTP connections.
func Start(conf common.Conf, dbO *sql.DB) *gin.Engine {
func Start(conf common.Conf, dbO *sqlx.DB) *gin.Engine {
db = dbO
cf = conf

View File

@ -5,6 +5,8 @@ import (
"database/sql"
"fmt"
"github.com/jmoiron/sqlx"
"git.zxq.co/ripple/rippleapi/common"
"git.zxq.co/ripple/schiavolib"
"golang.org/x/crypto/bcrypt"
@ -204,7 +206,7 @@ func TokenFixPrivilegesGET(md common.MethodData) common.CodeMessager {
return common.SimpleResponse(200, "Privilege fixing started!")
}
func fixPrivileges(user int, db *sql.DB) {
func fixPrivileges(user int, db *sqlx.DB) {
var wc string
var params = make([]interface{}, 0, 1)
if user != 0 {

View File

@ -8,26 +8,6 @@ import (
"git.zxq.co/ripple/rippleapi/common"
)
type score struct {
ID int `json:"id"`
BeatmapMD5 string `json:"beatmap_md5"`
Score int64 `json:"score"`
MaxCombo int `json:"max_combo"`
FullCombo bool `json:"full_combo"`
Mods int `json:"mods"`
Count300 int `json:"count_300"`
Count100 int `json:"count_100"`
Count50 int `json:"count_50"`
CountGeki int `json:"count_geki"`
CountKatu int `json:"count_katu"`
CountMiss int `json:"count_miss"`
Time time.Time `json:"time"`
PlayMode int `json:"play_mode"`
Accuracy float64 `json:"accuracy"`
PP float32 `json:"pp"`
Completed int `json:"completed"`
}
type userScore struct {
score
Beatmap beatmap `json:"beatmap"`

View File

@ -1,16 +1,16 @@
package common
import (
"database/sql"
"encoding/json"
"github.com/gin-gonic/gin"
"github.com/jmoiron/sqlx"
)
// MethodData is a struct containing the data passed over to an API method.
type MethodData struct {
User Token
DB *sql.DB
DB *sqlx.DB
RequestData RequestData
C *gin.Context
}

View File

@ -1,7 +1,6 @@
package main
import (
"database/sql"
"fmt"
"log"
"strings"
@ -12,6 +11,7 @@ import (
"git.zxq.co/ripple/schiavolib"
// Golint pls dont break balls
_ "github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx"
)
// Version is the git hash of the application. Do not edit. This is
@ -24,7 +24,7 @@ func init() {
common.Version = Version
}
var db *sql.DB
var db *sqlx.DB
func main() {
fmt.Print("Ripple API")
@ -49,7 +49,7 @@ func main() {
}
var err error
db, err = sql.Open(conf.DatabaseType, conf.DSN)
db, err = sqlx.Open(conf.DatabaseType, conf.DSN)
if err != nil {
schiavo.Bunker.Send(err.Error())
log.Fatalln(err)