module Database.SQLite.Simple.ToRow
(
ToRow(..)
) where
import Database.SQLite.Simple.ToField (ToField(..))
import Database.SQLite.Simple.Types (Only(..), (:.)(..))
import Database.SQLite3 (SQLData(..))
class ToRow a where
toRow :: a -> [SQLData]
instance ToRow () where
toRow :: () -> [SQLData]
toRow ()
_ = []
instance (ToField a) => ToRow (Only a) where
toRow :: Only a -> [SQLData]
toRow (Only a
v) = [a -> SQLData
forall a. ToField a => a -> SQLData
toField a
v]
instance (ToField a, ToField b) => ToRow (a,b) where
toRow :: (a, b) -> [SQLData]
toRow (a
a,b
b) = [a -> SQLData
forall a. ToField a => a -> SQLData
toField a
a, b -> SQLData
forall a. ToField a => a -> SQLData
toField b
b]
instance (ToField a, ToField b, ToField c) => ToRow (a,b,c) where
toRow :: (a, b, c) -> [SQLData]
toRow (a
a,b
b,c
c) = [a -> SQLData
forall a. ToField a => a -> SQLData
toField a
a, b -> SQLData
forall a. ToField a => a -> SQLData
toField b
b, c -> SQLData
forall a. ToField a => a -> SQLData
toField c
c]
instance (ToField a, ToField b, ToField c, ToField d) => ToRow (a,b,c,d) where
toRow :: (a, b, c, d) -> [SQLData]
toRow (a
a,b
b,c
c,d
d) = [a -> SQLData
forall a. ToField a => a -> SQLData
toField a
a, b -> SQLData
forall a. ToField a => a -> SQLData
toField b
b, c -> SQLData
forall a. ToField a => a -> SQLData
toField c
c, d -> SQLData
forall a. ToField a => a -> SQLData
toField d
d]
instance (ToField a, ToField b, ToField c, ToField d, ToField e)
=> ToRow (a,b,c,d,e) where
toRow :: (a, b, c, d, e) -> [SQLData]
toRow (a
a,b
b,c
c,d
d,e
e) =
[a -> SQLData
forall a. ToField a => a -> SQLData
toField a
a, b -> SQLData
forall a. ToField a => a -> SQLData
toField b
b, c -> SQLData
forall a. ToField a => a -> SQLData
toField c
c, d -> SQLData
forall a. ToField a => a -> SQLData
toField d
d, e -> SQLData
forall a. ToField a => a -> SQLData
toField e
e]
instance (ToField a, ToField b, ToField c, ToField d, ToField e, ToField f)
=> ToRow (a,b,c,d,e,f) where
toRow :: (a, b, c, d, e, f) -> [SQLData]
toRow (a
a,b
b,c
c,d
d,e
e,f
f) =
[a -> SQLData
forall a. ToField a => a -> SQLData
toField a
a, b -> SQLData
forall a. ToField a => a -> SQLData
toField b
b, c -> SQLData
forall a. ToField a => a -> SQLData
toField c
c, d -> SQLData
forall a. ToField a => a -> SQLData
toField d
d, e -> SQLData
forall a. ToField a => a -> SQLData
toField e
e, f -> SQLData
forall a. ToField a => a -> SQLData
toField f
f]
instance (ToField a, ToField b, ToField c, ToField d, ToField e, ToField f,
ToField g)
=> ToRow (a,b,c,d,e,f,g) where
toRow :: (a, b, c, d, e, f, g) -> [SQLData]
toRow (a
a,b
b,c
c,d
d,e
e,f
f,g
g) =
[a -> SQLData
forall a. ToField a => a -> SQLData
toField a
a, b -> SQLData
forall a. ToField a => a -> SQLData
toField b
b, c -> SQLData
forall a. ToField a => a -> SQLData
toField c
c, d -> SQLData
forall a. ToField a => a -> SQLData
toField d
d, e -> SQLData
forall a. ToField a => a -> SQLData
toField e
e, f -> SQLData
forall a. ToField a => a -> SQLData
toField f
f,
g -> SQLData
forall a. ToField a => a -> SQLData
toField g
g]
instance (ToField a, ToField b, ToField c, ToField d, ToField e, ToField f,
ToField g, ToField h)
=> ToRow (a,b,c,d,e,f,g,h) where
toRow :: (a, b, c, d, e, f, g, h) -> [SQLData]
toRow (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h) =
[a -> SQLData
forall a. ToField a => a -> SQLData
toField a
a, b -> SQLData
forall a. ToField a => a -> SQLData
toField b
b, c -> SQLData
forall a. ToField a => a -> SQLData
toField c
c, d -> SQLData
forall a. ToField a => a -> SQLData
toField d
d, e -> SQLData
forall a. ToField a => a -> SQLData
toField e
e, f -> SQLData
forall a. ToField a => a -> SQLData
toField f
f,
g -> SQLData
forall a. ToField a => a -> SQLData
toField g
g, h -> SQLData
forall a. ToField a => a -> SQLData
toField h
h]
instance (ToField a, ToField b, ToField c, ToField d, ToField e, ToField f,
ToField g, ToField h, ToField i)
=> ToRow (a,b,c,d,e,f,g,h,i) where
toRow :: (a, b, c, d, e, f, g, h, i) -> [SQLData]
toRow (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i) =
[a -> SQLData
forall a. ToField a => a -> SQLData
toField a
a, b -> SQLData
forall a. ToField a => a -> SQLData
toField b
b, c -> SQLData
forall a. ToField a => a -> SQLData
toField c
c, d -> SQLData
forall a. ToField a => a -> SQLData
toField d
d, e -> SQLData
forall a. ToField a => a -> SQLData
toField e
e, f -> SQLData
forall a. ToField a => a -> SQLData
toField f
f,
g -> SQLData
forall a. ToField a => a -> SQLData
toField g
g, h -> SQLData
forall a. ToField a => a -> SQLData
toField h
h, i -> SQLData
forall a. ToField a => a -> SQLData
toField i
i]
instance (ToField a, ToField b, ToField c, ToField d, ToField e, ToField f,
ToField g, ToField h, ToField i, ToField j)
=> ToRow (a,b,c,d,e,f,g,h,i,j) where
toRow :: (a, b, c, d, e, f, g, h, i, j) -> [SQLData]
toRow (a
a,b
b,c
c,d
d,e
e,f
f,g
g,h
h,i
i,j
j) =
[a -> SQLData
forall a. ToField a => a -> SQLData
toField a
a, b -> SQLData
forall a. ToField a => a -> SQLData
toField b
b, c -> SQLData
forall a. ToField a => a -> SQLData
toField c
c, d -> SQLData
forall a. ToField a => a -> SQLData
toField d
d, e -> SQLData
forall a. ToField a => a -> SQLData
toField e
e, f -> SQLData
forall a. ToField a => a -> SQLData
toField f
f,
g -> SQLData
forall a. ToField a => a -> SQLData
toField g
g, h -> SQLData
forall a. ToField a => a -> SQLData
toField h
h, i -> SQLData
forall a. ToField a => a -> SQLData
toField i
i, j -> SQLData
forall a. ToField a => a -> SQLData
toField j
j]
instance (ToField a) => ToRow [a] where
toRow :: [a] -> [SQLData]
toRow = (a -> SQLData) -> [a] -> [SQLData]
forall a b. (a -> b) -> [a] -> [b]
map a -> SQLData
forall a. ToField a => a -> SQLData
toField
instance (ToRow a, ToRow b) => ToRow (a :. b) where
toRow :: (a :. b) -> [SQLData]
toRow (a
a :. b
b) = a -> [SQLData]
forall a. ToRow a => a -> [SQLData]
toRow a
a [SQLData] -> [SQLData] -> [SQLData]
forall a. [a] -> [a] -> [a]
++ b -> [SQLData]
forall a. ToRow a => a -> [SQLData]
toRow b
b