Closed gedw99 closed 8 months ago
The plan for data persistence support in Clace is two fold. First (managed) is a built-in solution and second (external) uses plugins for accessing external databases. The external approach will mean plugins for any database, exposing the database native api (like SQL), but the tables/collections have to be managed externally by the user. Clace plugins just provide the API to Starlark to work with the external storage.
The first (managed) solution involves Clace managing the storage abstraction, automatically creating the tables and providing the migration required as schema evolves. The plan is to implement this solution first. The second external solution will come after the support for external plugin loading is added.
The goals for the managed persistence solution are:
The current design to achieve these goals is:
The end user interface should be simple. An app create
call on an app which used the managed persistence plugin should automatically create the tables in sqlite (default), no additional work should be required.
The current status is the schema loading support was added few days back https://github.com/claceio/clace/commit/693fd626d300db161e71a0f335d526799696d8cb. The next release 0.4 will have the full managed sqlite support in a few weeks.
The goal of Clace is to prove a complete solution for building hypermedia based web applications, backend and UI. The storage API will be exposed as a Starlark call for use in the backend Starlark application code. There is no plan to automatically create JSON REST API's for use from external applications. The starlark code is the only client. That code can implement a JSON api if desired (though Hypermedia clients expose HTML apis generally). In that way, Clace is different from Firebase and Pocketbase type backend as a service solutions, which prove storage and automatically expose JSON REST API's.
Would appreciate any inputs on the proposed solution.
It sounds really good.
JSON storage aspects are not clear yet.
Will the DB have a Web GUI that is HTMX driven, so that users can interact with the DB in some way ?
Apps can share a storage, app A can be configured to use same storage as app B. The type information will be automatically loaded. This feature will be used to allow admin apps to show the storage details for any app. I am not sure about the timeline for the admin app currently.
@gedw99 Basic functionality for sqlite support is working. See https://github.com/claceio/apps/blob/main/utils/bookmarks for a sample app.
The workflow is
doc.bookmark
to create a new document of bookmark type, table.bookmark
to use the store apis to work with the table. See https://github.com/claceio/apps/blob/d83c59601f01d145ec0534bdf1c802e1f508071b/utils/bookmarks/app.star#L21Transaction support is still in progress. https://github.com/claceio/clace/blob/main/internal/app/tests/store_test.go has more tests. The query syntax is like mongo, which has the advantage of not having to worry about sql injection. Some complex queries are in https://github.com/claceio/clace/blob/e89d74c74eb48f9cb9f0d3d9cfc76c483c1b724d/internal/app/store/parse_query_test.go#L57
Please let me know any feedback
Added transaction functionality for store plugin, docs are at https://clace.io/docs/plugins/store/
Hey @akclace
Can we call the Sqlite DB to connect them to the htmx layer ?
I use Pocketbase for htmx apps in golang at the moment. https://github.com/pocketbase/pocketbase