db

package
v0.0.0-...-01732ca Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//DuplicateUserError is a postgres specific error for duplicate users in our users db
	DuplicateUserError = "pq: duplicate key value violates unique constraint \"users_username_key\""
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DatabaseConnection

type DatabaseConnection struct {
	*sql.DB
	// contains filtered or unexported fields
}

DatabaseConnection represents a single connection to the database

func NewDatabaseConnection

func NewDatabaseConnection(logger *logrus.Logger) (DatabaseConnection, error)

NewDatabaseConnection intiializes the database connection and returns a DatabaseConnection.

func (*DatabaseConnection) Connect

func (connection *DatabaseConnection) Connect() error

Connect connets to the database and begins necessary migrations.

func (DatabaseConnection) CreateSession

func (db DatabaseConnection) CreateSession(user User) (Session, error)

CreateSession makes a session given a User

func (DatabaseConnection) CreateUser

func (db DatabaseConnection) CreateUser(username string, password []byte) error

CreateUser insersts a user into the database

func (DatabaseConnection) GetDevice

func (db DatabaseConnection) GetDevice(deviceID uuid.UUID) (Device, error)

GetDevice gets a Device from the database, given a deviceID

func (DatabaseConnection) GetSession

func (db DatabaseConnection) GetSession(sessionID uuid.UUID) (Session, error)

GetSession gets the user associated with a session

func (DatabaseConnection) GetUser

func (db DatabaseConnection) GetUser(username string) (User, error)

GetUser gets a user from the database and returns a User.

func (DatabaseConnection) GetUserByID

func (db DatabaseConnection) GetUserByID(id int) (User, error)

GetUserByID gets a user from the database and returns a User.

func (DatabaseConnection) GetUserCount

func (db DatabaseConnection) GetUserCount() (int, error)

GetUserCount gets the number of registered users in the database. The first return value will be -1 in error.

func (DatabaseConnection) MakeFileBlock

func (db DatabaseConnection) MakeFileBlock(user User) (uuid.UUID, error)

MakeFileBlock makes a file block in the database

func (DatabaseConnection) RecordFile

func (db DatabaseConnection) RecordFile(fileName string, blockID uuid.UUID) error

RecordFile stores an MMS file to the database

func (DatabaseConnection) RegisterDeviceToUser

func (db DatabaseConnection) RegisterDeviceToUser(user User) (Device, error)

RegisterDeviceToUser registers a device for a user

func (DatabaseConnection) RegisterFCMID

func (db DatabaseConnection) RegisterFCMID(deviceID uuid.UUID, fcmID []byte) error

RegisterFCMID sets the FCM id (firebase_id) for a user's device, given a device id

func (DatabaseConnection) VerifyUser

func (db DatabaseConnection) VerifyUser(username string, password []byte) (User, error)

VerifyUser verifies a user against its authentication details. Returns the user if authed.

type DatabaseError

type DatabaseError struct {

	//DatabaseFault signals whether or not this is something that should be thought of as an error with the database itself, and not a problem with the query.
	DatabaseFault bool
	// contains filtered or unexported fields
}

DatabaseError represents an error that was produced during the running of a databse action Can either contain an error or a string. If both are present in the struct, the string will take precedence.

func (DatabaseError) Error

func (err DatabaseError) Error() string

Error returns the error message associated with a database error. If a string and error are present in the DatabaseError, the string is returned. Allows it to implement the error interface.

type Device

type Device struct {
	ID    uuid.UUID
	FCMID []byte
	User  User
}

Device represents a user within the database

type Session

type Session struct {
	ID   uuid.UUID
	User User
}

Session represents a session for a user

type User

type User struct {
	ID       int
	Username string
	// contains filtered or unexported fields
}

User represents a user within the database

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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