db

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2014 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MinPasswordLength is the shortest a password can be.
	MinPasswordLength = 6

	// MaxPasswordLength is the longest a password can be.
	MaxPasswordLength = 50
)
View Source
const SessionIdleTime = "2 HOURS"

SessionIdleTime is the amount of idle time that delimits sessions.

View Source
const UserPrefix = "@"

Variables

View Source
var (
	// ErrFunnelNotFound is returned when a funnel does not exist.
	ErrFunnelNotFound = &Error{"funnel not found", nil}

	// ErrFunnelNameRequired is returned when a funnel has a blank name.
	ErrFunnelNameRequired = &Error{"funnel name required", nil}

	// ErrFunnelStepsRequired is returned when a funnel has no steps.
	ErrFunnelStepsRequired = &Error{"funnel steps required", nil}
)
View Source
var (
	// ErrUserNotFound is returned when a user does not exist.
	ErrUserNotFound = &Error{"user not found", nil}

	// ErrUserEmailRequired is returned when a user has a blank email.
	ErrUserEmailRequired = &Error{"user email required", nil}

	// ErrUserEmailTaken is returned when a email already exists.
	ErrUserEmailTaken = &Error{"user email already in use", nil}

	// ErrUserPasswordRequired is returned when a user has a blank password.
	ErrUserPasswordRequired = &Error{"user password required", nil}

	// ErrUserPasswordTooShort is returned when a password is too short.
	ErrUserPasswordTooShort = &Error{"user password too short", nil}

	// ErrUserPasswordTooLong is returned when a password is too long.
	ErrUserPasswordTooLong = &Error{"user password too long", nil}

	// ErrUserNotAuthenticated is returned when a password doesn't match the hash.
	ErrUserNotAuthenticated = &Error{"user not authenticated", nil}
)
View Source
var (
	// ErrAccountNotFound is returned when an account with the given id does
	// not exist.
	ErrAccountNotFound = &Error{"account not found", nil}
)

Functions

This section is empty.

Types

type Account

type Account struct {
	Tx *Tx

	APIKey string `json:"apiKey"`
	// contains filtered or unexported fields
}

Account represents a collection of Users and Events.

func (*Account) CreateFunnel

func (a *Account) CreateFunnel(f *Funnel) error

CreateFunnel creates a new Funnel for this account.

func (*Account) CreateUser

func (a *Account) CreateUser(u *User) error

CreateUser creates a new User for this account.

func (*Account) Delete

func (a *Account) Delete() error

Delete removes the account from the database.

func (*Account) Events

func (a *Account) Events(id string) ([]*Event, error)

Events returns a list of events for a given ID.

func (*Account) Funnel

func (a *Account) Funnel(id int) (*Funnel, error)

Funnel retrieves a funnel with a given ID. Only funnels associated with this account will be returned.

func (*Account) Funnels

func (a *Account) Funnels() (Funnels, error)

Funnels retrieves a list of all funnels for the account.

func (*Account) GenerateAPIKey

func (a *Account) GenerateAPIKey() error

GenerateAPIKey creates a new API key for an account.

func (*Account) ID

func (a *Account) ID() int

ID returns the account identifier.

func (*Account) Load

func (a *Account) Load() error

Load retrieves an account from the database.

func (*Account) Migrate

func (a *Account) Migrate() error

Migrate creates a Sky table and updates the schema, if necessary.

func (*Account) Reset

func (a *Account) Reset() error

Reset drops the sky table and recreates it.

func (*Account) Resources

func (a *Account) Resources() ([]string, error)

Resources returns a list unique resources on the account.

func (*Account) Save

func (a *Account) Save() error

Save commits the Account to the database.

func (*Account) SkyTable

func (a *Account) SkyTable() *sky.Table

SkyTable returns a reference to the table used by Sky.

func (*Account) SkyTableName

func (a *Account) SkyTableName() string

SkyTableName returns the name of the table used by Sky.

func (*Account) Track

func (a *Account) Track(e *Event) error

Track sends a single event to Sky.

func (*Account) Users

func (a *Account) Users() (Users, error)

Users retrieves a list of all users for the account.

func (*Account) Validate

func (a *Account) Validate() error

Validate validates all fields of the account.

type Accounts

type Accounts []*Account

func (Accounts) Len

func (s Accounts) Len() int

func (Accounts) Less

func (s Accounts) Less(i, j int) bool

func (Accounts) Swap

func (s Accounts) Swap(i, j int)

type DB

type DB struct {
	bolt.DB
	SkyClient sky.Client
}

DB represents a Bolt-backed data store. The DB stores all non-event data.

func (*DB) Do

func (db *DB) Do(fn func(*Tx) error) error

Do executes a function within the context of a writable transaction.

func (*DB) Open

func (db *DB) Open(path string, mode os.FileMode) error

Open initializes and opens the database.

func (*DB) Secret

func (db *DB) Secret() ([]byte, error)

Secret retrieves the secret key used for cookie storage.

func (*DB) With

func (db *DB) With(fn func(*Tx) error) error

With executes a function within the context of a read-only transaction.

type Error

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

Error represents an error condition within the database.

func (*Error) Error

func (e *Error) Error() string

Error returns a string representation of the error.

type Event

type Event struct {
	Timestamp time.Time              `json:"timestamp"`
	UserID    string                 `json:"userID"`
	DeviceID  string                 `json:"deviceID"`
	Channel   string                 `json:"channel"`
	Resource  string                 `json:"resource"`
	Action    string                 `json:"action"`
	Data      map[string]interface{} `json:"data"`
}

Event represents an action or state change trigger by a tracked user.

func (*Event) Deserialize

func (e *Event) Deserialize(id string, event *sky.Event)

Deserialize converts a Sky event into a Skybox event.

func (*Event) ID

func (e *Event) ID() string

ID returns the identifier used to store the event in Sky.

func (*Event) IsAnonymous

func (e *Event) IsAnonymous() bool

IsAnonymous returns whether the event is for an unidentified user.

func (*Event) Serialize

func (e *Event) Serialize() *sky.Event

Serialize converts the Skybox event into a Sky event.

type Funnel

type Funnel struct {
	Tx *Tx

	AccountID int           `json:"accountID"`
	Name      string        `json:"name"`
	Steps     []*FunnelStep `json:"steps"`
	// contains filtered or unexported fields
}

Funnel represents a multi-step query. A Funnel belongs to an Account.

func (*Funnel) Delete

func (f *Funnel) Delete() error

Delete removes the Funnel from the database.

func (*Funnel) ID

func (f *Funnel) ID() int

ID returns the funnel identifier.

func (*Funnel) Load

func (f *Funnel) Load() error

Load retrieves a funnel from the database.

func (*Funnel) Query

func (f *Funnel) Query() (*FunnelResult, error)

Query executes a query against the funnel and returns the result.

func (*Funnel) QueryString

func (f *Funnel) QueryString() string

QueryString generates a funnel query for use in Sky.

func (*Funnel) Save

func (f *Funnel) Save() error

Save commits the Funnel to the database.

func (*Funnel) Validate

func (f *Funnel) Validate() error

Validate validates all fields of the funnel.

type FunnelResult

type FunnelResult struct {
	Name  string              `json:"name"`
	Steps []*FunnelStepResult `json:"steps"`
}

FunnelResult represents the results of an executed funnel query.

type FunnelStep

type FunnelStep struct {
	Condition string `json:"condition"`
}

FunnelStep represents a single step in a funnel.

type FunnelStepResult

type FunnelStepResult struct {
	Condition string `json:"condition"`
	Count     int    `json:"count"`
}

FunnelStepResult represents the result of one step in an executed funnel query.

type Funnels

type Funnels []*Funnel

func (Funnels) Len

func (s Funnels) Len() int

func (Funnels) Less

func (s Funnels) Less(i, j int) bool

func (Funnels) Swap

func (s Funnels) Swap(i, j int)

type Tx

type Tx struct {
	*bolt.Tx
	// contains filtered or unexported fields
}

func (*Tx) Account

func (t *Tx) Account(id int) (*Account, error)

Account retrieves an Account from the database with the given identifier.

func (*Tx) AccountByAPIKey

func (t *Tx) AccountByAPIKey(apiKey string) (*Account, error)

AccountByAPIKey retrieves an acocunt from the database with the given API key.

func (*Tx) Accounts

func (t *Tx) Accounts() (Accounts, error)

Accounts retrieves all Account objects from the database.

func (*Tx) CreateAccount

func (t *Tx) CreateAccount(a *Account) error

CreateAccount creates a new Account in the database.

func (*Tx) Funnel

func (t *Tx) Funnel(id int) (*Funnel, error)

Funnel retrieves a Funnel from the database with the given identifier.

func (*Tx) User

func (t *Tx) User(id int) (*User, error)

User retrieves a User from the database with the given identifier.

func (*Tx) UserByEmail

func (t *Tx) UserByEmail(email string) (*User, error)

UserByEmail retrieves a User from the database with the given Email.

type User

type User struct {
	Tx *Tx

	AccountID int    `json:"accountID"`
	Email     string `json:"email"`
	Password  string `json:"-"`
	Hash      []byte `json:"hash"`
	// contains filtered or unexported fields
}

User represents a user within the system. A User belongs to an Account.

func (*User) Account

func (u *User) Account() (*Account, error)

Account returns a reference to the user's account.

func (*User) Authenticate

func (u *User) Authenticate(password string) error

Authenticate checks if a plaintext password matches the hash.

func (*User) Delete

func (u *User) Delete() error

Delete removes the User from the database.

func (*User) GenerateHash

func (u *User) GenerateHash() error

GenerateHash generates a hashed password from the currently set password.

func (*User) ID

func (u *User) ID() int

ID returns the user identifier.

func (*User) Load

func (u *User) Load() error

Load retrieves a user from the database.

func (*User) Save

func (u *User) Save() error

Save commits the User to the database.

func (*User) Validate

func (u *User) Validate() error

Validate validates all fields of the user.

type Users

type Users []*User

func (Users) Len

func (s Users) Len() int

func (Users) Less

func (s Users) Less(i, j int) bool

func (Users) Swap

func (s Users) Swap(i, j int)

Jump to

Keyboard shortcuts

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