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

View File

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

View File

@ -8,26 +8,6 @@ import (
"git.zxq.co/ripple/rippleapi/common" "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 { type userScore struct {
score score
Beatmap beatmap `json:"beatmap"` Beatmap beatmap `json:"beatmap"`

View File

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

View File

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