Skip to content

Database interface for users - #24

Merged
RyanConnell merged 3 commits into
RyanConnell:developfrom
VoyTechnology:database-interface
Mar 14, 2021
Merged

Database interface for users#24
RyanConnell merged 3 commits into
RyanConnell:developfrom
VoyTechnology:database-interface

Conversation

@VoyTechnology

Copy link
Copy Markdown
Collaborator

This change add an interface which can be implemented by various systems
to store the data. This means that we won't have to always rely on SQL.
It is up to implementation to return the correct information.

In the future this will allow to use other databases.
Comment on lines +8 to +13
func TestImplements(t *testing.T) {
var i interface{} = &UserDatabase{}

if _, ok := i.(database.UserDatabase); !ok {
t.Errorf("UserDatabase doesn't implement database.UserDatabase")
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

We can replace this whole thing with a compile-time check:

var_ database.UserDatabase= (*UserDatabase)(nil)

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

I've seen this in use, however in my opinion it directly contradicts

There is no explicit declaration of intent, no "implements" keyword.

Implicit interfaces decouple the definition of an interface from its implementation

The compile-time check adds this explicit declaration of intent. Placing it in tests allows to check can the type potentially be used as intended, rather than tying it to the interface. Furthermore, when a consumer is using the type, they will get that compile-time check anyways.

But this is just my opinion, if you prefer for me to change it, I'll be happy to oblige.

This change add an interface which can be implemented by various systems
to store the data. This means that we won't have to always rely on SQL.
It is up to implementation to return the correct information.
@VoyTechnologyVoyTechnology changed the title Database interfaceDatabase interface for usersMar 10, 2021
Comment threadinternal/database/sql/sql_test.go Outdated
Comment threadinternal/database/database.go
Ryan didn't want the shrug.
@RyanConnell
RyanConnell merged commit ec1140f into RyanConnell:developMar 14, 2021
@VoyTechnology
VoyTechnology deleted the database-interface branch March 14, 2021 22:26
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@VoyTechnology@RyanConnell