feat: add sqlite support to starmelon interpreter
This commit is contained in:
parent
e90a0b62a6
commit
3cf23637d5
7 changed files with 566 additions and 24 deletions
|
|
@ -1,8 +1,11 @@
|
|||
module Astrid.Query
|
||||
exposing
|
||||
( Query
|
||||
, errorToString
|
||||
, execute
|
||||
, fetch
|
||||
, fetchOne
|
||||
, fetchOptional
|
||||
, map
|
||||
, map2
|
||||
, map3
|
||||
|
|
@ -11,12 +14,54 @@ module Astrid.Query
|
|||
)
|
||||
|
||||
import Json.Decode
|
||||
import Json.Encode
|
||||
import Array exposing (Array)
|
||||
|
||||
{-| A value that knows how to load data from a SQL database.
|
||||
-}
|
||||
type Query a = Dummy
|
||||
|
||||
type Error
|
||||
= Execute String String
|
||||
| Decode String Int Json.Decode.Error
|
||||
| Failure String
|
||||
| NotFound String
|
||||
|
||||
errorToString : Error -> String
|
||||
errorToString error =
|
||||
case error of
|
||||
Execute sql message ->
|
||||
"Execute `" ++ sql ++ "` failed `" ++ message ++ "`"
|
||||
|
||||
Decode sql index decodeError ->
|
||||
"Decode results for `" ++ sql ++ "` failed at index `" ++ (String.fromInt index) ++ "` with error " ++ Json.Decode.errorToString(decodeError)
|
||||
|
||||
Failure message ->
|
||||
"Failure `" ++ message ++ "`"
|
||||
|
||||
NotFound sql ->
|
||||
"NotFound `" ++ sql ++ "`"
|
||||
|
||||
execute : Query a -> Result Error a
|
||||
execute query =
|
||||
dummyExecute
|
||||
|
||||
{- Constructing the type inside this helper function will force Elm to generate
|
||||
the javascript of the Query type constructor above the execute function
|
||||
javascript.
|
||||
-}
|
||||
dummyExecute : Result Error a
|
||||
dummyExecute =
|
||||
let
|
||||
query = Dummy
|
||||
_ = Execute "" ""
|
||||
_ = Decode "" 0 (Json.Decode.Failure "" Json.Encode.null)
|
||||
_ = Failure ""
|
||||
_ = NotFound ""
|
||||
in
|
||||
Err (Failure "This package only works inside the starmelon interpreter")
|
||||
|
||||
|
||||
fetch : String -> List String -> Json.Decode.Decoder a -> Query (Array a)
|
||||
fetch sql parameters decoder =
|
||||
Dummy
|
||||
|
|
@ -25,6 +70,10 @@ fetchOne : String -> List String -> Json.Decode.Decoder a -> Query a
|
|||
fetchOne sql parameters decoder =
|
||||
Dummy
|
||||
|
||||
fetchOptional : String -> List String -> Json.Decode.Decoder a -> Query (Maybe a)
|
||||
fetchOptional sql parameters decoder =
|
||||
Dummy
|
||||
|
||||
map : (a -> value) -> Query a -> Query value
|
||||
map f a =
|
||||
Dummy
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue