ú·ÔÓR      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQ(c) Ole Krüger 2015-2016BSD3Ole Krüger <ole@vprsm.de>None35 Column typePack column value.Unpack column value.Descripe the column type.Description of a columnType name (e.g. bool, integer)Can the column be null?+Query parameter or value of a column - see  on how to generate s manually but conveniently. Type object identifier  Data value  Data format*Generate column description in SQL. Think  CREATE TABLE.0Generate the sanitized representation of a name.;Similiar to "sanitizeName" but encloses the name in quotes.,Generate the name for the identifying field.9Similiar to "identField" but encloses the name in quotes.RAProduce the two-digit hexadecimal representation of a 8-bit word.S>Retrieve 8-bit word from two-digit hexadecimal representation.T.Unpack a byte array in textual representation.U,Pack textual representation of a byte array.VFinish the parsing process.WParse a ByteString.XBuild strict ByteString.& RSTUVWXYZ[\]^_`abcd   RSTUVWXYZ[\]^_`abcd(c) Ole Krüger 2015-2016BSD3Ole Krüger <ole@vprsm.de>None1A row containing all a list of all column values. Result row#Extract rows from the given result.Column informationResult processor+Error that occured during result processingProcess the result.eGet the number of columns.(Get the column number for a column name.Get the type of a column.Get the format of a column. Get information about a column.!Do something for each row."Get cell value.fGet cell value.#Unpack cell value.e !"f#ghijklmn !"# !"#e !"f#ghijklmn(c) Ole Krüger 2015-2016BSD3Ole Krüger <ole@vprsm.de>Noneo Query segment$3Query including statement and parameters. Use the 0- quasi-quoter to conveniently create queries.& Statement' Parameters( Attach meta data to a table type)Describe the table.*Describe table name.+Describe table identifier.,Description of a table type. Table name/Identifier column name0 Generate a $ from a SQL statement.Table and column namesÿ7All plain identifiers will be treated as Haskell names. They are going to be resolved to their fully-qualified and quoted version. Beware, the use of names which don't refer to a table type or field will likely result in unknown table or column errors. The associated table name of a type is retrieved using *C. If you don't want a name to be resolved use a quoted identifier.Example: _{-# LANGUAGE QuasiQuotes #-} module MyModule where ... data Table = Table { myField :: Int } mkTable ''Table [] myQuery :: $ myQuery = [0.| SELECT * FROM Table WHERE myField > 1337 |] "The SQL statement associated with myQuery will be: >SELECT * FROM "MyModule.Table" WHERE "MyModule.myField" > 1337 Variables%You can use reference variables with  $myVariable0. The variable's type has to be an instance of 5, otherwise it cannot be attached as query parameter.Example: 2magicNumber :: Int magicNumber = 1337 myQuery :: $ myQuery = [06| SELECT * FROM Table WHERE myField > $magicNumber |] Row identifiersEach instance of (Table a) => Row a, (Table a) =>  Reference a± and each row of the actual table inside the database has an identifier value. These identifiers are used to reference specific rows. The identifier column is exposed via the &MyTable5 pattern. Identifier field names are resolved using +.Example: [0G| SELECT * FROM TableA, TableB WHERE refToB = &TableB |] Note refToB is a field of TableAD. In different circumstances one would write such query as follows. 5SELECT * FROM TableA a, Table b WHERE a.refToB = b.idpList of relevant SQL keywordsq SQL keywordrAlpha numeric characters UnderscoretDotuNamev Possible namewVariablex IdentifieryQuotezSegments{Turn Text into a UTF-8-encoded  ByteString expression.|GReduce segments in order to resolve names and collect query parameters.}"Parse quasi-quoted PG Store Query."o~€‚ƒ$%&'()*+,-./0pqrstuvwxyz{|} $%&'()*+,-./0 ,-./()*+$%&'0o~€‚ƒ$%&'()*+,-./0pqrstuvwxyz{|}(c) Ole Krüger 2015-2016BSD3Ole Krüger <ole@vprsm.de>None1 An interaction with the database2Error during errand8Run an errand.9Raise an error.:&Execute a query and return its result.;‚Execute a query and process its result set. It is essential that all fields required by the underlying result parser are present.<Execute a query. 123456789:;< 123456789:;< 234567189:;<123456789:;<(c) Ole Krüger 2015-2016BSD3Ole Krüger <ole@vprsm.de>None&= Options to P.>+A combination of fields must be unique. Unique ['name1, 'name2, ...]7 works analogous to the following table constraint: UNIQUE (name1, name2, ...)?\A combination of fields references another combination of fields from a different table. GForeignKey ['name1, 'name2, ...] ''RefTable ['refname1, 'refname2, ...]0 works like this table constraint in SQL: LFOREIGN KEY (name1, name2, ...) REFERENCES RefTable(refname1, refname2, ...)@$A value of that type contains an ID.ARetrieve the underlying ID.C)Insert a row into the table and return a J to the inserted row.D/Find the row identified by the given reference.EUpdate an existing row.FDelete a row from the table.GFGenerate the query which creates this table inside the database. Use  mkCreateQuery for convenience.HExtract rows from a result set.IExtract only a J to each row.JReference to a rowL Resolved rowN IdentifierOValue„Unqualify a name.…&Generate the insert query for a table.†*Generate the select query for a table row.‡&Generate the update query for a table.ˆ&Generate the delete query for a table.‰&Generate the create query for a table.вGenerate an expression which gathers all records from a type and packs them into a list. `packParamsE 'row ['field1, 'field2]` generates `[pack (field1 row), pack (field2 row)]`‹@Generate an expression which gathers information about a column.ŒRGenerate a query which binds information about a column to the column's info name.AGenerate a name which is reserved for information about a column.Ž=Generate an expression which unpacks a column at a given row.`Generate a query which binds the unpacked data for a column at a given row to the column's name.dGenerate an expression which uses a record constructor with variables that correspond to its fields.‘GGenerate an expression which unpacks a table instance from a given row.’]Generate an expression which traverses all rows in order to unpack table instances from them.“FGenerate an expression which retrieves a table instance from each row.”?Generate an expression which retrieves a reference to each row.•Implement an instance B for the given type.–6Check that all field types have an instance of Column.P Implement BA for a data type. The given type must fulfill these requirements: Data typeNo type contextNo type variables,One record constructor with 1 or more fields)All field types must have an instance of Example: ‘{-# LANGUAGE TemplateHaskell #-} module Movies where ... data Movie = Movie { movieTitle :: String, movieYear :: Int } deriving Show Pa ''Movie [] data Actor = Actor { actorName :: String, actorAge :: Int } deriving Show P@ ''Actor [] data MovieCast = MovieCast { movieCastMovie :: J Movie, movieCastActor :: J Actor } deriving Show P ''MovieCast [] —)Check if the given name refers to a type.Q Generate a $9 which will create the table described my the given type.Example: &data Table = Table { myField :: Int } P ''Table [] ... < $(Q ''Table) .=>?@ABCDEFGHIJKLMNO„…†‡ˆ‰Š‹ŒŽ‘’“”•–P—Q˜™š›œ,-./=>?@ABCDEFGHIJKLMNOPQ,-./BCDEFGHILMNOJK@A=>?PQ =>?@ABCDEFGHIJKLMNO„…†‡ˆ‰Š‹ŒŽ‘’“”•–P—Q˜™š›œ(c) Ole Krüger 2015-2016BSD3Ole Krüger <ole@vprsm.de>None!$%&'012345678;<=>?CDEFJKLMNOPQ!=>?PLMNOJK$%&'0Q23456718;<CDEF       !"#$%&'(()*+,-.//0123456789:;<=>?@ABCDEFGHIJKKLLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œpgsto_57c7x5Zz7P8HHO9Q1YYXsX!Database.PostgreSQL.Store.Columns Database.PostgreSQL.Store.ResultDatabase.PostgreSQL.Store.Query Database.PostgreSQL.Store.ErrandDatabase.PostgreSQL.Store.TableDatabase.PostgreSQL.StoreColumnpackunpackdescribeColumnColumnDescriptioncolumnTypeNamecolumnTypeNullValue valueType valueData valueFormat NullValuemakeColumnDescription sanitizeName sanitizeName' identField identField'RawRowResultresultProcessor ColumnInfoResultProcessor ResultError ColumnMissing ValueErrorrunResultProcessor columnNumber columnType columnFormat columnInfo foreachRow cellValueunpackCellValueQueryqueryStatement queryParamsDescribableTable describeTabledescribeTableNamedescribeTableIdentifierTableDescription tableNametableIdentifierpgsqErrand ErrandErrorNoResult ExecErrorUnexpectedEmptyResult UserError runErrandraiseErrandError executeQueryqueryquery_TableConstraintUnique ForeignKeyHasID referenceIDTableinsertfindupdatedelete createQuerytableResultProcessortableRefResultProcessor ReferenceRowrowIDrowValuemkTable mkCreateQuery word8ToHex hexToWord8fromTextByteArraytoTextByteArray finishParser parseMaybebuildByteString$fColumnByteString$fColumnByteString0 $fColumnText $fColumnText0 $fColumn[] $fColumnInt64 $fColumnInt32 $fColumnInt16 $fColumnInt8 $fColumnInt $fColumnBool $fColumnMaybe numColumns cellValue'$fResultRawRow$fResult(,,,,,,)$fResult(,,,,,)$fResult(,,,,) $fResult(,,,) $fResult(,,) $fResult(,) $fResult()SegmentreservedSQLKeywordskeywordalphaNum underscoredotname possibleNamevariable identifierquotesegmentstextE reduceSegmentparseStoreQueryEKeyword PossibleNameVariable IdentifierQuoteOther unqualifyName insertQueryE findQueryE updateQueryE deleteQueryE createQueryE packParamsE columnInfoEbindColumnInfoScolumnInfoName unpackColumnE bindColumnSconstructRecordE unpackRowE unpackRowsEtableResultProcessorEtableRefResultProcessorEimplementTableDvalidateFieldsisType$fHasIDReference $fHasIDRow$fResultReference $fResultRow$fColumnReference