How do you handle state in Roc? For instance with the basic-web server platform, let's say that I have an in memory counter that I wanna increase on every request? Is there a way to do that from Roc?
basic-webserver doesn't currently support that feature, but in general it's possible for a platform to offer that!
I am using sqlite3 for that. Works great with basic-webserver
The todos app shows a basic use case. But yeah definitely not as nice as having something all in memory
@Richard Feldman is there an interim design I could implement which works like Stored ability and keeps things in memory for webserver? I would love to have a cache or something similar.
it wouldn't quite be like Stored
, but you could use the equivalent of Model
here to let the application specify a particular type that the platform knows about
and then the platform can have the Response
include that as a type parameter
this wouldn't be nearly as ergonomic as Stored
, which is one reason basic-webserver doesn't do it :big_smile:
Would be sweet to have sqlite builtin to the platform instead of shelling out to a child process like that. Not sure that version is resistant to todos named ');DROP TABLE todos; --
either, but I can be missing something :)
Your not missing anything, that's a simple example to show something using webserver. I would love to add sqlite effects for that platform, but not sure if we should be coupled so closely to a single db? I think sqlite3 is probable an exception given it is so common. Other db's will probably interface using tcp/ip while sqlite3 is a library.
Yeah, sqlite is one of the example pain points of a popular c library that has no good way to interact with roc through a generic interface like tcp
Instead needs custom platform support
Could maybe load it with libffi, but would be a pain and probably not worth doing
Last updated: Jul 06 2025 at 12:14 UTC