<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class="elementToProof">
<span style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;background-color:rgb(255,255,255);color:rgb(0,0,0)" class="ContentPasted0">Hello--</span></div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);" class="elementToProof">
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;background-color:rgb(255,255,255);color:rgb(0,0,0)">
<br class="ContentPasted0">
</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;background-color:rgb(255,255,255);color:rgb(0,0,0)" class="ContentPasted0">
I use postgresql-simple and for selecting rows from one table I have the following function.</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;background-color:rgb(255,255,255);color:rgb(0,0,0)">
<br class="ContentPasted0">
</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;background-color:rgb(255,255,255);color:rgb(0,0,0)">
<span style="font-family:Consolas,Courier,monospace;font-size:10pt" class="ContentPasted0">runMyQuery :: Connection</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;background-color:rgb(255,255,255);color:rgb(0,0,0)">
<span style="font-family:Consolas,Courier,monospace;font-size:10pt" class="ContentPasted0"> -> String -- query with '?' params to bind</span><br class="ContentPasted0">
</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;background-color:rgb(255,255,255);color:rgb(0,0,0)">
<span style="font-family:Consolas,Courier,monospace;font-size:10pt" class="ContentPasted0"> -> Int -- first param</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;background-color:rgb(255,255,255);color:rgb(0,0,0)">
<span style="font-family:Consolas,Courier,monospace;font-size:10pt" class="ContentPasted0"> -> Int -- second param</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;background-color:rgb(255,255,255);color:rgb(0,0,0)">
<span style="font-family:Consolas,Courier,monospace;font-size:10pt" class="ContentPasted0"> -> IO [MyTable1]</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;background-color:rgb(255,255,255);color:rgb(0,0,0)">
<span style="font-family:Consolas,Courier,monospace;font-size:10pt" class="ContentPasted0">runMyQuery conn dbQuery param1 param2 = query conn dbQuery $ (param2, param2)</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;background-color:rgb(255,255,255);color:rgb(0,0,0)">
<br class="ContentPasted0">
</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;background-color:rgb(255,255,255);color:rgb(0,0,0)">
<span style="font-family:Consolas,Courier,monospace;font-size:10pt" class="ContentPasted0">data MyTable1 = MyTable1 {col1 :: Int, col2 :: Int, col3 :: String}</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;background-color:rgb(255,255,255);color:rgb(0,0,0)">
<br class="ContentPasted0">
</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;background-color:rgb(255,255,255);color:rgb(0,0,0)">
<span style="font-family:Consolas,Courier,monospace;font-size:10pt" class="ContentPasted0">instance FromRow MyTable1 where fromRow = MyTable1 <$> field <*> field <*> field<br>
</span></div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;background-color:rgb(255,255,255);color:rgb(0,0,0)">
<br class="ContentPasted0">
</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;background-color:rgb(255,255,255);color:rgb(0,0,0)" class="ContentPasted0">
There are some things I'd like to improve:</div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;background-color:rgb(255,255,255);color:rgb(0,0,0)">
<ol>
<li><span class="ContentPasted0">I will have to write "MyTable1", "MyTable2", ... datatypes, one for each table, but would like to have only one function runMyQuery where the return type is a generic IO [MyModel]. My problem is that I don't know how to write
it for tables with different number of columns and different SQL types.</span></li><li><span class="ContentPasted0">The 2nd<span class="ContentPasted0"> </span>to the penultimate arguments of runMyQuery are the arguments to bind into the SQL string query. This means that I should write several different version of "runMyQuery" each with a
different number of arguments, but would like to have only one.</span></li></ol>
<div class="ContentPasted0">Can you recommend some approaches?</div>
<div><br class="ContentPasted0">
</div>
<span class="ContentPasted0">Thanks.</span></div>
<br>
</div>
</body>
</html>