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

Handle dynamic table columns, names or joins #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

maplenk
Copy link

@maplenk maplenk commented Dec 31, 2024

Trying to handle dynamic table columns, names or joins

SQL Eg:

-- name: get_profit_entries_by_date
-- raw: 1
SELECT * FROM $1 WHERE user_id = ? AND timestamp > ? and timestamp < ?;

Here $1 can be replaced with any table name.

Request Sample:

curl localhost:6060/tasks/get_profit_entries_by_date/jobs -H "Content-Type: application/json" -X POST --data '{"job_id": "myjob", "args": ["USER1", "2017-12-01", "2017-01-01"], "dynamic_params": ["entries"]}'

{"status":"success","data":{"job_id":"myjob","task_name":"get_profit_entries_by_date","queue":"sqljob_queue","eta":null,"retries":0}}

@knadh
Copy link
Collaborator

knadh commented Dec 31, 2024

Hi @maplenk. Thanks for the PR.

That isn't valid SQL syntax though. Neither MySQL nor Postgres support parameters for table names.

@maplenk
Copy link
Author

maplenk commented Dec 31, 2024

Hi @knadh!
I updated the parameters before the query was sent for execution.
It was a use case with my SaaS app where table names are dynamic based on customer ID.

@maplenk
Copy link
Author

maplenk commented Dec 31, 2024

Not sure if it might be needed by others.
Just thought I'd create a PR here as well.

PS,
Thanks a ton for the repo!!!

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

Successfully merging this pull request may close these issues.

2 participants