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

Support for named parameters #28

Open
chshersh opened this issue Oct 23, 2018 · 3 comments
Open

Support for named parameters #28

chshersh opened this issue Oct 23, 2018 · 3 comments

Comments

@chshersh
Copy link

Currently in order to use arguments with SQL queries I'm using question marks ?. I wonder, how difficult it would to add support for named parameters to be able to write queries like this:

    updateUploadHistory :: UTCTime -> m ()
    updateUploadHistory curTime = executeNamed_ [sql|
        INSERT INTO file_upload_history
            (file_name, uploader_id, timestamp, data_type, remarks)
        VALUES
            (:file, :uploader, :time, :type, :remarks)
        |] [ ":file"     := duFileName
           , ":uploader" := adminId
           , ":time"     := curTime
           , ":type"     := duDataType
           , ":remarks"  := duRemarks
           ]

It's much more convenient to write with named arguments (as any other query) because we don't need to care about order in which arguments are passed.

@winterland1989
Copy link
Owner

While it's good to have such helpers, I'm afraid this is out of this package's functionality a little bit, since this package is intend to be a low-level database driver.

But anyway don't get discouraged, the bottom line is, if someone can submit a lightweight patch, I would like to accept it. An extra package could be a better idea if the code is getting larger(> ~ 300 loc).

@chshersh
Copy link
Author

@winterland1989 Thanks for the answer! My question is mostly about whether MySQL supports named parameters on the protocol level or should I implement my own custom parser of Query.

@winterland1989
Copy link
Owner

winterland1989 commented Oct 23, 2018

There is no server-side support AFAIK, e.g. see the discussion here.

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

2 participants