Use type alias for fields (#3)
parent
3ce698c397
commit
2bd753efa7
|
@ -2,9 +2,9 @@ package django
|
||||||
|
|
||||||
const (
|
const (
|
||||||
AlertID = ID
|
AlertID = ID
|
||||||
AlertUserID = "user_id"
|
AlertUserID Field = "user_id"
|
||||||
AlertMessage = "message"
|
AlertMessage Field = "message"
|
||||||
AlertSeen = "seen"
|
AlertSeen Field = "seen"
|
||||||
AlertDate = "date"
|
AlertDate Field = "date"
|
||||||
AlertLink = Link
|
AlertLink = Link
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,14 +2,14 @@ package django
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ApplicationID = ID
|
ApplicationID = ID
|
||||||
ApplicationUsername = "username"
|
ApplicationUsername Field = "username"
|
||||||
ApplicationAge = "age"
|
ApplicationAge Field = "age"
|
||||||
ApplicationPlayerType = "player_type"
|
ApplicationPlayerType Field = "player_type"
|
||||||
ApplicationEverBanned = "ever_banned"
|
ApplicationEverBanned Field = "ever_banned"
|
||||||
ApplicationEverBannedExplanation = "ever_banned_explanation"
|
ApplicationEverBannedExplanation Field = "ever_banned_explanation"
|
||||||
ApplicationReference = "reference"
|
ApplicationReference Field = "reference"
|
||||||
ApplicationReadRules = "read_rules"
|
ApplicationReadRules Field = "read_rules"
|
||||||
ApplicationAccepted = "accepted"
|
ApplicationAccepted Field = "accepted"
|
||||||
ApplicationDate = "date"
|
ApplicationDate Field = "date"
|
||||||
ApplicationLink = Link
|
ApplicationLink = Link
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,9 +5,11 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Field string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ID = "id"
|
ID Field = "id"
|
||||||
Link = "link"
|
Link Field = "link"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Builder struct {
|
type Builder struct {
|
||||||
|
@ -22,22 +24,22 @@ func (db *Builder) QueryString() string {
|
||||||
return "?" + strings.Join(db.Params, "&")
|
return "?" + strings.Join(db.Params, "&")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Builder) Exact(field, value string) *Builder {
|
func (db *Builder) Exact(field Field, value string) *Builder {
|
||||||
db.Params = append(db.Params, fmt.Sprintf("%s__exact=%s", field, value))
|
db.Params = append(db.Params, fmt.Sprintf("%s__exact=%s", field, value))
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Builder) IExact(field, value string) *Builder {
|
func (db *Builder) IExact(field Field, value string) *Builder {
|
||||||
db.Params = append(db.Params, fmt.Sprintf("%s__iexact=%s", field, value))
|
db.Params = append(db.Params, fmt.Sprintf("%s__iexact=%s", field, value))
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Builder) Contains(field, value string) *Builder {
|
func (db *Builder) Contains(field Field, value string) *Builder {
|
||||||
db.Params = append(db.Params, fmt.Sprintf("%s__contains=%s", field, value))
|
db.Params = append(db.Params, fmt.Sprintf("%s__contains=%s", field, value))
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Builder) IContains(field, value string) *Builder {
|
func (db *Builder) IContains(field Field, value string) *Builder {
|
||||||
db.Params = append(db.Params, fmt.Sprintf("%s__icontains=%s", field, value))
|
db.Params = append(db.Params, fmt.Sprintf("%s__icontains=%s", field, value))
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
@ -47,117 +49,117 @@ func (db *Builder) In(field string, values ...string) *Builder {
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Builder) Gt(field, value string) *Builder {
|
func (db *Builder) Gt(field Field, value string) *Builder {
|
||||||
db.Params = append(db.Params, fmt.Sprintf("%s__gt=%s", field, value))
|
db.Params = append(db.Params, fmt.Sprintf("%s__gt=%s", field, value))
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Builder) Gte(field, value string) *Builder {
|
func (db *Builder) Gte(field Field, value string) *Builder {
|
||||||
db.Params = append(db.Params, fmt.Sprintf("%s__gte=%s", field, value))
|
db.Params = append(db.Params, fmt.Sprintf("%s__gte=%s", field, value))
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Builder) Lt(field, value string) *Builder {
|
func (db *Builder) Lt(field Field, value string) *Builder {
|
||||||
db.Params = append(db.Params, fmt.Sprintf("%s__lt=%s", field, value))
|
db.Params = append(db.Params, fmt.Sprintf("%s__lt=%s", field, value))
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Builder) Lte(field, value string) *Builder {
|
func (db *Builder) Lte(field Field, value string) *Builder {
|
||||||
db.Params = append(db.Params, fmt.Sprintf("%s__lte=%s", field, value))
|
db.Params = append(db.Params, fmt.Sprintf("%s__lte=%s", field, value))
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Builder) Startswith(field, value string) *Builder {
|
func (db *Builder) Startswith(field Field, value string) *Builder {
|
||||||
db.Params = append(db.Params, fmt.Sprintf("%s__startswith=%s", field, value))
|
db.Params = append(db.Params, fmt.Sprintf("%s__startswith=%s", field, value))
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Builder) IStartswith(field, value string) *Builder {
|
func (db *Builder) IStartswith(field Field, value string) *Builder {
|
||||||
db.Params = append(db.Params, fmt.Sprintf("%s__istartswith=%s", field, value))
|
db.Params = append(db.Params, fmt.Sprintf("%s__istartswith=%s", field, value))
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Builder) Endswith(field, value string) *Builder {
|
func (db *Builder) Endswith(field Field, value string) *Builder {
|
||||||
db.Params = append(db.Params, fmt.Sprintf("%s__endswith=%s", field, value))
|
db.Params = append(db.Params, fmt.Sprintf("%s__endswith=%s", field, value))
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Builder) IEndswith(field, value string) *Builder {
|
func (db *Builder) IEndswith(field Field, value string) *Builder {
|
||||||
db.Params = append(db.Params, fmt.Sprintf("%s__iendswith=%s", field, value))
|
db.Params = append(db.Params, fmt.Sprintf("%s__iendswith=%s", field, value))
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Builder) Range(field, from, to string) *Builder {
|
func (db *Builder) Range(field Field, from, to string) *Builder {
|
||||||
db.Params = append(db.Params, fmt.Sprintf("%s__range=(%s,%s)", field, from, to))
|
db.Params = append(db.Params, fmt.Sprintf("%s__range=(%s,%s)", field, from, to))
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Builder) Date(field, value string) *Builder {
|
func (db *Builder) Date(field Field, value string) *Builder {
|
||||||
db.Params = append(db.Params, fmt.Sprintf("%s__date=%s", field, value))
|
db.Params = append(db.Params, fmt.Sprintf("%s__date=%s", field, value))
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Builder) Year(field, value string) *Builder {
|
func (db *Builder) Year(field Field, value string) *Builder {
|
||||||
db.Params = append(db.Params, fmt.Sprintf("%s__year=%s", field, value))
|
db.Params = append(db.Params, fmt.Sprintf("%s__year=%s", field, value))
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Builder) Month(field, value string) *Builder {
|
func (db *Builder) Month(field Field, value string) *Builder {
|
||||||
db.Params = append(db.Params, fmt.Sprintf("%s__month=%s", field, value))
|
db.Params = append(db.Params, fmt.Sprintf("%s__month=%s", field, value))
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Builder) Day(field, value string) *Builder {
|
func (db *Builder) Day(field Field, value string) *Builder {
|
||||||
db.Params = append(db.Params, fmt.Sprintf("%s__day=%s", field, value))
|
db.Params = append(db.Params, fmt.Sprintf("%s__day=%s", field, value))
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Builder) Week(field, value string) *Builder {
|
func (db *Builder) Week(field Field, value string) *Builder {
|
||||||
db.Params = append(db.Params, fmt.Sprintf("%s__week=%s", field, value))
|
db.Params = append(db.Params, fmt.Sprintf("%s__week=%s", field, value))
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Builder) WeekDay(field, value string) *Builder {
|
func (db *Builder) WeekDay(field Field, value string) *Builder {
|
||||||
db.Params = append(db.Params, fmt.Sprintf("%s__week_day=%s", field, value))
|
db.Params = append(db.Params, fmt.Sprintf("%s__week_day=%s", field, value))
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Builder) Quarter(field, value string) *Builder {
|
func (db *Builder) Quarter(field Field, value string) *Builder {
|
||||||
db.Params = append(db.Params, fmt.Sprintf("%s__quarter=%s", field, value))
|
db.Params = append(db.Params, fmt.Sprintf("%s__quarter=%s", field, value))
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Builder) Time(field, value string) *Builder {
|
func (db *Builder) Time(field Field, value string) *Builder {
|
||||||
db.Params = append(db.Params, fmt.Sprintf("%s__time=%s", field, value))
|
db.Params = append(db.Params, fmt.Sprintf("%s__time=%s", field, value))
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Builder) Hour(field, value string) *Builder {
|
func (db *Builder) Hour(field Field, value string) *Builder {
|
||||||
db.Params = append(db.Params, fmt.Sprintf("%s__hour=%s", field, value))
|
db.Params = append(db.Params, fmt.Sprintf("%s__hour=%s", field, value))
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Builder) Minute(field, value string) *Builder {
|
func (db *Builder) Minute(field Field, value string) *Builder {
|
||||||
db.Params = append(db.Params, fmt.Sprintf("%s__minute=%s", field, value))
|
db.Params = append(db.Params, fmt.Sprintf("%s__minute=%s", field, value))
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Builder) Second(field, value string) *Builder {
|
func (db *Builder) Second(field Field, value string) *Builder {
|
||||||
db.Params = append(db.Params, fmt.Sprintf("%s__second=%s", field, value))
|
db.Params = append(db.Params, fmt.Sprintf("%s__second=%s", field, value))
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Builder) IsNull(field, value string) *Builder {
|
func (db *Builder) IsNull(field Field, value string) *Builder {
|
||||||
db.Params = append(db.Params, fmt.Sprintf("%s__isnull=%s", field, value))
|
db.Params = append(db.Params, fmt.Sprintf("%s__isnull=%s", field, value))
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Builder) Regex(field, value string) *Builder {
|
func (db *Builder) Regex(field Field, value string) *Builder {
|
||||||
db.Params = append(db.Params, fmt.Sprintf("%s__regex=r'%s'", field, value))
|
db.Params = append(db.Params, fmt.Sprintf("%s__regex=r'%s'", field, value))
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Builder) IRegex(field, value string) *Builder {
|
func (db *Builder) IRegex(field Field, value string) *Builder {
|
||||||
db.Params = append(db.Params, fmt.Sprintf("%s__iregex=r'%s'", field, value))
|
db.Params = append(db.Params, fmt.Sprintf("%s__iregex=r'%s'", field, value))
|
||||||
return db
|
return db
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package django
|
||||||
|
|
||||||
const (
|
const (
|
||||||
IPID = ID
|
IPID = ID
|
||||||
IPPlayerID = "player_id"
|
IPPlayerID Field = "player_id"
|
||||||
IPLastUsed = "last_used"
|
IPLastUsed Field = "last_used"
|
||||||
IPLink = Link
|
IPLink = Link
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,10 +2,10 @@ package django
|
||||||
|
|
||||||
const (
|
const (
|
||||||
NoteID = ID
|
NoteID = ID
|
||||||
NotePlayerID = "player_id"
|
NotePlayerID Field = "player_id"
|
||||||
NoteMessage = "message"
|
NoteMessage Field = "message"
|
||||||
NoteImportance = "importance"
|
NoteImportance Field = "importance"
|
||||||
NoteStaffID = "staff_id"
|
NoteStaffID Field = "staff_id"
|
||||||
NoteDate = "date"
|
NoteDate Field = "date"
|
||||||
NoteLink = Link
|
NoteLink = Link
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,11 +2,11 @@ package django
|
||||||
|
|
||||||
const (
|
const (
|
||||||
PlayerID = ID
|
PlayerID = ID
|
||||||
PlayerAuthUserID = "auth_user_id"
|
PlayerAuthUserID Field = "auth_user_id"
|
||||||
PlayerUUID = "uuid"
|
PlayerUUID Field = "uuid"
|
||||||
PlayerUsername = "username"
|
PlayerUsername Field = "username"
|
||||||
PlayerApplicationID = "application_id"
|
PlayerApplicationID Field = "application_id"
|
||||||
PlayerFirstSeen = "first_seen"
|
PlayerFirstSeen Field = "first_seen"
|
||||||
PlayerLastSeen = "last_seen"
|
PlayerLastSeen Field = "last_seen"
|
||||||
PlayerLink = Link
|
PlayerLink = Link
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,15 +2,15 @@ package django
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TicketID = ID
|
TicketID = ID
|
||||||
TicketPlayerID = "player_id"
|
TicketPlayerID Field = "player_id"
|
||||||
TicketMessage = "message"
|
TicketMessage Field = "message"
|
||||||
TicketPriority = "priority"
|
TicketPriority Field = "priority"
|
||||||
TicketStaffID = "staff_id"
|
TicketStaffID Field = "staff_id"
|
||||||
TicketResolved = "resolved"
|
TicketResolved Field = "resolved"
|
||||||
TicketWorld = "world"
|
TicketWorld Field = "world"
|
||||||
TicketX = "x"
|
TicketX Field = "x"
|
||||||
TicketY = "Y"
|
TicketY Field = "Y"
|
||||||
TicketZ = "Z"
|
TicketZ Field = "Z"
|
||||||
TicketDate = "date"
|
TicketDate Field = "date"
|
||||||
TicketLink = Link
|
TicketLink = Link
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,10 +2,10 @@ package django
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TicketNoteID = ID
|
TicketNoteID = ID
|
||||||
TicketNoteAuthorID = "author_id"
|
TicketNoteAuthorID Field = "author_id"
|
||||||
TicketNoteTicketID = "ticket_id"
|
TicketNoteTicketID Field = "ticket_id"
|
||||||
TicketNoteMessage = "message"
|
TicketNoteMessage Field = "message"
|
||||||
TicketNoteLastUpdate = "last_update"
|
TicketNoteLastUpdate Field = "last_update"
|
||||||
TicketNoteDate = "date"
|
TicketNoteDate Field = "date"
|
||||||
TicketNoteLink = Link
|
TicketNoteLink = Link
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,12 +2,12 @@ package django
|
||||||
|
|
||||||
const (
|
const (
|
||||||
UserSettingsID = ID
|
UserSettingsID = ID
|
||||||
UserSettingsAuthUserID = "auth_user_id"
|
UserSettingsAuthUserID Field = "auth_user_id"
|
||||||
UserSettingsDefaultResults = "default_results"
|
UserSettingsDefaultResults Field = "default_results"
|
||||||
UserSettingsDefaultTheme = "default_theme"
|
UserSettingsDefaultTheme Field = "default_theme"
|
||||||
UserSettingsDefaultTimezone = "default_timezone"
|
UserSettingsDefaultTimezone Field = "default_timezone"
|
||||||
UserSettingsSearchPlayerIP = "search_player_ip"
|
UserSettingsSearchPlayerIP Field = "search_player_ip"
|
||||||
UserSettingsShowTimestampChat = "show_timestamp_chat"
|
UserSettingsShowTimestampChat Field = "show_timestamp_chat"
|
||||||
UserSettingsLastIP = "last_ip"
|
UserSettingsLastIP Field = "last_ip"
|
||||||
UserSettingsLink = Link
|
UserSettingsLink = Link
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue