JackyChiu / realworld-starter-kit

Go examples API for a blog
https://realworld.io
21 stars 2 forks source link

SQL Connection & Go ORM #12

Open JackyChiu opened 7 years ago

JackyChiu commented 7 years ago

I'm quite new to using SQL with Go, so if anyone has any opinion or design proposals post them here!

As of now:

adelowo commented 7 years ago

This could change to

func RegisterUser(db *SqlxBlah) error {
    return func (w http.ResponseWriter, h *http.Request) {
     //old code
   }
}
JackyChiu commented 7 years ago

@adelowo yeah I definitely agree that DI was the way to go, I'll look into this approach!

For the example you posted, would you need to change it to this?

func RegisterUser(db *SqlxBlah, w http.ResponseWriter, h *http.Request) error {
    return func (w http.ResponseWriter, h *http.Request) {
     //old code
   }
}

How do you feel about the ORM? I started off with that just to get something up

adelowo commented 7 years ago
adelowo commented 7 years ago

I should be able to help out on a couple things though

JackyChiu commented 7 years ago

@adelowo sorry I just wasn't too sure what you were saying but I think I see it now for the http.handler!

Yeah if you could show an example without the ORM I'd really appreciate it! And feel free to contribute to any part 😄

adelowo commented 7 years ago

Can i pull a fork of this showing that ? or how do you want me to "show the example" ?

JackyChiu commented 7 years ago

Can i pull a fork of this showing that ? or how do you want me to "show the example" ?

Yeah a fork, a gist, or whatever works 😁

adelowo commented 7 years ago

A fork it shall be... Should get that done in a couple hours

adelowo commented 7 years ago

Ok, i found out i already have something like this..

You might want to look into it

Database => https://github.com/adelowo/reblog/tree/master/models (plus mocks) Handlers => https://github.com/adelowo/reblog/tree/master/handler

https://github.com/adelowo/reblog/blob/master/main.go#L24

qwo commented 7 years ago

I agree with the DI approach. This article does a good job showing a few approach. http://www.alexedwards.net/blog/organising-database-access

JackyChiu commented 7 years ago

Yep I've switch it using DI!