feat: add map2, map3, andThen to Astrid.Query
This commit is contained in:
parent
3cf23637d5
commit
b6182376b6
12 changed files with 1202 additions and 1018 deletions
26
examples/sqlite-integration/elm.json
Normal file
26
examples/sqlite-integration/elm.json
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"type": "application",
|
||||
"source-directories": [
|
||||
"src",
|
||||
"../../lib/sql/src"
|
||||
],
|
||||
"elm-version": "0.19.1",
|
||||
"dependencies": {
|
||||
"direct": {
|
||||
"elm/browser": "1.0.2",
|
||||
"elm/core": "1.0.5",
|
||||
"elm/html": "1.0.0",
|
||||
"elm/json": "1.1.3",
|
||||
"elm-community/array-extra": "2.4.0"
|
||||
},
|
||||
"indirect": {
|
||||
"elm/time": "1.0.0",
|
||||
"elm/url": "1.0.0",
|
||||
"elm/virtual-dom": "1.0.2"
|
||||
}
|
||||
},
|
||||
"test-dependencies": {
|
||||
"direct": {},
|
||||
"indirect": {}
|
||||
}
|
||||
}
|
||||
BIN
examples/sqlite-integration/example.sqlite
Normal file
BIN
examples/sqlite-integration/example.sqlite
Normal file
Binary file not shown.
47
examples/sqlite-integration/src/CombinatorsTest.elm
Normal file
47
examples/sqlite-integration/src/CombinatorsTest.elm
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
module CombinatorsTest exposing (main)
|
||||
|
||||
import Astrid.Query exposing (fetch, execute, errorToString, map3, fetchOne, andThen)
|
||||
import Json.Decode
|
||||
import Html exposing (Html, ul, li, text, code, node, div)
|
||||
import Array.Extra
|
||||
|
||||
main : Html msg
|
||||
main =
|
||||
let
|
||||
query =
|
||||
map3
|
||||
(\one two three ->
|
||||
one ++ " " ++ two ++ " " ++ three
|
||||
)
|
||||
(fetchOne "select json_quote('a')" [] Json.Decode.string)
|
||||
{-
|
||||
(andThen
|
||||
(\right ->
|
||||
map
|
||||
(\v ->
|
||||
"andThen( " ++ v ++ ""
|
||||
)
|
||||
(andThen
|
||||
(\left ->
|
||||
succeed "andThen"
|
||||
)
|
||||
)
|
||||
)
|
||||
(fetchOne "select json_quote('b')" [] Json.Decode.string)
|
||||
)
|
||||
-}
|
||||
(fetchOne "select json_quote('b')" [] Json.Decode.string)
|
||||
(fetchOne "select json_quote('c')" [] Json.Decode.string)
|
||||
in
|
||||
case execute query of
|
||||
Ok result ->
|
||||
div []
|
||||
[ node "style" []
|
||||
[ text "code { background-color: #f6f7f9; display: block; padding: 1em; border-radius: 4px; border 1px solid #eee; } "
|
||||
]
|
||||
, code []
|
||||
[ text result ]
|
||||
]
|
||||
|
||||
Err error ->
|
||||
Html.text (errorToString error)
|
||||
48
examples/sqlite-integration/src/ShowDatabaseSchema.elm
Normal file
48
examples/sqlite-integration/src/ShowDatabaseSchema.elm
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
module ShowDatabaseSchema exposing (main)
|
||||
|
||||
import Astrid.Query exposing (fetch, execute, errorToString)
|
||||
import Json.Decode
|
||||
import Html exposing (Html, ul, li, text, code, node, div)
|
||||
import Array.Extra
|
||||
|
||||
|
||||
main : Html msg
|
||||
main =
|
||||
let
|
||||
query =
|
||||
fetch
|
||||
"select json_object('type', type, 'name', name, 'sql', sql) from sqlite_master WHERE type = 'table'"
|
||||
[]
|
||||
(Json.Decode.map3
|
||||
(\kind name sql->
|
||||
(kind, name, sql)
|
||||
)
|
||||
(Json.Decode.field "type" Json.Decode.string)
|
||||
(Json.Decode.field "name" Json.Decode.string)
|
||||
(Json.Decode.field "sql" Json.Decode.string)
|
||||
)
|
||||
in
|
||||
case execute query of
|
||||
Ok results ->
|
||||
div []
|
||||
[ node "style" []
|
||||
[ text "code { background-color: #f6f7f9; display: block; padding: 1em; border-radius: 4px; border 1px solid #eee; } "
|
||||
]
|
||||
, ul []
|
||||
(Array.Extra.mapToList
|
||||
(\(kind, name, sql) ->
|
||||
li []
|
||||
[ text "type = "
|
||||
, text kind
|
||||
, text ", name ="
|
||||
, text name
|
||||
, code []
|
||||
[ text sql]
|
||||
]
|
||||
)
|
||||
results
|
||||
)
|
||||
]
|
||||
|
||||
Err error ->
|
||||
Html.text (errorToString error)
|
||||
Loading…
Add table
Add a link
Reference in a new issue