mysql

package
v0.0.0-...-70dac13 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const ErrMissingEnvs = Error("missing required environment variables")
View Source
const ErrNoUser = database.Error("No User found with that name")

Variables

This section is empty.

Functions

func ConfigFromEnv

func ConfigFromEnv(dir ...string) (*gsdmysql.Config, error)

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 Error

type Error string

func (Error) Error

func (e Error) Error() string

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

func New(config *gsdmysql.Config) (*MySQLDB, error)

New connects to the configured mysql server and returns a new MySQLDB that can perform queries for things and users.

func (*MySQLDB) Close

func (m *MySQLDB) Close() error

Close closes the database connection. Not strictly necessary to call this.

func (*MySQLDB) CreateThing

func (m *MySQLDB) CreateThing(args database.CreateThingParams) (*database.Thing, error)

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

func (m *MySQLDB) CreateUser(name, email string) (*database.User, error)

CreateUser creates a new user with the given name and email. The returned user will have its ID set.

func (*MySQLDB) DeleteThing

func (m *MySQLDB) DeleteThing(id uint32) error

DeleteThing deletes the thing with the given ID.

func (*MySQLDB) DeleteUser

func (m *MySQLDB) DeleteUser(id uint32) error

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

func (m *MySQLDB) GetUserByName(name string) (*database.User, error)

GetUserByName returns the user with the given name.

func (*MySQLDB) Reset

func (m *MySQLDB) Reset() error

Reset drops all tables and recreates them. Use with extreme caution!

Jump to

Keyboard shortcuts

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