0

Is it possible to create a custom rawSQL in yesod?

for example i have a Model for images

Images
    filename String
    description Text Maybe
    date UTCTime
    deriving Show

and i have a rawSQL query of

selectImages :: Handler [Entity Images]
selectImages = do
      runDB $ rawSql s []
      where s =  "SELECT ?? from images;"

but instead of this string query code SELECT ?? from images;. I would like to SELECT id, CONCAT('upload/', filename) as path from images;.

Hope you help me thank you in advance.

Ryan Monreal
  • 587
  • 5
  • 16
  • 1
    Not an answer to the question you're asking but I'd want to do that conversion in the application layer rather than at the database. Specifically I'd return the filename strings then prepend 'upload/' to them with a Haskell function. – cms_mgr Apr 14 '15 at 16:20
  • thank you for you input :-) i solve this today using the toJSON :) – Ryan Monreal Apr 15 '15 at 02:27
  • 1
    Cool, remember to stick your solution in as an answer for the benefit of future viewers. Answering your own question is actively encouraged on SO. – cms_mgr Apr 15 '15 at 08:40

1 Answers1

1

I solve this problem using toJSON , This Link helps me alot also with the help of IRC #haskell, #yesod channel.

Ryan Monreal
  • 587
  • 5
  • 16