Documentation ¶
Index ¶
- Constants
- type DatabaseConnection
- func (connection *DatabaseConnection) Connect() error
- func (db DatabaseConnection) CreateSession(user User) (Session, error)
- func (db DatabaseConnection) CreateUser(username string, password []byte) error
- func (db DatabaseConnection) GetDevice(deviceID uuid.UUID) (Device, error)
- func (db DatabaseConnection) GetSession(sessionID uuid.UUID) (Session, error)
- func (db DatabaseConnection) GetUser(username string) (User, error)
- func (db DatabaseConnection) GetUserByID(id int) (User, error)
- func (db DatabaseConnection) GetUserCount() (int, error)
- func (db DatabaseConnection) MakeFileBlock(user User) (uuid.UUID, error)
- func (db DatabaseConnection) RecordFile(fileName string, blockID uuid.UUID) error
- func (db DatabaseConnection) RegisterDeviceToUser(user User) (Device, error)
- func (db DatabaseConnection) RegisterFCMID(deviceID uuid.UUID, fcmID []byte) error
- func (db DatabaseConnection) VerifyUser(username string, password []byte) (User, error)
- type DatabaseError
- type Device
- type Session
- type User
Constants ¶
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 ¶
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.