Last active
June 30, 2020 11:37
-
-
Save dasch/82a7729f6c64cf3bce0efec3530b73b0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Sql | |
import Sql.Param | |
findArticleById : Int -> Result Sql.Error Article | |
findArticleById id = | |
let | |
query = | |
"SELECT articles.id, articles.title, article.body WHERE articles.id = :id LIMIT 1" | |
in | |
Sql.queryWithParams query [ ("id", Sql.Param.int id) ] | |
|> Sql.first |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Sql.Decode exposing (..) | |
type Decoder a = ... | |
column : Decoder a -> String -> Decoder a | |
string : Decoder String | |
integer : Decoder Int | |
float : Decoder Float | |
bool : Decoder Bool |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Sql exposing (..) | |
type Query a = Query | |
{ decoder : Decoder a | |
, encoder : Encoder a | |
, query : String | |
, params : List (String, Param) | |
} | |
execute : Query a -> Result Error a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment