storage

package module
Version: v0.0.0-...-79ec261 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2013 License: MIT Imports: 5 Imported by: 1

README

MsgBox Storage

Provides an API for permanent storage of incoming messages. This currently uses a Postgres database but should eventually provide an agreeded upon API that can be used with other data storage soultions.

Requirements

A postgres database and the following environment variable:

  • DATABASE_NAME
  • DATABASE_USER
  • DATABASE_PASS
  • DATABASE_HOST
  • DATABASE_PORT
  • DATABASE_SSL (probally 'disable')

Schema

This is the minimum postgres schema currently for using this. You will need the 'uuid-ossp' extension installed.

CREATE TABLE accounts(
    id              uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
    username        varchar(40) NOT NULL,
    email           text NOT NULL,
    password        text NOT NULL,
    name            text,
    avatar_url      text,
    created_at      timestamp NOT NULL,
    modified_at     timestamp,
    CONSTRAINT "User already exists" UNIQUE(username),
    CONSTRAINT "Email already in user" UNIQUE(email)
    );


CREATE TABLE boxes(
    id              uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
    account_id      uuid NOT NULL REFERENCES accounts (id),
    name            varchar(40) NOT NULL,
    created_at      timestamp NOT NULL,
    modified_at     timestamp
    );


CREATE TABLE messages(
    id              uuid PRIMARY KEY,
    user_id         uuid NOT NULL REFERENCES accounts (id),
    box_id          uuid NOT NULL REFERENCES boxes (id),
    creator         text NOT NULL,
    created_at      bigint NOT NULL,
    status          bool DEFAULT false,
    payload         text
    );

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB_HOST = os.Getenv("DATABASE_HOST")
View Source
var DB_NAME = os.Getenv("DATABASE_NAME")
View Source
var DB_PASS = os.Getenv("DATABASE_PASS")
View Source
var DB_PORT = os.Getenv("DATABASE_PORT")
View Source
var DB_SSL = os.Getenv("DATABASE_SSL")
View Source
var DB_USER = os.Getenv("DATABASE_USER")

Functions

func Connect

func Connect() *sql.DB

func InsertMessage

func InsertMessage(user string, box string, msg *messages.Message) error

Types

type Account

type Account struct {
	Id       string
	Username string
}

func FindAccount

func FindAccount(username string) *Account

type Box

type Box struct {
	Id   string
	Name string
}

func FindBox

func FindBox(user string, name string) *Box

Jump to

Keyboard shortcuts

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