Skip to content
This repository was archived by the owner on Jul 22, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: go
install: go get -t ./...
install: make deps
go:
- 1.9
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,12 @@ check-license:
@echo "Checking for license in source files..."
@grep -L LICENSE ${GOFILES}
@exit `grep -L LICENSE ${GOFILES} | wc -l`

.PHONY: deps
deps:
go get launchpad.net/godeps
godeps -u dependencies.tsv

.PHONY: create-deps
create-deps:
godeps -t ./... > dependencies.tsv
39 changes: 3 additions & 36 deletions db/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ import (
// options.
func New(options *Options) (*DB, error) {
db := &DB{
options: options,
Options: options,
}
connStr, err := db.options.ConnectionString()
connStr, err := db.Options.ConnectionString()
if err != nil {
return nil, errgo.Mask(err)
}
conn, err := sql.Open("postgres", connStr)
if err != nil {
return nil, err
}
db.conn = conn
db.Conn = conn
return db, nil
}

Expand Down Expand Up @@ -105,36 +105,3 @@ func (o *Options) ConnectionString() (string, error) {
}
return strings.Join(opts, " "), nil
}

// DataReader describes an object which can read data from the database.
type DataReader interface {
// Args: slug
// Returns: model, error
Source(string, *Source) error
Survey(string, *Survey) error
// Args: survey slug, id
// Returns: model, error
Response(string, *Response) error
Respondent(string, *Respondent) error
// Args: query, order, group, limit, an interface to hold the expected data.
// Returns: error
Select(string, string, string, int, *interface{}) error
}

// DataWriter describes an object which can write data to the database.
type DataWriter interface {
WriteSource(Source) error
WriteSurvey(Survey) error
WriteSummary(Summary) error
WriteResponse(Response) error
WriteRespondent(Respondent) error
Insert(string) error
Update(string) error
Delete(string) error
}

// DB holds connection information and allows querying of the database
type DB struct {
conn *sql.DB
options *Options
}
84 changes: 84 additions & 0 deletions db/db.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright 2017 [adjective][species], Ltd
// Licensed under the MIT license, see the LICENSE file for details.

package db

import "database/sql"

// DB holds connection information and allows querying of the database
type DB struct {
Conn *sql.DB
Options *Options
}

func (db *DB) Source(slug string, source *Source, opts ReadOpts) error {
return nil
}

func (db *DB) Survey(slug string, source *Source, opts ReadOpts) error {
return nil
}

func (db *DB) Summary(slug string, summary *Summary, opts ReadOpts) error {
return nil
}

func (db *DB) Response(id string, response *Response, opts ReadOpts) error {
return nil
}

func (db *DB) Respondent(id string, respondent *Respondent, opts ReadOpts) error {
return nil
}

func (db *DB) Select(query string, args []interface{}, opts ReadOpts, result []interface{}) error {
return nil
}

func (db *DB) WriteSource(source *Source, opts WriteOpts) error {
return nil
}

func (db *DB) LoadSource(source *Source, opts WriteOpts) error {
return nil
}

func (db *DB) WriteSurvey(survey *Survey, opts WriteOpts) error {
return nil
}

func (db *DB) LoadSurvey(survey *Survey, opts WriteOpts) error {
return nil
}

func (db *DB) WriteSummary(summary *Summary, opts WriteOpts) error {
return nil
}

func (db *DB) WriteResponse(response *Response, opts WriteOpts) error {
return nil
}

func (db *DB) LoadResponses(responses []Response, opts WriteOpts) error {
return nil
}

func (db *DB) WriteRespondent(respondent *Respondent, opts WriteOpts) error {
return nil
}

func (db *DB) LoadRespondents(respondents []Respondent, opts WriteOpts) error {
return nil
}

func (db *DB) Insert(query string, arg []interface{}, opts WriteOpts) error {
return nil
}

func (db *DB) Update(query string, arg []interface{}, opts WriteOpts) error {
return nil
}

func (db *DB) Delete(query string, arg []interface{}, opts WriteOpts) error {
return nil
}
86 changes: 86 additions & 0 deletions db/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright 2017 [adjective][species], Ltd
// Licensed under the MIT license, see the LICENSE file for details.

package db

type ReadOpts struct {
LoadDepth int
OrderBy map[string]bool
GroupBy string
Limit int
}

// DataReader describes an object which can read data from the database.
type DataReader interface {

// Source attempts to find a data source with the given slug, taking into
// account the given options.
Source(string, *Source, ReadOpts) error

// Survey attempts to find a dataset with the given slug, taking into
// account the given options.
Survey(string, *Survey, ReadOpts) error

// Summary attempts to find a summary with the given slug, taking into
// account the given options.
Summary(string, *Summary, ReadOpts) error

// Response attempts to load a survey response with the given id, taking
// into account the given options.
Response(string, *Response, ReadOpts) error

// Respondent attempts to load a respondent with the given id, taking into
// account the given options.
Respondent(string, *Respondent, ReadOpts) error

// Select attempts to run a a query agaist the database.
// Args: query, query arguments, options, an interface to hold the expected
// data.
// Returns: error
Select(string, []interface{}, ReadOpts, []interface{}) error
}

type WriteOpts struct {
Upsert bool
Cascade bool
}

// DataWriter describes an object which can write data to the database.
type DataWriter interface {

// WriteSource writes a source to the database.
WriteSource(*Source, WriteOpts) error

// LoadSource attempts to load a source into the database, including as
// many of its component parts (surveys, respondents, etc) that are
// provided.
LoadSource(*Source, WriteOpts) error

// WriteSurvey writes a survey to the database.
WriteSurvey(*Survey, WriteOpts) error

// LoadSurvey attempts to load a survey into the database, including as many
// of its component parts (responses, etc) that are provided.
LoadSurvey(*Survey, WriteOpts) error

// WriteSummary writes a summary to the database.
WriteSummary(*Summary, WriteOpts) error

// WriteResponse writes a response to the database.
WriteResponse(*Response, WriteOpts) error

// LoadResponses loads a set of responses to the database.
LoadResponses([]Response, WriteOpts) error

// WriteRespondent writes a respondent to the database.
WriteRespondent(*Respondent, WriteOpts) error

// LoadRespondents loads a set of respondents to the database.
LoadRespondents([]Respondent, WriteOpts) error

// The following attempt to run statements against the database, using the
// given string as the statement and the array of strings as the arguments.
Insert(string, []interface{}, WriteOpts) error
Update(string, []interface{}, WriteOpts) error
Delete(string, []interface{}, WriteOpts) error
}
10 changes: 10 additions & 0 deletions dependencies.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
github.com/gorilla/mux git 7625a85c14e615274a4ee4bc8654f72310a563e4 2017-10-20T03:47:00Z
github.com/jtolds/gls git 77f18212c9c7edc9bd6a33d383a7b545ce62f064 2017-05-03T22:48:51Z
github.com/lib/pq git b609790bd85edf8e9ab7e0f8912750a786177bcf 2017-10-22T19:20:43Z
github.com/smartystreets/assertions git 0b37b35ec7434b77e77a4bb29b79677cced992ea 2017-09-25T17:21:51Z
github.com/smartystreets/goconvey git e5b2b7c9111590d019a696c7800593f666e1a7f4 2017-08-25T22:14:26Z
go.uber.org/atomic git 54f72d32435d760d5604f17a82e2435b28dc4ba5 2017-08-29T22:32:23Z
go.uber.org/multierr git fb7d312c2c04c34f0ad621048bbb953b168f9ff6 2017-08-29T22:43:07Z
go.uber.org/zap git 54bf686453bd64588ccdc1c8a8e1f175f6d40f03 2017-10-30T18:49:38Z
gopkg.in/errgo.v1 git 442357a80af5c6bf9b6d51ae791a39c3421004f3 2016-12-22T12:58:16Z
gopkg.in/yaml.v2 git eb3733d160e74a9c7e442f435eb3bea458e1d19f 2017-08-12T16:00:11Z