Documentation
¶
Index ¶
- Variables
- type Config
- type Database
- func (db *Database) CountUsers(accountID string) (int, error)
- func (db *Database) CreateAPIkey(key auth.Key, accountID string) error
- func (db *Database) CreateAccount(accountID, email, password string) error
- func (db *Database) CreateMetric(accountID, userID string, timestamp time.Time) error
- func (db *Database) CreateUser(userID, accountID string) error
- func (db *Database) GetAPIkey(accountID string) (model.APIkey, error)
- func (db *Database) GetAccount(accountID string) (model.Account, error)
- func (db *Database) GetAccountByEmail(email string) (model.Account, error)
- func (db *Database) GetUser(userID string) (model.User, error)
- func (db *Database) UpgradeAccount(accountID string) (int, error)
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
CountUsers counts how many users are associated with the accountID
func (*Database) CreateAPIkey ¶
CreateAPIkey creates a new apikey entry TODO: could check that accouuntID exists in account table
func (*Database) CreateAccount ¶
CreateAccount creates a new account and saves it in the database
func (*Database) CreateMetric ¶
CreateMetric adds a new metric to the "metric" table in the database
func (*Database) CreateUser ¶
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) GetAccount ¶
GetAccount retrieves an Account from the database by accountID
func (*Database) GetAccountByEmail ¶
GetAccountByEmail retrieves an Account from the database by email address
func (*Database) GetUser ¶
GetUser retrieves a user from the database by user_id. Returns an error if user DNE.
func (*Database) UpgradeAccount ¶
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