Replace magic comments with SET #871
Unanswered
kyleconroy
asked this question in
Ideas
Replies: 2 comments 2 replies
-
I like the conciseness of the magic comment. I'd be nervous about making it more difficult to write a query. I hope you'd continue supporting that and maybe also support other methods if you need more complexity. |
Beta Was this translation helpful? Give feedback.
2 replies
-
CREATE TABLE authors (
id BIGSERIAL PRIMARY KEY,
name text NOT NULL,
bio text
);
PREPARE get_author AS
SELECT * FROM authors
WHERE id = $1 LIMIT 1;
PREPARE list_authors AS
SELECT * FROM authors
ORDER BY name;
PREPARE create_author AS
INSERT INTO authors (
name, bio
) VALUES (
$1, $2
)
RETURNING *;
PREPARE delete_authors AS
DELETE FROM authors
WHERE id = $1; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
sqlc currently uses a magic comment to configure per-query name and return type:
While this has worked well so far, there are some significant downsides. It's very easy to make a typo. If we want to add additional per-query configuration options (custom models, overrides, etc.), we need to change the syntax.
Instead of continuing down the comment path, I think it's better to use the
SET
command, already part of the SQL standard.Thoughts?
https://www.postgresql.org/docs/current/sql-set.html
https://dev.mysql.com/doc/refman/8.0/en/set-statement.html
Beta Was this translation helpful? Give feedback.
All reactions