postgres

package
Version: v0.0.0-...-c118757 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2019 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnString

func ConnString(host string, port int, user, password, dbName string) string

ConnString builds a connection string

Types

type Db

type Db struct {
	*sql.DB
}

Db wraps a database with helper functions

func New

func New(connString string) (*Db, error)

New creates a new DB connection for the resolver

func (*Db) AttachUserRole

func (d *Db) AttachUserRole(u *models.User, r *models.Role) error

AttachUserRole creates a relation between a user and a given role

func (*Db) Auth

func (d *Db) Auth(user *models.User, password string) error

Auth authorizes a user

func (*Db) CheckUserRole

func (d *Db) CheckUserRole(userid, roleid uuid.UUID) error

CheckUserRole checks to see if a user has a given role

func (*Db) CreateGroup

func (d *Db) CreateGroup(g *models.Group) error

CreateGroup inserts a group into the database

func (*Db) CreateImage

func (d *Db) CreateImage(i *models.Image, data []byte) error

CreateImage generates missing data and inserts an entry in the database

func (*Db) CreateProfile

func (d *Db) CreateProfile(p *models.Profile) error

CreateProfile Inserts a profile into the database

func (*Db) CreateRole

func (d *Db) CreateRole(r *models.Role) error

CreateRole sets the remaining fields and create's a new Role

func (*Db) CreateUser

func (d *Db) CreateUser(u *models.User) error

CreateUser a new user in the given database

func (*Db) GetAllImages

func (d *Db) GetAllImages() ([]models.Image, error)

GetAllImages returns every image

func (*Db) GetGroupByID

func (d *Db) GetGroupByID(id uuid.UUID) (*models.Group, error)

GetGroupByID is used by the database resolver to find groups

func (*Db) GetGroupByName

func (d *Db) GetGroupByName(name string) (*models.Group, error)

GetGroupByName retrieves a group by it's name

func (*Db) GetGroupByQuery

func (d *Db) GetGroupByQuery(query string, arg ...interface{}) ([]models.Group, error)

GetGroupByQuery runs the query and returns a group and error

func (*Db) GetGroupMembers

func (d *Db) GetGroupMembers(gid uuid.UUID) ([]models.User, error)

GetGroupMembers retrives a list of users belonging to a group

func (*Db) GetGroupsByOwnerID

func (d *Db) GetGroupsByOwnerID(ownerid uuid.UUID) ([]models.Group, error)

GetGroupsByOwnerID retrives a list of groups by the owner_id

func (*Db) GetImageByID

func (d *Db) GetImageByID(id uuid.UUID) (*models.Image, error)

GetImageByID retrieves an image by it's ID

func (*Db) GetImageByQuery

func (d *Db) GetImageByQuery(query string, arg ...interface{}) ([]models.Image, error)

GetImageByQuery retrieves models using a query

func (*Db) GetImageBySha256

func (d *Db) GetImageBySha256(sum string) (*models.Image, error)

GetImageBySha256 retrieves an image based on it's sha256 sum

func (*Db) GetImagesByOwnerID

func (d *Db) GetImagesByOwnerID(ownerid uuid.UUID) ([]models.Image, error)

GetImagesByOwnerID retrives a list of images based on the given owner_id

func (*Db) GetProfileByID

func (d *Db) GetProfileByID(id uuid.UUID) (*models.Profile, error)

GetProfileByID retrieves a profile via it's ID

func (*Db) GetProfileByQuery

func (d *Db) GetProfileByQuery(query string, args ...interface{}) ([]models.Profile, error)

GetProfileByQuery returns a list of profiles matching the query and given arguments.

func (*Db) GetProfileByUserID

func (d *Db) GetProfileByUserID(userid uuid.UUID) (*models.Profile, error)

GetProfileByUserID retrieves a profile via it's User ID association

func (*Db) GetRoleByID

func (d *Db) GetRoleByID(id uuid.UUID) (*models.Role, error)

GetRoleByID retrieves a role with it's user ID's

func (*Db) GetRoleByName

func (d *Db) GetRoleByName(name string) (*models.Role, error)

GetRoleByName finds a role using it's name

func (*Db) GetRoleByQuery

func (d *Db) GetRoleByQuery(query string, arg ...interface{}) ([]models.Role, error)

GetRoleByQuery runs a query to get models

func (*Db) GetSharedImagesByUserID

func (d *Db) GetSharedImagesByUserID(userid uuid.UUID) ([]models.Image, error)

GetSharedImagesByUserID returns the list of images by the UserID

func (*Db) GetUserByEmail

func (d *Db) GetUserByEmail(email string) (*models.User, error)

GetUserByEmail returns a user model via the email address

func (*Db) GetUserByID

func (d *Db) GetUserByID(id uuid.UUID) (*models.User, error)

GetUserByID is used by the database resolver to find users

func (*Db) GetUserByQuery

func (d *Db) GetUserByQuery(query string, args ...interface{}) ([]models.User, error)

GetUserByQuery runs the given query with the given argument and returns a user model

func (*Db) GetUserByUsername

func (d *Db) GetUserByUsername(username string) (*models.User, error)

GetUserByUsername returns a user model containing the username

func (*Db) GetUserRoles

func (d *Db) GetUserRoles(userid uuid.UUID) ([]models.Role, error)

GetUserRoles returns a list of roles held by a user ID

func (*Db) GetUsersByID

func (d *Db) GetUsersByID(ids ...uuid.UUID) ([]models.User, error)

GetUsersByID returns a slice of user models from the list of given ids

func (*Db) ShareImage

func (d *Db) ShareImage(imageshare *models.ImageShare) error

ShareImage inserts an image share

func (*Db) UpdateUserToken

func (d *Db) UpdateUserToken(uid uuid.UUID, newtoken string) (*models.User, error)

UpdateUserToken updates a users token TODO: Factor using a standard Update method

func (*Db) VerifyToken

func (d *Db) VerifyToken(id, token uuid.UUID) bool

VerifyToken authenticates a token against the authenticated users id

type InvalidError

type InvalidError struct {
	// contains filtered or unexported fields
}

InvalidError error type

func NewInvalidError

func NewInvalidError(err error) *InvalidError

NewInvalidError generates a meaningful error message when a model isn't found.

func (*InvalidError) Error

func (m *InvalidError) Error() string

Error fullfills the interface for errors

type ModelFound

type ModelFound struct {
	// contains filtered or unexported fields
}

ModelFound error type

func NewModelFound

func NewModelFound(err error) *ModelFound

NewModelFound generates a meaningful error message when a model is found.

func (*ModelFound) Error

func (m *ModelFound) Error() string

Error fullfills the interface for errors

type ModelNotFound

type ModelNotFound struct {
	// contains filtered or unexported fields
}

ModelNotFound error type

func NewModelNotFound

func NewModelNotFound(err error) *ModelNotFound

NewModelNotFound generates a meaningful error message when a model isn't found.

func (*ModelNotFound) Error

func (m *ModelNotFound) Error() string

Error fullfills the interface for errors

type UnknownError

type UnknownError struct {
	// contains filtered or unexported fields
}

UnknownError is to log unknown errors

func NewUnknownError

func NewUnknownError(err error) *UnknownError

NewUnknownError generates a meaningful error message when an unknown error occurs

func (*UnknownError) Error

func (u *UnknownError) Error() string

Error fullfills the interface for errors

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL