database

package
v0.0.0-...-cd49cae Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2018 License: MIT Imports: 10 Imported by: 2

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

View Source
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.

View Source
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.

View Source
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

func New(database string) (*DB, error)

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

func (db *DB) DeletePreregistration(email string) error

DeletePreregistration deletes the given preregistration from the appropriate database.

func (*DB) InsertPreregistration

func (db *DB) InsertPreregistration(email string) error

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.

Jump to

Keyboard shortcuts

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