D
D
Dmitry Shnyrev2014-11-03 20:13:51
go
Dmitry Shnyrev, 2014-11-03 20:13:51

How do you handle database relationships in a Go application?

In my Web application on Go, I plan to use sqlx to work with the database, which allows me to put the data from the request directly into the structure. Here's how to make a request and the structure, everything seems to be clear.
But how "nice" to work with related data?
For example, I have tables Articles and Users. Articles refers to Users via UserId.
To show me a list of articles with authors. I select by means of JOIN. Here is the snag. I need to make a separate structure for this with all the fields that are contained in two tables (that is, in the general case, make your own structure for each request). Or you can make 2 structures (User and Article as they do with ORM) and somehow cleverly decompose the data into these two structures and somehow connect them.
What can you advise, or share a link to which example?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Shevelev, 2015-08-27
@dmnBrest

Try to abandon structures altogether where you do not need to explicitly add methods to them. Nothing prevents you from making as many variables of the desired types as you need ... and operating on them however you like.
Well, or try to add the necessary mechanism in sqlx, everything will be useful :)
PS I know that the topic is pretty old, there are simply no new ones :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question