Change all references to sql.DB to references to sqlx.DB
This commit is contained in:
parent
e41be44397
commit
346f26177c
|
@ -1,13 +1,12 @@
|
||||||
package peppy
|
package peppy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/jmoiron/sqlx"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetBeatmap retrieves general beatmap information.
|
// 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 whereClauses []string
|
||||||
var params []string
|
var params []string
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"git.zxq.co/ripple/rippleapi/common"
|
"git.zxq.co/ripple/rippleapi/common"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/jmoiron/sqlx"
|
||||||
)
|
)
|
||||||
|
|
||||||
var defaultResponse = []struct{}{}
|
var defaultResponse = []struct{}{}
|
||||||
|
@ -32,7 +33,7 @@ func genmodei(m string) int {
|
||||||
return v
|
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 whereClause string
|
||||||
var p string
|
var p string
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,11 @@
|
||||||
package peppy
|
package peppy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/jmoiron/sqlx"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetMatch retrieves general match information.
|
// 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)
|
c.JSON(200, defaultResponse)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,11 +7,12 @@ import (
|
||||||
|
|
||||||
"git.zxq.co/ripple/ocl"
|
"git.zxq.co/ripple/ocl"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/jmoiron/sqlx"
|
||||||
"github.com/thehowl/go-osuapi"
|
"github.com/thehowl/go-osuapi"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetUser retrieves general user information.
|
// 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") == "" {
|
if c.Query("u") == "" {
|
||||||
c.JSON(200, defaultResponse)
|
c.JSON(200, defaultResponse)
|
||||||
return
|
return
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package peppy
|
package peppy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -9,16 +8,17 @@ import (
|
||||||
"git.zxq.co/ripple/rippleapi/common"
|
"git.zxq.co/ripple/rippleapi/common"
|
||||||
"git.zxq.co/x/getrank"
|
"git.zxq.co/x/getrank"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/jmoiron/sqlx"
|
||||||
"gopkg.in/thehowl/go-osuapi.v1"
|
"gopkg.in/thehowl/go-osuapi.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetUserRecent retrieves an user's recent scores.
|
// 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))
|
getUserX(c, db, "ORDER BY scores.time DESC", common.InString(1, c.Query("limit"), 50, 10))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserBest retrieves an user's best scores.
|
// 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
|
var sb string
|
||||||
if genmodei(c.Query("m")) == 0 {
|
if genmodei(c.Query("m")) == 0 {
|
||||||
sb = "scores.pp"
|
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))
|
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)
|
whereClause, p := genUser(c, db)
|
||||||
query := fmt.Sprintf(
|
query := fmt.Sprintf(
|
||||||
`SELECT
|
`SELECT
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/jmoiron/sqlx"
|
||||||
)
|
)
|
||||||
|
|
||||||
// PeppyMethod generates a method for the peppyapi
|
// 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) {
|
return func(c *gin.Context) {
|
||||||
rateLimiter()
|
rateLimiter()
|
||||||
perUserRequestLimiter(0, c.ClientIP())
|
perUserRequestLimiter(0, c.ClientIP())
|
||||||
|
|
|
@ -5,11 +5,13 @@ import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/jmoiron/sqlx"
|
||||||
|
|
||||||
"git.zxq.co/ripple/rippleapi/common"
|
"git.zxq.co/ripple/rippleapi/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetTokenFull retrieves an user ID and their token privileges knowing their API token.
|
// 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 t common.Token
|
||||||
var privs uint64
|
var privs uint64
|
||||||
var priv8 bool
|
var priv8 bool
|
||||||
|
|
Loading…
Reference in New Issue
Block a user