model

package
v0.0.0-...-7b16907 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	OrderStartAtAsc    = &[]string{"event.start_at_unix ASC", "event.id ASC"}
	OrderStartAtDesc   = &[]string{"event.start_at_unix DESC", "event.id ASC"}
	OrderCreatedAtAsc  = &[]string{"event.id ASC"}
	OrderCreatedAtDesc = &[]string{"event.id DESC"}
)

Order values.

Functions

func CleanTags

func CleanTags(ctx context.Context, db bun.IDB) error

CleanTags deletes tags which have no event relations.

func DeleteEvent

func DeleteEvent(ctx context.Context, db *bun.DB, ev *domain.Event) error

DeleteEvent deletes an event..

func DeleteExpiredInvites

func DeleteExpiredInvites(ctx context.Context, db *bun.DB) error

DeleteExpiredInvites deletes expired invites.

func DeleteInvite

func DeleteInvite(ctx context.Context, db bun.IDB, token uuid.UUID) error

DeleteInvite deletes an invite.

func DeleteTags

func DeleteTags(ctx context.Context, db bun.IDB, eventID snowflake.ID) error

DeleteTags deletes event's tags.

func DeleteUser

func DeleteUser(ctx context.Context, db bun.IDB, id snowflake.ID) error

DeleteUser deletes a user.

func GetEvent

func GetEvent(ctx context.Context, db *bun.DB, id snowflake.ID) (*domain.Event, error)

GetEvent retrieves a single event.

func GetInvite

func GetInvite(ctx context.Context, db *bun.DB, token uuid.UUID) (*domain.Invite, error)

GetInvite returns an invite.

func GetSettings

func GetSettings(ctx context.Context, db bun.IDB) (*domain.Settings, error)

GetSettings returns settings.

func GetUser

func GetUser(ctx context.Context, db bun.IDB, userID snowflake.ID) (*domain.User, error)

GetUser returns a user.

func GetUserByUsername

func GetUserByUsername(ctx context.Context, db bun.IDB, username string) (*domain.User, error)

GetUserByUsername returns a user.

func InsertEvent

func InsertEvent(ctx context.Context, db *bun.DB, ev *domain.Event) error

InsertEvent inserts an event to the database.

func InsertInvite

func InsertInvite(ctx context.Context, db *bun.DB, invite *domain.Invite) error

InsertInvite inserts a new event to the database.

func InsertSettings

func InsertSettings(ctx context.Context, db bun.IDB, s *domain.Settings) error

InsertSettings inserts settings.

func InsertUser

func InsertUser(ctx context.Context, db bun.IDB, user *domain.User) error

InsertUser inserts a user into the database.

func ListStopWords

func ListStopWords(ctx context.Context, db bun.IDB) ([]string, error)

ListStopWords lists all stopwords.

func ListTags

func ListTags(ctx context.Context, db bun.IDB, eventStartAtFrom, eventStartAtUntil time.Time, userID snowflake.ID, limit int) ([]*domain.Tag, error)

ListTags lists most popular tags, excluding stopwords.

func ListUsers

func ListUsers(ctx context.Context, db bun.IDB) ([]*domain.User, error)

ListUsers lists users.

func SetStopWords

func SetStopWords(ctx context.Context, db bun.IDB, words domain.StopWordList) error

SetStopWords sets stop words in the database.

func UpdateEvent

func UpdateEvent(ctx context.Context, db *bun.DB, ev *domain.Event) error

UpdateEvent updates an event.

func UpdateSettings

func UpdateSettings(ctx context.Context, db bun.IDB, s *domain.Settings) error

UpdateSettings updates settings.

func UpdateUser

func UpdateUser(ctx context.Context, db bun.IDB, user *domain.User) error

UpdateUser updates a user.

Types

type Event

type Event struct {
	ID             snowflake.ID `bun:"id,pk"`
	StartAtUnix    int64        `bun:"start_at_unix"`
	TimezoneOffset int          `bun:"tz_offset"`
	Title          string       `bun:"title"`
	Description    string       `bun:"description"`
	URL            string       `bun:"url"`
	Location       string       `bun:"location"`
	OSMType        string       `bun:"osm_type"`
	OSMID          uint64       `bun:"osm_id"`
	Latitude       float64      `bun:"latitude"`
	Longitude      float64      `bun:"longitude"`

	IsDraft bool         `bun:"is_draft"`
	UserID  snowflake.ID `bun:"user_id"`

	bun.BaseModel `bun:"events"`
}

Event is the event database model.

type EventOrder

type EventOrder *[]string

EventOrder is an event ordering type.

type EventsQueryBuilder

type EventsQueryBuilder func(*SelectQuery)

EventsQueryBuilder builds an event list query.

func NewEventsQuery

func NewEventsQuery() EventsQueryBuilder

NewEventsQuery creates a new events list query. Note: cursor is ID cursor when sorting by created at and offset when sorting by start time.

func (EventsQueryBuilder) List

func (build EventsQueryBuilder) List(ctx context.Context, db *bun.DB) ([]*domain.Event, error)

List executes the query.

func (EventsQueryBuilder) WithIncludeDrafts

func (build EventsQueryBuilder) WithIncludeDrafts() EventsQueryBuilder

WithIncludeDrafts includes drafts.

func (EventsQueryBuilder) WithLimit

func (build EventsQueryBuilder) WithLimit(limit int) EventsQueryBuilder

WithLimit configures results limit.

func (EventsQueryBuilder) WithOrder

func (build EventsQueryBuilder) WithOrder(cursor int64, orders EventOrder) EventsQueryBuilder

WithOrder configures results order.

func (EventsQueryBuilder) WithSearchText

func (build EventsQueryBuilder) WithSearchText(s string) EventsQueryBuilder

WithSearchText filters the result by search text.

func (EventsQueryBuilder) WithStartAtFrom

func (build EventsQueryBuilder) WithStartAtFrom(from time.Time) EventsQueryBuilder

WithStartAtFrom configures minimum start at time.

func (EventsQueryBuilder) WithStartAtUntil

func (build EventsQueryBuilder) WithStartAtUntil(until time.Time) EventsQueryBuilder

WithStartAtUntil configures maximum start at time.

func (EventsQueryBuilder) WithUserID

func (build EventsQueryBuilder) WithUserID(userID snowflake.ID) EventsQueryBuilder

WithUserID filters the event list by user ID.

type Invite

type Invite struct {
	Token          uuid.UUID    `bun:"token"`
	ValidUntilUnix int64        `bun:"valid_until_unix"`
	CreatedBy      snowflake.ID `bun:"created_by"`

	bun.BaseModel `bun:"invites"`
}

Invite is the invite database model.

type SelectQuery

type SelectQuery struct {
	*bun.SelectQuery
	// contains filtered or unexported fields
}

SelectQuery is an events select query.

type Settings

type Settings struct {
	ID          int64  `bun:"id"`
	Title       string `bun:"title"`
	Description string `bun:"description"`

	bun.BaseModel `bun:"settings"`
}

Settings is the settings database model.

type StopWord

type StopWord struct {
	Word  string `bun:"word,pk"`
	Order uint64 `bun:"sort_order"`

	bun.BaseModel `bun:"stopwords"`
}

StopWord is the stopword database model.

type Tag

type Tag struct {
	ID         snowflake.ID `bun:"id,pk"`
	Name       string       `bun:"name"`
	EventCount uint64       `bun:"event_count,scanonly"`

	bun.BaseModel `bun:"tags"`
}

Tag is the tag database model.

type User

type User struct {
	ID       snowflake.ID `bun:"id,pk"`
	Username string       `bun:"username"`
	Password []byte       `bun:"password"`
	Role     string       `bun:"role"`

	bun.BaseModel `bun:"users"`
}

User is the user database model.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL