Change all references to sql.DB to references to sqlx.DB

This commit is contained in:
Howl 2016-08-15 13:45:42 +02:00
parent e41be44397
commit 346f26177c
7 changed files with 17 additions and 16 deletions

View File

@ -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

View File

@ -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

View File

@ -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)
}

View File

@ -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

View File

@ -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

View File

@ -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())

View File

@ -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