mysql-haskell icon indicating copy to clipboard operation
mysql-haskell copied to clipboard

Support for named parameters

Open chshersh opened this issue 7 years ago • 3 comments

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.

chshersh avatar Oct 23 '18 04:10 chshersh

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).

winterland1989 avatar Oct 23 '18 07:10 winterland1989

@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.

chshersh avatar Oct 23 '18 09:10 chshersh

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

winterland1989 avatar Oct 23 '18 09:10 winterland1989