News for hackers. Stuff that matters.
Re:Toyorm – ORM for Go by nemothekid on Monday April 02, 2018 @12:04AM (#16732229)
As far as Go ORMs go, there isn’t a decent one that handles what I consider a killer feature of ORMs - relationships. I think sqlx is good enough for most, but I once inherited a project that the management wanted to rewrite off of Scala to Go. Some of the relationships were so complex that hand writing complex joins would have been challenging. Gorm came closest, but it’s “eager fetching” features executes n+1 queries rather than joins.
Re:Toyorm – ORM for Go by astockwell on Monday April 02, 2018 @12:28AM (#16732339)
Yes yes and yes. Unless the usecase is truly as simple as CRUD with a single model (in which case I reach for gorm), The easiest road often seems to be just using sqlx and hand-writing the inserts/updates.
Re:Toyorm – ORM for Go by swah on Monday April 02, 2018 @04:54PM (#16739187)
What about 90% of cases being simple CRUD and 10% you just do the usual "raw SQL query"?

I've chosen this path of using only sqlx on my current work project (only me) and regret it, because so much typing..

Re:Toyorm – ORM for Go by bm1362 on Monday April 02, 2018 @06:02PM (#16739810)
I also work alone on a Go service and have some complex models. I used Gorm and then for complex selects broke out the raw sql. It works okay, I’m still having to bolt on things like OCC and Versioning to my models. I’m glad I used it though- it gave me a solid foundation to work off and replace the bits that don’t quite work well.
Re:Toyorm – ORM for Go by kemitche on Monday April 02, 2018 @07:17PM (#16740348)
I use Masterminds' squirrel library to build up queries which cuts down on the amount of hand written SQL I need.
Re:Toyorm – ORM for Go by bigpigeon on Monday April 02, 2018 @12:34AM (#16732361)
toyorm support half hand-writing you can bind the model and use its field in sql e.g https://github.com/bigpigeon/toyorm/blob/master/examples/sim...
Re:Toyorm – ORM for Go by sametmax on Tuesday April 03, 2018 @03:09AM (#16742486)
In that case, just copy the SQLAlchemy design.

It has a functional API and an ORM API, and have a very rich set of join strategies available.

Re:Toyorm – ORM for Go by sjellis on Monday April 02, 2018 @03:16AM (#16732892)
Pop has some support for associations:

https://github.com/markbates/pop

Re:Toyorm – ORM for Go by donatj on Monday April 02, 2018 @02:48PM (#16737871)
Appears unmaintained? "This repository has been archived by the owner. It is now read-only."
Re:Toyorm – ORM for Go by acidus on Monday April 02, 2018 @02:51PM (#16737907)
Re:Toyorm – ORM for Go by vldo on Monday April 02, 2018 @02:54PM (#16737952)
Re:Toyorm – ORM for Go by velodrome on Monday April 02, 2018 @04:39PM (#16739056)
> I think sqlx is good enough for most

sqlx is nice but I wish it had query logging.

Re:Toyorm – ORM for Go by kemitche on Monday April 02, 2018 @07:18PM (#16740357)
It's relatively easy to write a wrapper around your sqlx DB that logs queries before sending them to the underlying sqlx DB. I agree it would be nice to be built in, but then you're kind of locked into the logging interface(s) sqlx supports.
Re:Toyorm – ORM for Go by bigpigeon on Wednesday April 11, 2018 @09:47AM (#16810990)
now toyorm support join operation
Re:Toyorm – ORM for Go by bigpigeon on Monday April 02, 2018 @12:06PM (#16735788)
you means use join to query and output data as table? otherwise I think “eager fetching” is better way
Re:Toyorm – ORM for Go by nemothekid on Monday April 02, 2018 @12:40PM (#16736202)
Lets say I have a relationship where a User has one Profile.

    type User Struct { Id int ProfileId int Profile Profile }
    type Profile Struct { Id int }
For a load like this:

    var u User
    db.Model(&User{}).Preload("Profile").Where("id = ?", 7).Take(&u)
Gorm will do something like this:

    SELECT * FROM users WHERE id=7;
    SELECT * FROM profiles WHERE id=7;
Where a join would be more desirable (only involves 1 trip to the db):

    SELECT * FROM users JOIN profiles ON profiles.id=users.profileid WHERE users.id=7
This also has a huge effect on when your initial queries aren't restricted by ID. Gorm will do huge "id IN (1,2,3,4)" queries - or sometimes if I need to filter on a relation (i.e. get users where profile.foo = bar), I end up doing the join getting that data anyways, then the eager queries loads that data again.
Re:Toyorm – ORM for Go by bigpigeon on Monday April 02, 2018 @09:02PM (#16741002)
In "OneToOne" and "BelongTo" Join is match but in "ManyToMany" and "OneToMany" will generate duplicate data

I think add Join method and only support "One Data" preload is good way