Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there anything for generic CRUD in clojure / clojurescript forms

Tags:

clojure

crud

So, ideally, in my mind, based on a single schema definition, I should be able to fully generate complete Create Read Update Delete (CRUD) in a web-context, that is:

  • client: An interactive HTML data table component for the operations, maybe with inline editing etc.
  • client: a form component for editing a single record, including validation as deduced from the schema
  • server: A route to access the data for populating and updating said components (REST endpoint)
  • server: An implementation for persisting the data in, say, an SQL table.

So ideally; i'd just define a schema for, say, a Person datatype with name and surname and address fields, and then call a macro or function like (defcrud Person my-person-schema) and it works, i can go to a webpage, see the datatable, edit/delete data, and save the data all the way to the server.

My question is: is there anything in the clojure world that does something (or partially) as described above?

In my recent first full clj/cljs project, I found myself writing a lot of code for this basic stuff. In the olden days, when I used a GWT framework called SmartGWT, I just had to define a new ListGrid(myDataSource), and define a datasource (equivalent to the schema), and the rest was inferred (at least something with sensible defaults was).

The SmartGWT kind of high level of development is what enables true rapid prototyping for the kind of business apps I need to build quite often. GWT has its own drawbacks, like very slow compilation time for bigger apps, and the fact that I have to write Java, but it's the level of server-client integration out-of-the-box that I'm looking for in Clojure.

like image 217
Marten Sytema Avatar asked Apr 18 '16 13:04

Marten Sytema


2 Answers

Disclaimer, I am the author of closp-crud.

First, thanks @mac for hinting to my library.

Second, what you are asking for is exactly what I want to achieve, but in a different way. I hate all the magic that happens when you do stuff like inferring code. So my approach is different in that all the code:

  • html templates
  • routes
  • migrations
  • db access

is generated and can be fully changed afterwards.
Of course this has other disadvantages, but I will happily take them.

That said, documentation is still lacking, I started an incentive with: http://closp.net last week and will keep on working on it.
I might as well add docs for closp-crud next, if you need so.

Apart from that I made an introductionary video two days ago: https://www.livecoding.tv/sveri/videos/wrnL1-clojure-closp-webframework-41 which shows the usage of closp and closp-crud in a very basic way.
Usage of closp-crud starts round about 12 minutes.

like image 131
sveri Avatar answered Nov 15 '22 21:11

sveri


There is closp and closp-crud. That will take you part of the way.

like image 32
mac Avatar answered Nov 15 '22 21:11

mac