From 346f26177c29dce4eb7ff57ebcd1da8aaba731d8 Mon Sep 17 00:00:00 2001 From: Howl Date: Mon, 15 Aug 2016 13:45:42 +0200 Subject: [PATCH] Change all references to sql.DB to references to sqlx.DB --- app/peppy/beatmap.go | 5 ++--- app/peppy/common.go | 3 ++- app/peppy/match.go | 5 ++--- app/peppy/user.go | 3 ++- app/peppy/user_x.go | 8 ++++---- app/peppy_method.go | 5 ++--- app/tokens.go | 4 +++- 7 files changed, 17 insertions(+), 16 deletions(-) diff --git a/app/peppy/beatmap.go b/app/peppy/beatmap.go index 2467071..7fec6ab 100644 --- a/app/peppy/beatmap.go +++ b/app/peppy/beatmap.go @@ -1,13 +1,12 @@ package peppy import ( - "database/sql" - "github.com/gin-gonic/gin" + "github.com/jmoiron/sqlx" ) // GetBeatmap retrieves general beatmap information. -func GetBeatmap(c *gin.Context, db *sql.DB) { +func GetBeatmap(c *gin.Context, db *sqlx.DB) { var whereClauses []string var params []string diff --git a/app/peppy/common.go b/app/peppy/common.go index 0a669be..87d44bb 100644 --- a/app/peppy/common.go +++ b/app/peppy/common.go @@ -7,6 +7,7 @@ import ( "git.zxq.co/ripple/rippleapi/common" "github.com/gin-gonic/gin" + "github.com/jmoiron/sqlx" ) var defaultResponse = []struct{}{} @@ -32,7 +33,7 @@ func genmodei(m string) int { return v } -func genUser(c *gin.Context, db *sql.DB) (string, string) { +func genUser(c *gin.Context, db *sqlx.DB) (string, string) { var whereClause string var p string diff --git a/app/peppy/match.go b/app/peppy/match.go index 318b834..812df68 100644 --- a/app/peppy/match.go +++ b/app/peppy/match.go @@ -2,12 +2,11 @@ package peppy import ( - "database/sql" - "github.com/gin-gonic/gin" + "github.com/jmoiron/sqlx" ) // GetMatch retrieves general match information. -func GetMatch(c *gin.Context, db *sql.DB) { +func GetMatch(c *gin.Context, db *sqlx.DB) { c.JSON(200, defaultResponse) } diff --git a/app/peppy/user.go b/app/peppy/user.go index 5d28e3c..0bbdc09 100644 --- a/app/peppy/user.go +++ b/app/peppy/user.go @@ -7,11 +7,12 @@ import ( "git.zxq.co/ripple/ocl" "github.com/gin-gonic/gin" + "github.com/jmoiron/sqlx" "github.com/thehowl/go-osuapi" ) // GetUser retrieves general user information. -func GetUser(c *gin.Context, db *sql.DB) { +func GetUser(c *gin.Context, db *sqlx.DB) { if c.Query("u") == "" { c.JSON(200, defaultResponse) return diff --git a/app/peppy/user_x.go b/app/peppy/user_x.go index 0a0547a..fbd3883 100644 --- a/app/peppy/user_x.go +++ b/app/peppy/user_x.go @@ -1,7 +1,6 @@ package peppy import ( - "database/sql" "fmt" "strings" "time" @@ -9,16 +8,17 @@ import ( "git.zxq.co/ripple/rippleapi/common" "git.zxq.co/x/getrank" "github.com/gin-gonic/gin" + "github.com/jmoiron/sqlx" "gopkg.in/thehowl/go-osuapi.v1" ) // GetUserRecent retrieves an user's recent scores. -func GetUserRecent(c *gin.Context, db *sql.DB) { +func GetUserRecent(c *gin.Context, db *sqlx.DB) { getUserX(c, db, "ORDER BY scores.time DESC", common.InString(1, c.Query("limit"), 50, 10)) } // GetUserBest retrieves an user's best scores. -func GetUserBest(c *gin.Context, db *sql.DB) { +func GetUserBest(c *gin.Context, db *sqlx.DB) { var sb string if genmodei(c.Query("m")) == 0 { sb = "scores.pp" @@ -28,7 +28,7 @@ func GetUserBest(c *gin.Context, db *sql.DB) { getUserX(c, db, "AND completed = '3' ORDER BY "+sb+" DESC", common.InString(1, c.Query("limit"), 100, 10)) } -func getUserX(c *gin.Context, db *sql.DB, orderBy string, limit int) { +func getUserX(c *gin.Context, db *sqlx.DB, orderBy string, limit int) { whereClause, p := genUser(c, db) query := fmt.Sprintf( `SELECT diff --git a/app/peppy_method.go b/app/peppy_method.go index 639084f..c70eac6 100644 --- a/app/peppy_method.go +++ b/app/peppy_method.go @@ -1,13 +1,12 @@ package app import ( - "database/sql" - "github.com/gin-gonic/gin" + "github.com/jmoiron/sqlx" ) // PeppyMethod generates a method for the peppyapi -func PeppyMethod(a func(c *gin.Context, db *sql.DB)) gin.HandlerFunc { +func PeppyMethod(a func(c *gin.Context, db *sqlx.DB)) gin.HandlerFunc { return func(c *gin.Context) { rateLimiter() perUserRequestLimiter(0, c.ClientIP()) diff --git a/app/tokens.go b/app/tokens.go index f0015e9..fa297d1 100644 --- a/app/tokens.go +++ b/app/tokens.go @@ -5,11 +5,13 @@ import ( "database/sql" "fmt" + "github.com/jmoiron/sqlx" + "git.zxq.co/ripple/rippleapi/common" ) // GetTokenFull retrieves an user ID and their token privileges knowing their API token. -func GetTokenFull(token string, db *sql.DB) (common.Token, bool) { +func GetTokenFull(token string, db *sqlx.DB) (common.Token, bool) { var t common.Token var privs uint64 var priv8 bool