Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a package to abstract SQL operations #18

Merged
merged 9 commits into from
Jul 30, 2016
Merged

Add a package to abstract SQL operations #18

merged 9 commits into from
Jul 30, 2016

Conversation

Merovius
Copy link
Contributor

The data package should improve code-reuse by bundling together the SQL
operations into a common package. It will be marginally less efficient
than using SQL directly, but it will enforce best practices, remove
duplication and prevent mistakes from broken queries. #7 is the
associated issue.

To begin with, this updates termine to use the new package. It also
refactors termine a bit.

Fixes #3

The data package should improve code-reuse by bundling together the SQL
operations into a common package. It will be marginally less efficient
than using SQL directly, but it will enforce best practices, remove
duplication and prevent mistakes from broken queries. #7 is the
associated issue.

To begin with, this updates termine to use the new package. It also
refactors termine a bit.

Fixes #3

var (
driver = flag.String("driver", "postgres", "Der benutzte sql-Treiber")
connect = flag.String("connect", "dbname=nnev user=anon host=/var/run/postgresql sslmode=disable", "Die Verbindusgsspezifikation")
Copy link
Member

@cherti cherti Jul 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be consistent with the row length. Either be as long as it needs to be or not using 80 chars as a line-break-reference (compare L.25). I'd go for "as long as it is needed as long as it is reasonable".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My comments are at 80 characters because that's what gq does. As such, this provides the point of minimum care, use gq for commends (as gofmt doesn't split them and they become unreasonably long) and gofmt for everything else. Doing a manual "is this too long or not" evaluation just seems tedious to me. Also, having basically any rules for line lengths means that at some point arguments will start about what "unreasonably long" really means :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, automated comment-formatting is reasonable. just seemed strange having this one long line, but comments splittet after 75 chars.

t *Termin
}

// Next returns whether there is another element.
Copy link
Member

@cherti cherti Jul 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"... and changes pointer to the next element." something like that. I's an iterator after all, without Next, you don't get the next element.


// Err returns the last error that occured when reading. It must be called
// after being done with the iterator.
func (it *TerminIterator) Err() error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to call that Err() or rather something like Close()?

// One is a convenience method for queries that expect exactly one result. It
// returns an error if there is not exactly one result. Must be the only method
// being called.
func (it *TerminIterator) One() (*Termin, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why having One() at all if we have First()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They serve different purposes (so far, One doesn't serve any, though). One is useful for "I am searching for a specific meeting", whereas First is useful for e.g. "I want the next meeting". In the former case, using First would potentially hide bugs in the query or unexpected data.

I'm not married to it, though. If you want, I can remove it until the need is demonstrated.

Copy link
Member

@cherti cherti Jul 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. No harm in keeping it then.

Scan(dest ...interface{}) error
}

// row is an abstraction over the data elements to share code.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docu-comment must be updated as well

@cherti cherti merged commit dc41ca3 into master Jul 30, 2016
@cherti cherti deleted the crud branch July 30, 2016 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants