Documentation ¶
Overview ¶
Package database deals with the initialization of our database connection.
Package database deals with the initialization of our database connection.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ///////////////////////// // PostgreSQL Credentials ///////////////////////// PostgresConnectionName = os.Getenv("POSTGRES_CONNECTION_NAME") PostgresDBUser = os.Getenv("POSTGRES_DB_USER") PostgresDBPassword = os.Getenv("POSTGRES_DB_PASSWORD") PostgresDBName = os.Getenv("POSTGRES_DB_NAME") )
PostgreSQL Credentials
These are the credentials necessary to initialize a connection with the database.
var ( // PostgresInsertPreregistrationQuery is the query used to insert into the // preregistrations table. PostgresInsertPreregistrationQuery = ` INSERT INTO preregistrations(email, timestamp) VALUES($1, $2) ` // PostgresSelectPreregistrationsQuery is the query used to select all preregistrations // from the preregistrations table. PostgresSelectPreregistrationsQuery = ` SELECT * FROM preregistrations ORDER BY timestamp ASC ` // PostgresDeletePreregistrationQuery is the query used to delete a preregistration // from the preregistrations table. PostgresDeletePreregistrationQuery = ` DELETE FROM preregistrations WHERE email = $1 ` PostgresCreatePreregistrationTableQuery = ` CREATE TABLE IF NOT EXISTS preregistrations ( email VARCHAR (256) PRIMARY KEY timestamp TIMESTAMP NOT NULL ) ` )
PostgreSQL Queries
These are the queries used to read and modify the database.
var ( // ErrDuplicate refers to an error generated when // a unique constraint is violated. ErrDuplicate = errors.New("database: duplicate entry") )
Database Errors
These are the errors that can be generated by our databases.
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB wraps the underlying database connection, allowing for methods to be executed through it.
The purpose of this abstraction is to allow for the use of different databases without forcing the user to undergo a major refactor.
For the time being, planned support is for the following databases: * PostgreSQL (Currently Supported / Used by MangoHacks 2019) * MongoDB * Google Firebase
func New ¶
New returns a new connection to the specified PostgreSQL database.
The credentials for the database are exepected to be exported and will be pulled down from the environment.
func (*DB) DeletePreregistration ¶
DeletePreregistration deletes the given preregistration from the appropriate database.
func (*DB) InsertPreregistration ¶
InsertPreregistration inserts a new preregistration into the appropriate database.
func (*DB) SelectPreregistrations ¶
func (db *DB) SelectPreregistrations() ([]models.Preregistration, error)
SelectPreregistrations selects all the preregistrations from the appropriate database.