<div dir="ltr"><div><div><div><div><div>Hello all,<br><br></div>I wrote some template Haskell code that looks up data in a cassandra database in the system.schema_columns table using this library: <a href="https://github.com/the-real-blackh/cassandra-cql/blob/master/Database/Cassandra/CQL.hs">https://github.com/the-real-blackh/cassandra-cql/blob/master/Database/Cassandra/CQL.hs</a><br><br></div>Currently cassandra-cql lets you make queries like this:<br><br>getColFamInfo :: Query Rows () (Text, Text, Text, Text, Text)<br>getColFamInfo = "select keyspace_name, columnfamily_name, column_name, type, validator from system.schema_columns"<br><br></div>And then it returns type (Text,Text,Text,Text,Text).<br><br></div><div>I'd prefer to be able to write a query like:<br><br></div><div>data MyRecord = MyRecord { a :: Text, b :: Text, c :: Text, d :: Text }<br><br>getColFamInfo :: Query Rows () (Maybe MyRecord)<br>getColFamInfo = "select keyspace_name, columnfamily_name, column_name, type, validator from system.schema_columns"<br><br><br></div><div>Point being: I have types being generated from cassandra, but I have no idea where I'd start modifying the cassandra-cql library to use those types.<br><br></div><div>Could anyone offer any direction? Also...<br><br></div><div>Below is a snippet of how Query is implemented, but you can find the full code here: <a href="https://github.com/the-real-blackh/cassandra-cql/blob/master/Database/Cassandra/CQL.hs">https://github.com/the-real-blackh/cassandra-cql/blob/master/Database/Cassandra/CQL.hs</a></div><div><br></div>Query Looks like:<br><br></div>{ - START CODE -}<br><div><br>-- | The first type argument for Query. Tells us what kind of query it is.<br>data Style = Schema   -- ^ A query that modifies the schema, such as DROP TABLE or CREATE TABLE<br>           | Write    -- ^ A query that writes data, such as an INSERT or UPDATE<br>           | Rows     -- ^ A query that returns a list of rows, such as SELECT<br><br>-- | The text of a CQL query, along with type parameters to make the query type safe.<br>-- The type arguments are 'Style', followed by input and output column types for the<br>-- query each represented as a tuple.<br>--<br>-- The /DataKinds/ language extension is required for 'Style'.<br>data Query :: Style -> * -> * -> * where<br>    Query :: QueryID -> Text -> Query style i o<br>    deriving Show<br><br>queryText :: Query s i o -> Text<br>queryText (Query _ txt) = txt<br><br>instance IsString (Query style i o) where<br>    fromString = query . T.pack<br><br>-- | Construct a query. Another way to construct one is as an overloaded string through<br>-- the 'IsString' instance if you turn on the /OverloadedStrings/ language extension, e.g.<br>--<br>-- > {-# LANGUAGE OverloadedStrings #-}<br>-- > ...<br>-- ><br>-- > getOneSong :: Query Rows UUID (Text, Text, Maybe Text)<br>-- > getOneSong = "select title, artist, comment from songs where id=?"<br>query :: Text -> Query style i o<br>query cql = Query (QueryID . hash . T.encodeUtf8 $ cql) cql<br>{ - END CODE -}<br><br><br></div><div>Thanks,<br><br></div><div>Cody Goodman<br></div></div>