mysql-haskell-nem-0.1.0.0: Adds a interface like mysql-simple to mysql-haskell.

Copyright(c) 2011 MailRank Inc.
LicenseBSD3
MaintainerJosé Lorenzo Rodríguez
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Database.MySQL.Nem.QueryResults

Description

The QueryResults typeclass, for converting a row of results returned by a SQL query into a more useful Haskell representation.

Predefined instances are provided for tuples containing up to 24 elements.

Synopsis

Documentation

class QueryResults a where Source #

A collection type that can be converted from a MySQL row result.

Instances should use the convert method of the Result class to perform conversion of each element of the collection.

This example instance demonstrates how to convert a two-column row into a Haskell pair. Each field in the metadata is paired up with each value from the row, and the two are passed to convert.

instance (Result a, Result b) => QueryResults (a,b) where
    convertResults [fa,fb] [va,vb] = (a,b)
        where !a = convert fa va
              !b = convert fb vb
    convertResults fs vs  = convertError fs vs 2

Notice that this instance evaluates each element to WHNF before constructing the pair. By doing this, we guarantee two important properties:

  • Keep resource usage under control by preventing the construction of potentially long-lived thunks.
  • Ensure that any ResultError that might arise is thrown immediately, rather than some place later in application code that cannot handle it.

You can also declare Haskell types of your own to be instances of QueryResults.

data User = User { firstName :: String, lastName :: String }

instance QueryResults User where
    convertResults [fa,fb] [va,vb] = User $ a * b
        where !a = convert fa va
              !b = convert fb vb
    convertResults fs vs  = convertError fs vs 2
 

Minimal complete definition

convertResults

Instances

(Result a, Result b) => QueryResults (a, b) Source # 

Methods

convertResults :: [ColumnDef] -> [MySQLValue] -> (a, b) Source #

(Result a, Result b, Result c) => QueryResults (a, b, c) Source # 

Methods

convertResults :: [ColumnDef] -> [MySQLValue] -> (a, b, c) Source #

(Result a, Result b, Result c, Result d) => QueryResults (a, b, c, d) Source # 

Methods

convertResults :: [ColumnDef] -> [MySQLValue] -> (a, b, c, d) Source #

(Result a, Result b, Result c, Result d, Result e) => QueryResults (a, b, c, d, e) Source # 

Methods

convertResults :: [ColumnDef] -> [MySQLValue] -> (a, b, c, d, e) Source #

(Result a, Result b, Result c, Result d, Result e, Result f) => QueryResults (a, b, c, d, e, f) Source # 

Methods

convertResults :: [ColumnDef] -> [MySQLValue] -> (a, b, c, d, e, f) Source #

(Result a, Result b, Result c, Result d, Result e, Result f, Result g) => QueryResults (a, b, c, d, e, f, g) Source # 

Methods

convertResults :: [ColumnDef] -> [MySQLValue] -> (a, b, c, d, e, f, g) Source #

(Result a, Result b, Result c, Result d, Result e, Result f, Result g, Result h) => QueryResults (a, b, c, d, e, f, g, h) Source # 

Methods

convertResults :: [ColumnDef] -> [MySQLValue] -> (a, b, c, d, e, f, g, h) Source #

(Result a, Result b, Result c, Result d, Result e, Result f, Result g, Result h, Result i) => QueryResults (a, b, c, d, e, f, g, h, i) Source # 

Methods

convertResults :: [ColumnDef] -> [MySQLValue] -> (a, b, c, d, e, f, g, h, i) Source #

(Result a, Result b, Result c, Result d, Result e, Result f, Result g, Result h, Result i, Result j) => QueryResults (a, b, c, d, e, f, g, h, i, j) Source # 

Methods

convertResults :: [ColumnDef] -> [MySQLValue] -> (a, b, c, d, e, f, g, h, i, j) Source #

(Result a, Result b, Result c, Result d, Result e, Result f, Result g, Result h, Result i, Result j, Result k) => QueryResults (a, b, c, d, e, f, g, h, i, j, k) Source # 

Methods

convertResults :: [ColumnDef] -> [MySQLValue] -> (a, b, c, d, e, f, g, h, i, j, k) Source #

(Result a, Result b, Result c, Result d, Result e, Result f, Result g, Result h, Result i, Result j, Result k, Result l) => QueryResults (a, b, c, d, e, f, g, h, i, j, k, l) Source # 

Methods

convertResults :: [ColumnDef] -> [MySQLValue] -> (a, b, c, d, e, f, g, h, i, j, k, l) Source #

(Result a, Result b, Result c, Result d, Result e, Result f, Result g, Result h, Result i, Result j, Result k, Result l, Result m) => QueryResults (a, b, c, d, e, f, g, h, i, j, k, l, m) Source # 

Methods

convertResults :: [ColumnDef] -> [MySQLValue] -> (a, b, c, d, e, f, g, h, i, j, k, l, m) Source #

(Result a, Result b, Result c, Result d, Result e, Result f, Result g, Result h, Result i, Result j, Result k, Result l, Result m, Result n) => QueryResults (a, b, c, d, e, f, g, h, i, j, k, l, m, n) Source # 

Methods

convertResults :: [ColumnDef] -> [MySQLValue] -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n) Source #

(Result a, Result b, Result c, Result d, Result e, Result f, Result g, Result h, Result i, Result j, Result k, Result l, Result m, Result n, Result o) => QueryResults (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) Source # 

Methods

convertResults :: [ColumnDef] -> [MySQLValue] -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) Source #

(Result a, Result b, Result c, Result d, Result e, Result f, Result g, Result h, Result i, Result j, Result k, Result l, Result m, Result n, Result o, Result p) => QueryResults (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) Source # 

Methods

convertResults :: [ColumnDef] -> [MySQLValue] -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) Source #

(Result a, Result b, Result c, Result d, Result e, Result f, Result g, Result h, Result i, Result j, Result k, Result l, Result m, Result n, Result o, Result p, Result q) => QueryResults (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q) Source # 

Methods

convertResults :: [ColumnDef] -> [MySQLValue] -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q) Source #

(Result a, Result b, Result c, Result d, Result e, Result f, Result g, Result h, Result i, Result j, Result k, Result l, Result m, Result n, Result o, Result p, Result q, Result r) => QueryResults (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r) Source # 

Methods

convertResults :: [ColumnDef] -> [MySQLValue] -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r) Source #

(Result a, Result b, Result c, Result d, Result e, Result f, Result g, Result h, Result i, Result j, Result k, Result l, Result m, Result n, Result o, Result p, Result q, Result r, Result s) => QueryResults (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s) Source # 

Methods

convertResults :: [ColumnDef] -> [MySQLValue] -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s) Source #

(Result a, Result b, Result c, Result d, Result e, Result f, Result g, Result h, Result i, Result j, Result k, Result l, Result m, Result n, Result o, Result p, Result q, Result r, Result s, Result t, Result u, Result v) => QueryResults (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v) Source # 

Methods

convertResults :: [ColumnDef] -> [MySQLValue] -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v) Source #

(Result a, Result b, Result c, Result d, Result e, Result f, Result g, Result h, Result i, Result j, Result k, Result l, Result m, Result n, Result o, Result p, Result q, Result r, Result s, Result t, Result u, Result v, Result w) => QueryResults (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w) Source # 

Methods

convertResults :: [ColumnDef] -> [MySQLValue] -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w) Source #

(Result a, Result b, Result c, Result d, Result e, Result f, Result g, Result h, Result i, Result j, Result k, Result l, Result m, Result n, Result o, Result p, Result q, Result r, Result s, Result t, Result u, Result v, Result w, Result x) => QueryResults (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x) Source # 

Methods

convertResults :: [ColumnDef] -> [MySQLValue] -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x) Source #

convertError Source #

Arguments

:: [ColumnDef]

Descriptors of fields to be converted.

-> [MySQLValue]

Contents of the row to be converted.

-> Int

Number of columns expected for conversion. For instance, if converting to a 3-tuple, the number to provide here would be 3.

-> a 

Throw a ConversionFailed exception, indicating a mismatch between the number of columns in the Field and row, and the number in the collection to be converted to.