Comment

Comment by bigpigeon

when you want to make complex sql,toyorm maybe word better

find the name = "tom" user and it subquery blog title = "first blog" e.g

  brick := toy.Model(&User{}).Where("=",Offsetof(User{}.Name),"tom").
			Preload(Offsetof(User{}.Blog)).Where("=", Offsetof(Blog{}.Title), "first blog").Enter()

  brick.Find(&user)
  // raw sql
  // select id,name,data, from user where name = "tom" limit 1
  // select id,title,content,user_id from blog where user_id = @user.id and title = "first blog"
toyorm select field with Offsetof, it better when you want to refactor struct field name and you can operation main query as sub query
parent bigpigeon 8 years ago

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton