-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
To simplify explanation the proposal below uses this specific example models: ``` type User struct { ID uuid.UUID `json:"id"` Name string `json:"name"` } type Order struct { ID uuid.UUID UserID uuid.UUID `json:"user_id"` // references User's ID field Quantity int } ``` The API would allow to join two tables based on field equality: ``` userOrders, err := tigris.GetJoin[User, Order](db, "id", "user_id") ``` Now results can be read by: ``` it, err := userOrders.Read(ctx, filter.Eq("name")) ``` where filter is applied to the left table. Results could be iterated as: ``` var user User var orders []*Order for it.Next(&user, &orders) { fmt.Printf("user=%v orders=%v\n", user, orders) } ``` Implementation details: First request is issued to the left table with filter provided to Read API. Result is read into memory and request is prepared for the right table. Which will have the following filter `filter.Or(filter.Eq("user_id", {value of id field}), ....)`. Result from the first query is put in the map with ID as the key, while reading the result from second query we append it to the corresponding map bucket. So as merge is done in the memory, this approach is not effective for very large results.
- Loading branch information
Showing
6 changed files
with
921 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.