You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- name: CategoryGetAllAndChildren :manySELECT swipe_category.*,
sqlc.embed(swipe_sub_category)
FROM swipe_category
LEFT JOIN swipe_sub_category onswipe_category.swipe_category_id=swipe_sub_category.swipe_category_idWHEREswipe_category.organization_id= $1;
Where each swipe_sub_category has a foreign key relationship to category, I would expect the generated struct to be this:
typeCategoryGetAllAndChildrenRowstruct {
SwipeCategoryIDstring`db:"swipe_category_id" json:"swipeCategoryID"`CreatedAt pgtype.Timestamp`db:"created_at" json:"createdAt"`OrganizationIDstring`db:"organization_id" json:"organizationID"`Namestring`db:"name" json:"name"`// This field would be a sliceSwipeSubCategory**[]SwipeSubCategory**`db:"swipesubcategory" json:"swipesubcategory"`
}
and not this:
typeCategoryGetAllAndChildrenRowstruct {
SwipeCategoryIDstring`db:"swipe_category_id" json:"swipeCategoryID"`CreatedAt pgtype.Timestamp`db:"created_at" json:"createdAt"`OrganizationIDstring`db:"organization_id" json:"organizationID"`Namestring`db:"name" json:"name"`// Not just a fieldSwipeSubCategorySwipeSubCategory`db:"swipesubcategory" json:"swipesubcategory"`
}
Am I missing how to use this feature?
What database engines need to be changed?
PostgreSQL
What programming language backends need to be changed?
Go
The text was updated successfully, but these errors were encountered:
This isn't what sqlc.embed does. Embedded structs are just a way to allow for code reuse of common collections of fields. If it were otherwise and the generated code took the returned rows and manipulated them to produce a struct with a one-to-many relationship, that function would then return fewer rows than you would expect from the SQL.
sqlc is just a library to generate type-safe SQL that output the returned queries as named structs. It's helpful boilerplate generation but its still just SQL and row scanning under the hood. It's not an ORM.
What do you want to change?
Given this query:
Where each
swipe_sub_category
has a foreign key relationship to category, I would expect the generated struct to be this:and not this:
Am I missing how to use this feature?
What database engines need to be changed?
PostgreSQL
What programming language backends need to be changed?
Go
The text was updated successfully, but these errors were encountered: