Anyone tried SurrealDB? I just tried it and find a lot of things reminding me of elm.
New and radical ideas. Simple and super performant with a small footprint.
It is made by two dedicated brilliant brothers, not a company.
The main goal is to be able to develop applications with no API or backends, you just need the database and a frontend.
It is like Firebase, but with a better database, better access control and can run on an embedded device or scale up to large clusters. I think it is just a few MB self contained thing. Written in Rust
And can also run inside the browser itself if you want offline support (wasm)
It takes the best from SQL, Document and graph databases. Has native json support so you can easily work with arrays and structured objects. You can choose to use schema or not. Or only schema for some tables. As it is a database made for webapps its primary interface is HTTP and websockets, both a perfect fit for elm. The database can even hold javascript functions to have calculated fields and rules. (maybe we someday could compile those from elm functions?)
They say they have been using it in production themself for several years, but it is released to the public only the last couple of months.
It’s geting raving reviews by anyone that has looked at it.
Here is the Fireship “SurrealDB in 100 seconds”:
The website also looks amazing:
Just wanted to share this with others looking for a nice elm backend
@Atlewee From your description I first though it was yet another Firebase alternative, but SurrealDB, as it name says, is simply a database without authentication or hosting or serverless functions. So it could merely replace Firebase Firestore or Firebase Realtime DB, except that it is a SQL database. And without Firebase offline capabilities.
Yes you are correct, I was thinking of the Firebase realtime database. Not the whole firebase solution
But it also seems to have built in user account management / signup and stuff + functions that can run on triggers inside the database. So sort of cloud-functions capabilities as well.
And you can write your own js/wasm traversing functions so it happens inside the database instead of sending data to the client before the next step in treaversal.
I would not call surreal an SQL database… It seems to be mostly a json document database but with additional graph and SQL features + schema possibilities.
As for offline, they are definetly aiming for offline first webapps. That’s the whole reason why SurrealDB is designed to run embedded in the browser, as well as in a server environment.
I’m currently checking it out but the documentation has a lot of Lorem Ipsums… @Atlewee Did you find good docs to get you started on auth and Websockets connections? Or a gist of using it with Elm? Thanks!
Websocket looks simple. Connect unauthenticated and run the signin command passing username,password or a Token.
All websocket commands is a json object like this:
{
"id": <an id so you can identify responses later on>,
"method": <one of the available commands>,
"params": <an array of parameters>
}
So the websocket message to select a namespace and database would look like this in elm:
Seeing your name, I now see that my title is incorrect. Should be something like. “If for any reason you cant use lamdera yet, would SurrealDB be the next best thing for elm-apps?”
I guess nothing beats the lamdera experience when it fits your requirements.
Great question, I have not looked into migrations yet. ( I just discovered surrealDB 6days ago )
Found a discussion on discord about migrations:
So no tools for migrations yet. But I guess one could turn of schema for the effected tables, change data and turn on new schema? But not sure if that is possible in a single transaction, have not tried.
Or map the complete db or tables over to a new db/table with transform functions, immutable style.
Talking about immutability:
I forgot to mention one of the biggest difference to other databases: SurrealDB is immutable. It is meant to tell you how a single field in a table has changed over time in a performant way and with compact storage of changes.
For those interested I found this really interesting whitepaper written by one of the authors comparing performant immutable database structures: (it is more or less describing design decisions and how the previous version worked under the hood, it had a different name then and was written in go. They have later found even more performant structures and changed to rust + renamed to surrealDB after that)
I’m blown away how convincingly it’s presented as a production ready system with no data migration concepts at first I thought maybe you were expected to make new tables but their foreign key system is effectively hardcoded to a table name if I’m understanding correctly.
That’s my understanding as well. Especially knowing how well you handle Evergreen migrations in Lamdera, it’s a bit harrowing to build a production app with no migration tooling at all…
I’ve been using it for a few days now and I’m thoroughly enjoying the parts that just work. I think I’ll stick with it for this project, have a few makeshift scripts to test database health, and hope they come up with the rename field before I need it