db

package
v0.0.0-...-77bbea8 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package db implements DownToMeet server's connection to the PostgreSQL database. It also contains the database model definitions as GORM models.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(logger FieldLogger, dsn string) (*gorm.DB, error)

Get returns a new gorm.DB from the given Data Source Name (DSN) connection string.

func MeetupIDFromString

func MeetupIDFromString(s string) (uint, error)

MeetupIDFromString reverses Meetup.IDString.

func TagIDFromString

func TagIDFromString(s string) (uint, error)

TagIDFromString reverses Tag.IDString.

func UserIDFromString

func UserIDFromString(s string) (uint, error)

UserIDFromString reverses User.IDString.

Types

type Coordinates

type Coordinates struct {
	Lat, Lon *float64
}

Coordinates represent WGS 84 coordinates of the earth. It is not a database model but rather stored as a part of MeetupLocation.

type FieldLogger

type FieldLogger interface {
	log.FieldLogger
	WithContext(ctx context.Context) *log.Entry
}

FieldLogger is the same as log.FieldLogger, but with an additional WithContext method.

type Logger

type Logger struct {
	Logger FieldLogger
}

Logger is an adapter from logrus' logger to GORM.

func (Logger) Error

func (l Logger) Error(ctx context.Context, s string, i ...interface{})

Error implements GORM's logger.Interface.

func (Logger) Info

func (l Logger) Info(ctx context.Context, s string, i ...interface{})

Info implements GORM's logger.Interface.

func (Logger) LogMode

LogMode implements GORM's logger.Interface and does nothing.

func (Logger) Trace

func (l Logger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)

Trace implements GORM's logger.Interface.

func (Logger) Warn

func (l Logger) Warn(ctx context.Context, s string, i ...interface{})

Warn implements GORM's logger.Interface.

type Meetup

type Meetup struct {
	gorm.Model
	Title             string
	Time              time.Time
	Description       string
	Tags              []*Tag `gorm:"many2many:meetup_tag;"`
	MaxCapacity       int64
	MinCapacity       int64
	Owner             uint
	Attendees         []*User        `gorm:"many2many:meetup_user_attend;"`
	Location          MeetupLocation `gorm:"embedded;embeddedPrefix:location_"`
	PendingAttendees  []*User        `gorm:"many2many:meetup_user_pending;"`
	RejectedAttendees []*User        `gorm:"many2many:meetup_user_rejected;"`
	Cancelled         bool
}

Meetup is the database model for a meetup.

func (*Meetup) IDString

func (m *Meetup) IDString() string

IDString returns the meetup's ID as a string.

type MeetupLocation

type MeetupLocation struct {
	Coordinates
	URL  string
	Name string
}

MeetupLocation represents where a meetup could be held. It is not a database model but rather stored as a part of Meetup.

type Tag

type Tag struct {
	gorm.Model
	Name    string    `gorm:"uniqueIndex"`
	Users   []*User   `gorm:"many2many:tag_user;"`
	Meetups []*Meetup `gorm:"many2many:meetup_tag;"`
}

Tag is the database model for tags.

func (*Tag) IDString

func (t *Tag) IDString() string

IDString returns the tag's ID, represented as a string.

type User

type User struct {
	gorm.Model
	Email           string `gorm:"uniqueIndex"`
	Name            string
	ContactInfo     string
	ProfilePic      *string
	FacebookID      *string     `gorm:"uniqueIndex"`
	GoogleID        *string     `gorm:"uniqueIndex"`
	Location        Coordinates `gorm:"embedded;embeddedPrefix:location_"`
	OwnedMeetups    []*Meetup   `gorm:"foreignKey:Owner"`
	Attending       []*Meetup   `gorm:"many2many:meetup_user_attend;"`
	Tags            []*Tag      `gorm:"many2many:tag_user;"`
	PendingApproval []*Meetup   `gorm:"many2many:meetup_user_pending;"`
}

User is the database model for users.

func (*User) IDString

func (u *User) IDString() string

IDString returns the user's ID, represented as a string.

Jump to

Keyboard shortcuts

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