Json to Elm/Elm-UI

I am considering starting researching an analytics application in Elm. This will require talking to SQL databases as a bare minimum. Now, I want to do be able to create dynamically many elm-ui elements on top of various queries.

I was thinking that managing 1 json tree on the server (which includes also the query results) and then passing that to Elm via websockets might work, but I wanted to hear some feedback on this idea. If you think it could be done differently or that it’s not a good idea at all please let me know.

The process would be:

  • The user composes a query in Elm
  • Elm sends the user input to the server (via websocket?)
  • The server parses the input, queries the database and puts the output into a json
  • Elm gets the updated json via subscription
  • Elm dynamically creates, destroys or updates elm-ui elements

The json would persist alongside the Elm app so that eventually all state is persisted there and state is the same on both server and Elm.

Is this a bad idea?

If restricting to PostgreSQL is acceptable and you want to support any unknown database schema, it looks like it could be a good use case for postgrest (which is written in haskell by the way). You would need a layer on top for subscriptions though.

If the schema is known, graphql could be better, using elm-graphql.

I’m not sure about the persistence part, data could be huge, and synchronization hell.

Further to dmy’s comments, for Postgres there is also postgraphile, which you can query with elm-graphql.

2 Likes

Thanks. I have reviewed few of those solutions but came up with roadblocks. Just to be a bit more clear, here is part of the solution I am trying to build:

This is a tool to compose SQL queries that will run into various databases (Exasol, Redshift, Etc.) and then produce an output. The output is materialized into a new table within the db so in theory data does not have to go to the client, but eventually some data will if the client is going to do some more interesting things than just ETL (like charts for instance).

So I don’t have a predefined schema and I don’t have a predefined database. The sync part will be an issue but I was thinking it might be easier if we make communication between client/server super simple by having 1 direction for input (elm to server) and 1 direction for rendering (server json to elm).

Ideally we do most of the computation in the server and just light computation on the client, so the data going to the client could be of somewhat small-ish size. Depending on how much we can do on the server and how much we want to cache on the client.

Maybe what you want is RethinkDB.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.