Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> ...there's no "model" layer to work with

There's certainly not an Active Record -esque ORM for Go, but that doesn't prevent you from writing a very simple model layer. Write a few structs to represent your models, and use database/sql (or another DB interface) to unmarshal your response into the struct as needed.

i.e.

   type User struct {
      Id int
      Email string
      OAuthId string
      Created time.Time
      Active bool
   }

   user := &User{}
   
   err := r.Table("heroes").Get(user_id).Run(session).One(&user)

   fmt.Printf("%s", user.Email)
Obviously the example above is very minimal, but you can see how straightforward it is to describe "models" and query against them.

I'm finding that the code to do this is no more verbose (if at all) than writing out my models.py in Django.



database/sql? Really?

I cant even express much little I like that api.

Lets just start with: no comprehensive test suite to make sure drivers work, drivers that don't work (or work 'if you use the api in a particular way only; which defeats the purpose of having an api), no cross database support.

There are some good database apis, but using database/sql wouldn't be my advice (hint: use a c binding to a cpp orm).

I haven't heard of lots of people using database/sql; most shy around from it for mongo or similar as far as I'm aware.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: