postgres

package
v0.0.0-...-d7118e0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExpiredResource    error
	ErrInvalidCredentials = errors.New("invalid credentials")
)

Functions

This section is empty.

Types

type Config

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

type DB

type DB struct {
	*sqlx.DB
}

DB represents the database

func New

func New(config Config) (*DB, error)

func (*DB) Account

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

Account fetches an account by id

func (*DB) AccountWithCredentials

func (db *DB) AccountWithCredentials(email, allegedPassword string) (*hmm.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() (hmm.Accounts, error)

Accounts returns all accounts in the db

func (*DB) AddRoleToAccount

func (db *DB) AddRoleToAccount(roleID, accountID int64) (*hmm.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) (*hmm.Confirmation, error)

func (*DB) CreateAccount

func (db *DB) CreateAccount(ctx context.Context, a *hmm.Account, password, confirmationCode string) (*hmm.Account, *hmm.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 hmm.ConfirmationType) (*hmm.Confirmation, error)

func (*DB) CreateRole

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

CreateRole creates a new role with the given name

func (*DB) CreateSession

func (db *DB) CreateSession(ctx context.Context, email, password string) (*hmm.Session, error)

CreateSession creates a new session

func (*DB) ExpireSession

func (db *DB) ExpireSession(token string) (*hmm.Session, error)

ExpireSession expires the session with the given token

func (*DB) FailedConfirmationIncrease

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

func (*DB) PendingConfirmationByKey

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

func (*DB) PopulateAccount

func (db *DB) PopulateAccount(a *hmm.Account) *hmm.Account

func (*DB) PopulateAccounts

func (db *DB) PopulateAccounts(accs hmm.Accounts) hmm.Accounts

func (*DB) Role

func (db *DB) Role(id int64) (*hmm.Role, error)

func (*DB) Roles

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

Roles fetches all roles in the database

func (*DB) RolesForAccount

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

RolesForAccount fetches all roles for the given account

func (*DB) SessionFromToken

func (db *DB) SessionFromToken(token string) (*hmm.Session, error)

SessionFromToken fetches a session by its token

func (*DB) UpdateRole

func (db *DB) UpdateRole(roleID int64, permissionBit int) (*hmm.Role, error)

func (*DB) UpdateSession

func (db *DB) UpdateSession(token string) (*hmm.Session, error)

UpdateSession updates a session in the db with the current timestamp

Jump to

Keyboard shortcuts

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