Use type alias for fields (#3)

model_post
Etzelia 2019-10-07 19:21:04 +02:00 committed by Gitea
parent 3ce698c397
commit 2bd753efa7
9 changed files with 95 additions and 93 deletions

View File

@ -2,9 +2,9 @@ package django
const (
AlertID = ID
AlertUserID = "user_id"
AlertMessage = "message"
AlertSeen = "seen"
AlertDate = "date"
AlertUserID Field = "user_id"
AlertMessage Field = "message"
AlertSeen Field = "seen"
AlertDate Field = "date"
AlertLink = Link
)

View File

@ -2,14 +2,14 @@ package django
const (
ApplicationID = ID
ApplicationUsername = "username"
ApplicationAge = "age"
ApplicationPlayerType = "player_type"
ApplicationEverBanned = "ever_banned"
ApplicationEverBannedExplanation = "ever_banned_explanation"
ApplicationReference = "reference"
ApplicationReadRules = "read_rules"
ApplicationAccepted = "accepted"
ApplicationDate = "date"
ApplicationUsername Field = "username"
ApplicationAge Field = "age"
ApplicationPlayerType Field = "player_type"
ApplicationEverBanned Field = "ever_banned"
ApplicationEverBannedExplanation Field = "ever_banned_explanation"
ApplicationReference Field = "reference"
ApplicationReadRules Field = "read_rules"
ApplicationAccepted Field = "accepted"
ApplicationDate Field = "date"
ApplicationLink = Link
)

View File

@ -5,9 +5,11 @@ import (
"strings"
)
type Field string
const (
ID = "id"
Link = "link"
ID Field = "id"
Link Field = "link"
)
type Builder struct {
@ -22,22 +24,22 @@ func (db *Builder) QueryString() string {
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))
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))
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))
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))
return db
}
@ -47,117 +49,117 @@ func (db *Builder) In(field string, values ...string) *Builder {
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
return db
}

View File

@ -2,7 +2,7 @@ package django
const (
IPID = ID
IPPlayerID = "player_id"
IPLastUsed = "last_used"
IPPlayerID Field = "player_id"
IPLastUsed Field = "last_used"
IPLink = Link
)

View File

@ -2,10 +2,10 @@ package django
const (
NoteID = ID
NotePlayerID = "player_id"
NoteMessage = "message"
NoteImportance = "importance"
NoteStaffID = "staff_id"
NoteDate = "date"
NotePlayerID Field = "player_id"
NoteMessage Field = "message"
NoteImportance Field = "importance"
NoteStaffID Field = "staff_id"
NoteDate Field = "date"
NoteLink = Link
)

View File

@ -2,11 +2,11 @@ package django
const (
PlayerID = ID
PlayerAuthUserID = "auth_user_id"
PlayerUUID = "uuid"
PlayerUsername = "username"
PlayerApplicationID = "application_id"
PlayerFirstSeen = "first_seen"
PlayerLastSeen = "last_seen"
PlayerAuthUserID Field = "auth_user_id"
PlayerUUID Field = "uuid"
PlayerUsername Field = "username"
PlayerApplicationID Field = "application_id"
PlayerFirstSeen Field = "first_seen"
PlayerLastSeen Field = "last_seen"
PlayerLink = Link
)

View File

@ -2,15 +2,15 @@ package django
const (
TicketID = ID
TicketPlayerID = "player_id"
TicketMessage = "message"
TicketPriority = "priority"
TicketStaffID = "staff_id"
TicketResolved = "resolved"
TicketWorld = "world"
TicketX = "x"
TicketY = "Y"
TicketZ = "Z"
TicketDate = "date"
TicketPlayerID Field = "player_id"
TicketMessage Field = "message"
TicketPriority Field = "priority"
TicketStaffID Field = "staff_id"
TicketResolved Field = "resolved"
TicketWorld Field = "world"
TicketX Field = "x"
TicketY Field = "Y"
TicketZ Field = "Z"
TicketDate Field = "date"
TicketLink = Link
)

View File

@ -2,10 +2,10 @@ package django
const (
TicketNoteID = ID
TicketNoteAuthorID = "author_id"
TicketNoteTicketID = "ticket_id"
TicketNoteMessage = "message"
TicketNoteLastUpdate = "last_update"
TicketNoteDate = "date"
TicketNoteAuthorID Field = "author_id"
TicketNoteTicketID Field = "ticket_id"
TicketNoteMessage Field = "message"
TicketNoteLastUpdate Field = "last_update"
TicketNoteDate Field = "date"
TicketNoteLink = Link
)

View File

@ -2,12 +2,12 @@ package django
const (
UserSettingsID = ID
UserSettingsAuthUserID = "auth_user_id"
UserSettingsDefaultResults = "default_results"
UserSettingsDefaultTheme = "default_theme"
UserSettingsDefaultTimezone = "default_timezone"
UserSettingsSearchPlayerIP = "search_player_ip"
UserSettingsShowTimestampChat = "show_timestamp_chat"
UserSettingsLastIP = "last_ip"
UserSettingsAuthUserID Field = "auth_user_id"
UserSettingsDefaultResults Field = "default_results"
UserSettingsDefaultTheme Field = "default_theme"
UserSettingsDefaultTimezone Field = "default_timezone"
UserSettingsSearchPlayerIP Field = "search_player_ip"
UserSettingsShowTimestampChat Field = "show_timestamp_chat"
UserSettingsLastIP Field = "last_ip"
UserSettingsLink = Link
)