-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | elm-export persistent entities
--   
--   Ent is a newtype that wraps Persistent Entity's, allowing you to
--   export them to Elm types. Specifically, it adds a To/From JSON
--   instance which adds an id field, as well as an ElmType instance that
--   adds an id field constructor.
@package elm-export-persistent
@version 0.1.2


module Elm.Export.Persist.Ent

-- | <a>Entity</a> wrapper that adds <a>ToJSON</a>, <a>FromJSON</a>, and
--   <a>ElmType</a> instances
--   
--   The first type parameter <tt>field</tt> is a symbol used for the key
--   name
--   
--   <pre>
--   &gt;&gt;&gt; toElmTypeSource (Proxy :: Proxy (Ent "userId" User))
--   "type alias User = { userName : String, userId : Int }"
--   </pre>
newtype Ent (field :: Symbol) a
Ent :: (Entity a) -> Ent a

-- | <a>Ent</a> alias, using "id" as the key
--   
--   <pre>
--   &gt;&gt;&gt; toElmTypeSource (Proxy :: Proxy (EntId User))
--   "type alias User = { userName : String, id : Int }"
--   </pre>
type EntId a = Ent "id" a
instance GHC.Generics.Generic (Elm.Export.Persist.Ent.Ent field a)
instance (GHC.TypeLits.KnownSymbol field, Elm.Type.ElmType a) => Elm.Type.ElmType (Elm.Export.Persist.Ent.Ent field a)
instance (GHC.TypeLits.KnownSymbol field, Data.Aeson.Types.ToJSON.ToJSON a) => Data.Aeson.Types.ToJSON.ToJSON (Elm.Export.Persist.Ent.Ent field a)
instance (Database.Persist.Class.PersistStore.ToBackendKey Database.Persist.Sql.Types.Internal.SqlBackend a, Database.Persist.Class.PersistEntity.PersistEntity a, GHC.TypeLits.KnownSymbol field, Data.Aeson.Types.FromJSON.FromJSON a) => Data.Aeson.Types.FromJSON.FromJSON (Elm.Export.Persist.Ent.Ent field a)


-- | Orphan instances needed for SQL keys
--   
--   This is usually required, but optionally exported in case you have
--   your own already
module Elm.Export.Persist.BackendKey
instance GHC.Generics.Generic (Database.Persist.Class.PersistStore.BackendKey Database.Persist.Sql.Types.Internal.SqlBackend)
instance Elm.Type.ElmType (Database.Persist.Class.PersistStore.BackendKey Database.Persist.Sql.Types.Internal.SqlBackend)


-- | <h2>Usage</h2>
--   
--   
--   <pre>
--   newtype <a>Ent</a> (field :: <tt>Symbol</tt>) a = <a>Ent</a> (<tt>Entity</tt> a)
--     deriving (<tt>Generic</tt>)
--   
--   type <a>EntId</a> a = <a>Ent</a> "id" a
--   </pre>
--   
--   <a>Ent</a> is a newtype that wraps Persistent <tt>Entity</tt>s,
--   allowing you to export them to Elm types. Specifically, it adds a
--   {To,From}JSON instance which adds an <tt>id</tt> field, as well as an
--   <tt><tt>ElmType</tt></tt> instance that adds an <tt>id</tt> field
--   constructor.
--   
--   <h2>Example</h2>
--   
--   
--   Let's define a Persistent model:
--   
--   <pre>
--   {-# LANGUAGE FlexibleInstances #-}
--   {-# LANGUAGE GADTs #-}
--   {-# LANGUAGE GeneralizedNewtypeDeriving #-}
--   {-# LANGUAGE MultiParamTypeClasses #-}
--   {-# LANGUAGE OverloadedStrings #-}
--   {-# LANGUAGE QuasiQuotes #-}
--   {-# LANGUAGE TemplateHaskell #-}
--   {-# LANGUAGE TypeFamilies #-}
--   {-# LANGUAGE DeriveGeneric #-}
--   {-# LANGUAGE StandaloneDeriving #-}
--   
--   module Main where
--   
--   import Data.Aeson
--   import Data.<tt>Text</tt>
--   import Database.Persist.TH
--   import Elm
--   import GHC.Generics
--   
--   import Elm.Export.Persist
--   import Elm.Export.Persist.BackendKey ()
--   
--   share [mkPersist sqlSettings, mkMigrate "migrateAccount"] [persistLowerCase|
--   Account
--     email <tt>Text</tt>
--     password <tt>Text</tt>
--     deriving Show <tt>Generic</tt>
--     UniqueEmail email
--   |]
--   
--   instance <tt>ToJSON</tt> Account
--   instance <tt>FromJSON</tt> Account
--   instance <tt>ElmType</tt> Account
--   
--   -- use GeneralizedNewtypeDeriving for ids
--   -- this picks a simpler int-encoding
--   deriving instance <tt>ElmType</tt> AccountId
--   </pre>
--   
--   Now let's export it with an id field:
--   
--   <pre>
--   module Main where
--   
--   import Db
--   import Elm
--   import Data.Proxy
--   
--   mkSpecBody :: <tt>ElmType</tt> a =&gt; a -&gt; [<tt>Text</tt>]
--   mkSpecBody a =
--     [ toElmTypeSource    a
--     , toElmDecoderSource a
--     , toElmEncoderSource a
--     ]
--   
--   defImports :: [<tt>Text</tt>]
--   defImports =
--     [ "import Json.Decode exposing (..)"
--     , "import Json.Decode.Pipeline exposing (..)"
--     , "import Json.Encode"
--     , "import Http"
--     , "import String"
--     ]
--   
--   accountSpec :: Spec
--   accountSpec =
--     Spec ["Generated", "Account"] $
--          defImports ++ mkSpecBody (<tt>Proxy</tt> :: <tt>Proxy</tt> (<a>EntId</a> Account))
--   
--   main :: IO ()
--   main = specsToDir [accountSpec] "some/where/output"
--   </pre>
--   
--   This generates:
--   
--   <pre>
--   module Generated.Account exposing (..)
--   
--   import Json.Decode exposing (..)
--   import Json.Decode.Pipeline exposing (..)
--   import Json.Encode
--   import Http
--   import String
--   
--   type alias Account =
--       { accountEmail : String
--       , accountPassword : String
--       , id : Int
--       }
--   
--   decodeAccount : Decoder Account
--   decodeAccount =
--       decode Account
--           |&gt; required "accountEmail" string
--           |&gt; required "accountPassword" string
--           |&gt; required "id" int
--   
--   encodeAccount : Account -&gt; Json.Encode.Value
--   encodeAccount x =
--       Json.Encode.object
--           [ ( "accountEmail", Json.Encode.string x.accountEmail )
--           , ( "accountPassword", Json.Encode.string x.accountPassword )
--           , ( "id", Json.Encode.int x.id )
--           ]
--   </pre>
module Elm.Export.Persist
