database

package
v0.0.0-...-4b1f759 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrOrphanedUser is returned if caller attempts to create a user associated with an account_id that DNE.
	ErrOrphanedUser = errors.New("attempted to create an orphaned user")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Env string
}

Config is a database config object. Env determines whether the production or development database is created/used; if \"dev\", the app will seed the database with sample data for manual testing.

type Database

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

Database is a handle to the database layer

func New

func New(cfg Config) (*Database, error)

New creates a new *Database and initializes it's schema. Set filldb to true to fill the database with some fake data (for development purposes).

func (*Database) CountUsers

func (db *Database) CountUsers(accountID string) (int, error)

CountUsers counts how many users are associated with the accountID

func (*Database) CreateAPIkey

func (db *Database) CreateAPIkey(key auth.Key, accountID string) error

CreateAPIkey creates a new apikey entry TODO: could check that accouuntID exists in account table

func (*Database) CreateAccount

func (db *Database) CreateAccount(accountID, email, password string) error

CreateAccount creates a new account and saves it in the database

func (*Database) CreateMetric

func (db *Database) CreateMetric(accountID, userID string, timestamp time.Time) error

CreateMetric adds a new metric to the "metric" table in the database

func (*Database) CreateUser

func (db *Database) CreateUser(userID, accountID string) error

CreateUser creates a new user with userID associated with accountID. Determines whether the new User is active based on if the associated account has reached the user limit on its current plan.

func (*Database) GetAPIkey

func (db *Database) GetAPIkey(accountID string) (model.APIkey, error)

GetAPIkey gets an apikey from the database by accountID

func (*Database) GetAccount

func (db *Database) GetAccount(accountID string) (model.Account, error)

GetAccount retrieves an Account from the database by accountID

func (*Database) GetAccountByEmail

func (db *Database) GetAccountByEmail(email string) (model.Account, error)

GetAccountByEmail retrieves an Account from the database by email address

func (*Database) GetUser

func (db *Database) GetUser(userID string) (model.User, error)

GetUser retrieves a user from the database by user_id. Returns an error if user DNE.

func (*Database) UpgradeAccount

func (db *Database) UpgradeAccount(accountID string) (int, error)

UpgradeAccount upgrades an account from the FREE to the ENTERPRISE plan. It also updates any users in that account that were previously inactive to active. Returns the total number of users for the given accountID for ease of use by the UpgradeHandler. TODO: handle case when there wind up being more users than the ENTERPRISE plan allows

Jump to

Keyboard shortcuts

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