file20.hx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. N::User {
  2. name: String,
  3. age: U32,
  4. email: String,
  5. created_at: Date DEFAULT NOW,
  6. updated_at: Date DEFAULT NOW,
  7. }
  8. N::Post {
  9. content: String,
  10. created_at: Date DEFAULT NOW,
  11. updated_at: Date DEFAULT NOW,
  12. }
  13. E::Follows {
  14. From: User,
  15. To: User,
  16. Properties: {
  17. since: Date DEFAULT NOW,
  18. }
  19. }
  20. E::Created {
  21. From: User,
  22. To: Post,
  23. Properties: {
  24. created_at: Date DEFAULT NOW,
  25. }
  26. }
  27. QUERY CreateUser(name: String, age: U32, email: String) =>
  28. user <- AddN<User>({name: name, age: age, email: email})
  29. RETURN user
  30. QUERY CreateFollow(follower_id: ID, followed_id: ID) =>
  31. follower <- N<User>(follower_id)
  32. followed <- N<User>(followed_id)
  33. AddE<Follows>::From(follower)::To(followed_id) // don't need to specify the `since` property because it has a default value
  34. RETURN "success"
  35. QUERY CreatePost(user_id: ID, content: String) =>
  36. user <- N<User>(user_id)
  37. post <- AddN<Post>({content: content})
  38. AddE<Created>::From(user)::To(post) // don't need to specify the `created_at` property because it has a default value
  39. RETURN post
  40. QUERY GetUsers() =>
  41. users <- N<User>
  42. RETURN users
  43. QUERY GetPosts() =>
  44. posts <- N<Post>
  45. RETURN posts
  46. QUERY GetPostsByUser(user_id: ID) =>
  47. posts <- N<User>(user_id)::Out<Created>
  48. RETURN posts
  49. QUERY GetFollowedUsers(user_id: ID) =>
  50. followed <- N<User>(user_id)::Out<Follows>
  51. RETURN followed
  52. QUERY GetFollowedUsersPosts(user_id: ID) =>
  53. followers <- N<User>(user_id)::Out<Follows>
  54. posts <- followers::Out<Created>::RANGE(0, 40)
  55. RETURN posts::{
  56. post: content,
  57. creatorID: _::In<Created>::ID,
  58. }