Skip to content

SELECT %Columns% WHERE... #3888

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

Open
nurp opened this issue Mar 24, 2025 · 0 comments
Open

SELECT %Columns% WHERE... #3888

nurp opened this issue Mar 24, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@nurp
Copy link

nurp commented Mar 24, 2025

What do you want to change?

I had a conversation with chatgpt to simplfy my .sql file.
I am repeating the same fields three times for 3 different queries (select_user_by_email, select_user_by_username, select_user_by_id). It recommended this (thought, it didn't work. I guess it is not a feature yet)

-- name: UserColumns :const
SELECT 
  user_uid, 
  email, 
  username, 
  name, 
  avatar_url, 
  created_at, 
FROM users

-- name: SearchUsersByEmail :many
/*@ UserColumns */ WHERE email ILIKE $1
ORDER BY created_at DESC
LIMIT $2 OFFSET $3;

-- name: SearchUsersByUsername :many
/*@ UserColumns */ WHERE username ILIKE $1
ORDER BY created_at DESC
LIMIT $2 OFFSET $3;

-- name: SearchUsersByUID :many
/*@ UserColumns */ WHERE user_uid::text = $1
ORDER BY created_at DESC
LIMIT $2 OFFSET $3;

Can we have this feature? Or does everyone use Views in database for this kind of thing?

What database engines need to be changed?

No response

What programming language backends need to be changed?

No response

@nurp nurp added the enhancement New feature or request label Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant