postgres

package
v0.0.0-...-41dd682 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	*sqlx.DB
}

DB represents the database

func NewDB

func NewDB() (*DB, error)

func (*DB) Account

func (db *DB) Account(id int64) (*models.Account, error)

Account fetches an account by id

func (*DB) AccountExists

func (db *DB) AccountExists(email string) (bool, error)

AccountExists returns true if the provided email exists in the db

func (*DB) AccountWithCredentials

func (db *DB) AccountWithCredentials(email, allegedPassword string) (*models.Account, error)

AccountWithCredentials returns an account if the email and password provided match an (email,password) pair in the db

func (*DB) Accounts

func (db *DB) Accounts() (models.Accounts, error)

Accounts returns all accounts in the db

func (*DB) AddAccountRole

func (db *DB) AddAccountRole(roleID, accountID int64) (*models.AccountRole, error)

func (*DB) CleanSessionsOlderThan

func (db *DB) CleanSessionsOlderThan(age time.Duration) (int64, error)

CleanSessionsOlderThan deletes all sessions older than age(in seconds) and returns the number of rows affected

func (*DB) Confirm

func (db *DB) Confirm(id int64) (*models.Confirmation, error)

func (*DB) CreateAccount

func (db *DB) CreateAccount(first, last, email, password, confirmationCode string, dob time.Time, gender, phone *string) (*models.Account, *models.Confirmation, error)

CreateAccount creates a new account in the db and a confirmation code for the new registered email

func (*DB) CreateConfirmation

func (db *DB) CreateConfirmation(accountID int64, t models.ConfirmationType) (*models.Confirmation, error)

func (*DB) CreateRole

func (db *DB) CreateRole(name string) (*models.Role, error)

CreateRole creates a new role with the given name

func (*DB) CreateSession

func (db *DB) CreateSession(accountID int64) (*models.Session, error)

CreateSession creates a new session

func (*DB) DeleteSession

func (db *DB) DeleteSession(identifier string) error

DeleteSession deletes the session with the given identifier

func (*DB) FailedConfirmationIncrease

func (db *DB) FailedConfirmationIncrease(id int64) (*models.Confirmation, error)

func (*DB) PendingConfirmationByKey

func (db *DB) PendingConfirmationByKey(key string) (*models.Confirmation, error)

func (*DB) Role

func (db *DB) Role(roleID int64) (*models.Role, error)

func (*DB) RoleExists

func (db *DB) RoleExists(name string) (bool, error)

RoleExists returns true if already exists a role with the provided name in the db

func (*DB) Roles

func (db *DB) Roles() (models.Roles, error)

Roles fetches all roles in the database

func (*DB) RolesForAccount

func (db *DB) RolesForAccount(accountID int64) (models.Roles, error)

RolesForAccount fetches all roles for the given account

func (*DB) SessionFromIdentifier

func (db *DB) SessionFromIdentifier(identifier string) (*models.Session, error)

SessionFromIdentifier fetches a session from a given its identifier

func (*DB) UpdateSession

func (db *DB) UpdateSession(sessionToken string) (*models.Session, error)

UpdateSession updates a session in the db with the current timestamp

type DatabaseConfig

type DatabaseConfig struct {
	Name, User, Password, Host string
	Port                       int
}

Jump to

Keyboard shortcuts

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