{"id":16560941,"url":"https://github.com/jb55/elm-export-persistent","last_synced_at":"2025-09-23T20:05:32.649Z","repository":{"id":62435897,"uuid":"76308866","full_name":"jb55/elm-export-persistent","owner":"jb55","description":"Export Persistent Entities to Elm types","archived":false,"fork":false,"pushed_at":"2021-01-09T17:11:33.000Z","size":20,"stargazers_count":6,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-09-09T11:48:21.087Z","etag":null,"topics":["elm-export","persistent"],"latest_commit_sha":null,"homepage":null,"language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jb55.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-13T00:52:19.000Z","updated_at":"2021-01-09T17:11:36.000Z","dependencies_parsed_at":"2022-11-01T20:46:08.030Z","dependency_job_id":null,"html_url":"https://github.com/jb55/elm-export-persistent","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/jb55/elm-export-persistent","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jb55%2Felm-export-persistent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jb55%2Felm-export-persistent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jb55%2Felm-export-persistent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jb55%2Felm-export-persistent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jb55","download_url":"https://codeload.github.com/jb55/elm-export-persistent/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jb55%2Felm-export-persistent/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276639739,"owners_count":25678179,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-23T02:00:09.130Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elm-export","persistent"],"created_at":"2024-10-11T20:30:44.698Z","updated_at":"2025-09-23T20:05:32.611Z","avatar_url":"https://github.com/jb55.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# elm-export-persistent\n\n[![Build Status](https://travis-ci.org/jb55/elm-export-persistent.svg)](https://travis-ci.org/jb55/elm-export-persistent)\n\n[elm-export](https://hackage.haskell.org/package/elm-export) helpers for\nPersistent Entities.\n\n## Usage\n\n```hs\nnewtype Ent (field :: Symbol) a = Ent (Entity a)\n  deriving (Generic)\n\ntype EntId a = Ent \"id\" a\n```\n\nEnt is a newtype that wraps Persistent Entity's, allowing you to export them to\nElm types. Specifically, it adds a {To,From}JSON instance which adds an `id`\nfield, as well as an `ElmType` instance that adds an `id` field constructor.\n\n## Example\n\nLet's define a Persistent model:\n\n```hs\n{-# LANGUAGE FlexibleInstances #-}\n{-# LANGUAGE GADTs #-}\n{-# LANGUAGE GeneralizedNewtypeDeriving #-}\n{-# LANGUAGE MultiParamTypeClasses #-}\n{-# LANGUAGE OverloadedStrings #-}\n{-# LANGUAGE QuasiQuotes #-}\n{-# LANGUAGE TemplateHaskell #-}\n{-# LANGUAGE TypeFamilies #-}\n{-# LANGUAGE DeriveGeneric #-}\n{-# LANGUAGE StandaloneDeriving #-}\n\nmodule Main where\n\nimport Data.Aeson\nimport Data.Text\nimport Database.Persist.TH\nimport Elm\nimport GHC.Generics\n\nimport Elm.Export.Persist\nimport Elm.Export.Persist.BackendKey ()\n\nshare [mkPersist sqlSettings, mkMigrate \"migrateAccount\"] [persistLowerCase|\nAccount\n  email Text\n  password Text\n  deriving Show Generic\n  UniqueEmail email\n|]\n\ninstance ToJSON Account\ninstance FromJSON Account\ninstance ElmType Account\n\n-- use GeneralizedNewtypeDeriving for ids\n-- this picks a simpler int-encoding\nderiving instance ElmType AccountId \n```\n\nNow let's export it with an id field:\n\n```hs\nmodule Main where\n\nimport Db\nimport Elm\nimport Data.Proxy\n\nmkSpecBody :: ElmType a =\u003e a -\u003e [Text]\nmkSpecBody a =\n  [ toElmTypeSource    a\n  , toElmDecoderSource a\n  , toElmEncoderSource a\n  ]\n  \ndefImports :: [Text]\ndefImports =\n  [ \"import Json.Decode exposing (..)\"\n  , \"import Json.Decode.Pipeline exposing (..)\"\n  , \"import Json.Encode\"\n  , \"import Http\"\n  , \"import String\"\n  ]\n\naccountSpec :: Spec\naccountSpec = \n  Spec [\"Generated\", \"Account\"] $\n       defImports ++ mkSpecBody (Proxy :: Proxy (EntId Account))\n\nmain :: IO ()\nmain = specsToDir [accountSpec] \"some/where/output\"\n```\n\nThis generates:\n\n```elm\nmodule Generated.Account exposing (..)\n\nimport Json.Decode exposing (..)\nimport Json.Decode.Pipeline exposing (..)\nimport Json.Encode\nimport Http\nimport String\n\ntype alias Account =\n    { accountEmail : String\n    , accountPassword : String\n    , id : Int\n    }\n\ndecodeAccount : Decoder Account\ndecodeAccount =\n    decode Account\n        |\u003e required \"accountEmail\" string\n        |\u003e required \"accountPassword\" string\n        |\u003e required \"id\" int\n\nencodeAccount : Account -\u003e Json.Encode.Value\nencodeAccount x =\n    Json.Encode.object\n        [ ( \"accountEmail\", Json.Encode.string x.accountEmail )\n        , ( \"accountPassword\", Json.Encode.string x.accountPassword )\n        , ( \"id\", Json.Encode.int x.id )\n        ]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjb55%2Felm-export-persistent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjb55%2Felm-export-persistent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjb55%2Felm-export-persistent/lists"}