Skip to content

Instantly share code, notes, and snippets.

@steebchen
Last active December 3, 2019 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steebchen/8f0d43d06361239e0c08e209f74a556f to your computer and use it in GitHub Desktop.
Save steebchen/8f0d43d06361239e0c08e209f74a556f to your computer and use it in GitHub Desktop.

Select API

var result struct{
  User struct{
    Name User.Name.Field
    Email User.Email.Field
    Posts []Post
  }

  Posts []Post

  PostCount int
}

// Select a single user, the 10 first posts, and the total post count.
// .Load allows querying for anything
err := client.Load(
  client.User.FindOne(
    User.Name.Equals("john"),
    // also get the first 5 posts of user john
    User.Posts.Fetch().OrderBy(
      Post.Views.Order(DESC),
    ).First(5).Load(),
  ).Select(User.Name.Select(), User.Email.Select()).Load(),

  client.Post.FindMany().First(10).Load(),

  client.Post.Count().Load(),
).Exec(ctx, &result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment