<div dir="ltr"><br><br><div class="gmail_quote">On Fri, Apr 8, 2011 at 9:42 PM, Clint Moore <span dir="ltr"><<a href="mailto:clint@ivy.io">clint@ivy.io</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br><br><div class="gmail_quote"><div class="im">On Thu, Apr 7, 2011 at 12:01 PM, Michael Snoyman <span dir="ltr"><<a href="mailto:michael@snoyman.com" target="_blank">michael@snoyman.com</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div class="gmail_quote"><div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div></div><div>First, what's the 'right way' to get a string representation of a Key?</div>
<div>I generate select form elements from subsets of data in a table. Usually, resulting in 'select name="name_column" value="id_column"'</div><div><br></div></blockquote></div><div>I would probably use the Show instance, unless you have a compelling reason not to.</div>
</div></div></blockquote><div><br></div></div><div>Show on the key gives me 'TableId 1' instead of simply 1. I'm assuming the expectation is not to split the table name off every time, though I don't see a function to get just the id of a row. ie tableId </div>
<div><br></div><div>> x <- myConnect $ selectList [TableNameNe "honk"] [] 0 0</div><div>> fst $ head x</div><div>TableId 1</div><div><br></div><div>> tableId $ snd x <- convenient!</div><div class="im">
<div><br></div></div></div></blockquote><div><br></div><div>I think the function you're looking for is fromPersistKey, which will give you back an Int64. Be warned, however, that in Persistent 0.5, it will instead give you back a PersistValue, since some backends (MongoDB in particular) use more than 64 bits for their keys.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="gmail_quote"><div class="im"><div>
</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>Second, for types that have relationships, is there a shortcut or something I'm not seeing that will allow me to derive Data and Typeable?</div>
<div>example:</div><div><br></div><div>Species</div><div> name String Eq</div><div> deriving Data Typeable</div><div><br></div><div>Animal</div><div> name String</div><div> species SpeciesId</div><div> deriving Data Typeable <-- error! There aren't instances generated, at least that it can find, of SpeciesId for Data.Data</div>
<div><div></div><div>
<div><br></div></div></div></blockquote></div><div>I wanted to enable this by default in Persistent, but it would require user code to have DeriveDataTypeable enabled. I can consider putting it back in, but I wouldn't mind web-devels input.</div>
</div></div></blockquote><div><br></div></div><div>For my uses, the only place that this makes life much easier is when using HStringTemplate. If it were enabled, you could simply set a row as an argument directly with 'setAttribute' instead of having to massage the data beforehand.</div>
<div><br></div><div>Other than that, I can't think of a compelling reason to enable it by default.</div><div><br></div><div>As I write this, I thought perhaps you could add cabal flags to enable this if you knew that you needed it, but then you start having to litter your code with #ifdefs and that starts to make code look very ugly very quickly.</div>
<div><br></div><div>Maybe someone has another compelling use case for enabling this by default?</div><div><br></div><div> </div></div>
</blockquote></div><br><div>I definitely don't want to deal with cabal flags for this, it would mean that some packages wouldn't install on your system depending on how you build Persistent. For your case, it might be acceptable to just use standalone deriving declarations, ie:</div>
<div><br></div><div>deriving instance Data SpeciesId</div><div>deriving instance Data Animal</div><div>...</div><div><br></div><div>Michael</div></div>