Documentation
¶
Index ¶
- Constants
- func ConfigFromEnv(dir ...string) (*gsdmysql.Config, error)
- type Error
- type MySQLDB
- func (m *MySQLDB) Close() error
- func (m *MySQLDB) CreateThing(args database.CreateThingParams) (*database.Thing, error)
- func (m *MySQLDB) CreateUser(name, email string) (*database.User, error)
- func (m *MySQLDB) DeleteThing(id uint32) error
- func (m *MySQLDB) DeleteUser(id uint32) error
- func (m *MySQLDB) GetThings(params database.GetThingsParams) (*database.GetThingsResult, error)
- func (m *MySQLDB) GetUserByName(name string) (*database.User, error)
- func (m *MySQLDB) Reset() error
Constants ¶
const ErrMissingEnvs = Error("missing required environment variables")
const ErrNoUser = database.Error("No User found with that name")
Variables ¶
This section is empty.
Functions ¶
func ConfigFromEnv ¶
ConfigFromEnv returns a new MySQL config suitable for passing to New(), populated from environment variables TT_SQL_USER, TT_SQL_PASS, TT_SQL_HOST, TT_SQL_PORT, and TT_SQL_DB.
If these environment variables are defined in a file called .env.development.local (and not previously defined elsewhere), they will be loaded only if TT_ENV is set to "development".
If these environment variables are defined in a file called .env.test.local (and not previously defined elsewhere), they will be loaded only if TT_ENV is set to "test".
If these environment variables are defined in a file called .env.production.local (and not previously defined elsewhere), they will be loaded only if TT_ENV is set to "production".
If these environment variables are defined in a .env file (and not previously defined elsewhere), they will be automatically loaded.
Optionally supply a directory to look for the .env* files in.
Types ¶
type MySQLDB ¶
type MySQLDB struct {
// contains filtered or unexported fields
}
MySQLDB implements the database interface by storing and retrieving info about things and users from a MySQL database.
func New ¶
New connects to the configured mysql server and returns a new MySQLDB that can perform queries for things and users.
func (*MySQLDB) CreateThing ¶
CreateThing creates a new thing with the given details. The returned thing will have its ID set to an auto-increment value, and Created time set to now. The supplied Creator must match the Name of an existing User, and will be recored as a Subscriber of the new Thing.
func (*MySQLDB) CreateUser ¶
CreateUser creates a new user with the given name and email. The returned user will have its ID set.
func (*MySQLDB) DeleteThing ¶
DeleteThing deletes the thing with the given ID.
func (*MySQLDB) DeleteUser ¶
DeleteUser deletes the user with the given ID. This will also delete any subscriptions the user had (but not any Things the user created).
func (*MySQLDB) GetThings ¶
func (m *MySQLDB) GetThings(params database.GetThingsParams) (*database.GetThingsResult, error)
GetThings returns things that match the given parameters. Also in the result is the last page that would return things if Page and ThingsPerPage are > 0.
func (*MySQLDB) GetUserByName ¶
GetUserByName returns the user with the given name.