Use type alias for fields (#3)

model_post
Etzelia 3 years ago committed by Gitea
parent 3ce698c397
commit 2bd753efa7

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

@ -1,15 +1,15 @@
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"
ApplicationLink = Link
ApplicationID = ID
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
)

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

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

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

@ -1,12 +1,12 @@
package django
const (
PlayerID = ID
PlayerAuthUserID = "auth_user_id"
PlayerUUID = "uuid"
PlayerUsername = "username"
PlayerApplicationID = "application_id"
PlayerFirstSeen = "first_seen"
PlayerLastSeen = "last_seen"
PlayerLink = Link
PlayerID = ID
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
)

@ -1,16 +1,16 @@
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"
TicketLink = Link
TicketID = ID
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
)

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

@ -1,13 +1,13 @@
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"
UserSettingsLink = Link
UserSettingsID = ID
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
)

Loading…
Cancel
Save