From 3583557c9ed024dd697d4086c5d5bfed584b6485 Mon Sep 17 00:00:00 2001 From: Madison Scott-Clary Date: Wed, 1 Nov 2017 12:30:57 -0600 Subject: [PATCH 1/3] Stub DB, godeps --- Makefile | 8 +++++ db/connection.go | 39 ++-------------------- db/db.go | 84 ++++++++++++++++++++++++++++++++++++++++++++++ db/interface.go | 86 ++++++++++++++++++++++++++++++++++++++++++++++++ dependencies.tsv | 10 ++++++ 5 files changed, 191 insertions(+), 36 deletions(-) create mode 100644 db/db.go create mode 100644 db/interface.go create mode 100644 dependencies.tsv diff --git a/Makefile b/Makefile index 00beaed..4db1106 100644 --- a/Makefile +++ b/Makefile @@ -12,3 +12,11 @@ check-license: @echo "Checking for license in source files..." @grep -L LICENSE ${GOFILES} @exit `grep -L LICENSE ${GOFILES} | wc -l` + +.PHONY: deps +deps: + godeps -u dependencies.tsv + +.PHONY: create-deps +create-deps: + godeps -t ./... > dependencies.tsv diff --git a/db/connection.go b/db/connection.go index 9de8939..5fba670 100644 --- a/db/connection.go +++ b/db/connection.go @@ -17,9 +17,9 @@ 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) } @@ -27,7 +27,7 @@ func New(options *Options) (*DB, error) { if err != nil { return nil, err } - db.conn = conn + db.Conn = conn return db, nil } @@ -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 -} diff --git a/db/db.go b/db/db.go new file mode 100644 index 0000000..75b60d3 --- /dev/null +++ b/db/db.go @@ -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 +} diff --git a/db/interface.go b/db/interface.go new file mode 100644 index 0000000..e8dd175 --- /dev/null +++ b/db/interface.go @@ -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 +} diff --git a/dependencies.tsv b/dependencies.tsv new file mode 100644 index 0000000..9d581e4 --- /dev/null +++ b/dependencies.tsv @@ -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 From fba7b49d79cdf505421b01f447ef9e8cec5de6d6 Mon Sep 17 00:00:00 2001 From: Madison Scott-Clary Date: Wed, 1 Nov 2017 12:35:13 -0600 Subject: [PATCH 2/3] Update travis for godeps --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 349b616..f074b02 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ language: go -install: go get -t ./... +install: make deps go: - 1.9 From 7460647ae80cc679e5110861a505c3426aea9176 Mon Sep 17 00:00:00 2001 From: Madison Scott-Clary Date: Wed, 1 Nov 2017 12:39:38 -0600 Subject: [PATCH 3/3] Install godeps --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 4db1106..1177df8 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ check-license: .PHONY: deps deps: + go get launchpad.net/godeps godeps -u dependencies.tsv .PHONY: create-deps