-
Notifications
You must be signed in to change notification settings - Fork 949
Embedding a struct in a has-one relationship #3746
Unanswered
bjubes
asked this question in
Issue Triage
-
In my schema i have a Job that always has a foreign key to a video. I'd like the Job struct to have an embedded video every time i am using it. I can achieve this on a select doing the following:
-- name: GetJobEmbedVideo :one
SELECT sqlc.embed(videos), job.*
FROM job
JOIN videos ON job.video_id= videos.id
WHERE job.id = 1ドル;
output struct:
type GetJobEmbedVideoRow struct {
Video Video `json:"video"`
ID int32 `json:"id"`
Action string `json:"action"`
VideoID uuid.UUID `json:"video_id"`
Completed bool `json:"completed"`
Errored bool `json:"errored"`
Attempts int32 `json:"attempts"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
but I can't seem to get it to work when inserting a job. I've tried
INSERT INTO job(
action, video_id
) VALUES (
1,ドル 2ドル
)
RETURNING sqlc.embed(videos), job.*;
which won't compile.
INSERT INTO job(
action, video_id
) VALUES (
1,ドル 2ドル
)
RETURNING (
SELECT sqlc.embed(videos), job.*
FROM job
JOIN videos ON job.video_id = videos.id
WHERE job.id = lastval()
);
gives:
type CreateJobRow struct {
Video Video `json:"video"`
}
What is the correct SQL for this to work on insert (and hopefully update as well)
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment