mysql-haskell
mysql-haskell copied to clipboard
Support for named parameters
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.
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 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.
There is no server-side support AFAIK, e.g. see the discussion here.