Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use NamedStmt when building queries #22

Open
marianysilva opened this issue Mar 13, 2024 · 0 comments
Open

Use NamedStmt when building queries #22

marianysilva opened this issue Mar 13, 2024 · 0 comments

Comments

@marianysilva
Copy link
Contributor

Short description

We can improve the readability and maintainability of our queries using NamedStmt

Description

One of the features sqlx offers is the NamedStmt, which represents a prepared statement. A NamedStmt allows you to use named parameters in your SQL queries instead of the positional parameters(?) that are typically used in prepared statements. Named parameters make your queries more readable and maintainable by allowing you to use meaningful names instead of remembering the order of parameters.

Example:

// FROM
SELECT * FROM courses WHERE uuid = $1
// TO
SELECT * FROM courses WHERE uuid = :uuid

@rluders applied NamedStmt in his Golang course here

Additional information

NamedStmt
microservice-with-go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant