abadi199 / Elm Horizon
Programming Languages
elm-horizon
DISCLAIMER: This is a work in progress, not ready for production yet. Contribution and PR are welcome! 🙂
Thin wrapper around Horizon JavaScript client API for writing Horizon application in Elm.
Collection API
Write Operation
insertCmd/replaceCmd/storeCmd/updateCmd/upsertCmd/removeAllCmd
*Cmd -> String -> List Json.Value -> Cmd msg
Insert / replace / store / update / upsert / remove one or more new documents into a Collection.
Parameters:
-
collectionName
is the name of the Horizon collection -
values
is List of encoded Json.Value you want to insert / replace / store / update / upsert / remove to the collection.
Example:
insertCmd "chat_messages" [ chatMessageEncoder { id = 1, from = "elm", message = "Hello World!" } ]
removeAllCmd "chat_messages" <| List.map Json.Encode.int [ 1, 2, 3 ]
removeCmd
removeCmd -> String -> Json.Value -> Cmd msg
Parameters:
-
collectionName
is the name of the Horizon collection -
value
is the encoded Json.Value of the id/record of the data you want to delete.
Example:
removeCmd "chat_messages" <| Json.Encode.int 1
insertSub/replaceSub/storeSub/updateSub/upsertSub/removeAllSub/removeSub
*Sub -> (Result Error () -> msg) -> Sub msg
Subscription for the result of Insert / replace / store / update / upsert / remove operation.
Parameters:
-
tagger
is the constructor for your msg that requires aResult
Example:
type Msg = InsertResponse (Result Error ())
subscriptions = insertSub InsertResponse
Read Operations
fetchCmd/watchCmd
*Cmd -> String -> List Modifier -> Cmd msg
Parameters:
-
collectionName
is the name of the Horizon collection -
modifiers
is the List of Modifier
Example:
watchCmd "chat_messages" [ Limit 10, Order "name" Ascending ]
fetchSub/watchSub
*Sub -> Decoder a -> (Result Error (List (Maybe a)) -> msg) -> Sub msg
Parameters:
-
decoder
is the decoder for decoding the data -
tagger
is msg constructor for tagging the decoded data
Example:
type Msg = NewMessageMsg (Result Error (List (Maybe ChatMessage)))
subscriptions = watchSub NewMessageMsg
Modifiers
Above Json.Value
Restrict the range of results returned to values that sort above a given value.
Example:
Above <| encoder { price = 100.0 }
Below Json.Value
Restrict the range of results returned to values that sort below a given value.
Example:
Below <| encoder { value = 20 }
Find Json.Value
Retrieve a single document from a Collection.
Example:
Find <| encoder { id = 1 }
FindAll (List Json.Value)
Retrieve multiple documents from a Collection.
Example:
FindAll [ encoder { id = 1 }, encoder { id = 2 }]
Limit Int
Example:
Limit 10
Order String Direction
where Direction
can be:
Ascending
Descending
Example:
Order "timestamp" Ascending
Examples:
To build and run the example, clone the repo, and then from the root folder of the repo, run this command:
$ npm install
$ npm start
and then open http://localhost:8000 from your browser to open the chat app, or http://localhost:8000/search.html to open the search app.
Make sure you have Horizon and RthinkDB installed on your machine. See http://horizon.io/install/ for installation instruction.
Authentication
TBA
Users & Groups
TBA
Permissions
TBA