2022-01-07 20:00:05 +00:00
|
|
|
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
|
2024-04-17 17:18:04 -07:00
|
|
|
"select type, name, sql from sqlite_master WHERE type = 'table'"
|
2022-01-07 20:00:05 +00:00
|
|
|
[]
|
|
|
|
|
(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)
|