8 ms·
Clojure looks productive. What frameworks libraries do people use to build web apps? Like, replacement for Django view layer and ORM (not looking to debate orms
by winrid 2y ago
Clojure looks productive. What frameworks libraries do people use to build web apps? Like, replacement for Django view layer and ORM (not looking to debate orms thanks)?
- whalesalad 2y agoThere is not a batteries included framework a-la Django or Rails for Clojure. I would argue that is one of the biggest pitfalls to the language/ecosystem. If you are building a web application, you will need to invent the entire thing yourself. There are micro frameworks and tools that exist standalone to deal with HTTP, DB ORM, etc... but that will be an exercise left to the reader. Some will say this is a good thing (and as a very experienced engineer I will agree) but the barrier to entry for a newbie is quite high in this regard. You have all the rope to hang yourself with - and you will. Especially if you are on a team full of lots of interns and junior folks.
- jiriknesl 2y agoThe closest to this (MVC framework with all features including migrations, API building, auth...) is Xiana https://github.com/Flexiana/framework/ https://github.com/Flexiana/framework/
- whalesalad 2y agoThis framework looks like an absolute nightmare to use.
- neilyio 2y agoCheck out Biff, it's very thoughtfully made: https://biffweb.com https://biffweb.com
- anentropic 2y agoIt's kind of surprising the most popular(?) web framework uses a weird/obscure db I have no doubt that XTDB is good, it is just surprising as a first choice and is not going to be easy to get up and running compared to the conventional alternatives (Is there even a hosted offering for XTDB? I like that it's open source but seems that you will have to grapple with all this stuff including a Kafka cluster https://docs.xtdb.com/guides/starting-with-aws.html https://docs.xtdb.com/guides/starting-with-aws.html)
- rads 2y agoThis is a good starting point if you want to get a web app going quickly: https://biffweb.com https://biffweb.com It uses XTDB by default but you can switch to Postgres: https://biffweb.com/p/how-to-use-postgres-with-biff/ https://biffweb.com/p/how-to-use-postgres-with-biff/ People don't really use ORMs in Clojure, they just write SQL directly and abstract the details from consumers using functions. That said, HoneySQL is a common alternative to writing SQL that makes it a lot less painful (and composable!): https://github.com/seancorfield/honeysql https://github.com/seancorfield/honeysql
- neilyio 2y agoHoneySQL is so, so good. It does for SQL what Hiccup did for HTML. Once you start writing with those, it's hard to remember there's any other way.
- zerg000000 2y agoTotally agree! or datalog is even better if you can accept not using the mainstream databases.
- winrid 2y agoBiff looks neat, thanks! I mainly just don't want to write raw sql/mappers to structures for simple queries. Looks like most sql libraries with clojure can just return maps so that's neat.
- rads 2y agoHere's a quick example of how DB access generally looks in production: (ns rads.sql-example (:require [next.jdbc :as jdbc] [honey.sql :as sql] [clojure.string :as str])) ;; DB Table: posts ;; +----+-------+ ;; | id | title | ;; +----+-------+ ;; | 1 | hello | ;; +----+-------+ (def ds (jdbc/get-datasource (System/getenv "DATABASE_URL"))) (defn row->post [row] ;; This is your optional mapping layer (a plain function that takes a map). ;; You can hide DB details here. (update row :title str/capitalize)) (defn get-posts [ds] ;; Write a SQL query using Clojure data structures. (let [query {:select [:*] :from [:posts]}] ;; Run the query. (->> (jdbc/execute! ds (sql/format query)) ;; Convert each raw DB map to a "post" map (map row->post)))) (println (get-posts ds)) ;; => [{:id 1, :title "Hello"}]
- robto 2y agoThis is my goto: webserver: ring-jetty9-adapter[0] routing: reitit[1] html templates: hiccup[2] never used an ORM, but happily used HugSQL for making composable queries[3]. [0]https://github.com/sunng87/ring-jetty9-adapter https://github.com/sunng87/ring-jetty9-adapter [1]https://github.com/metosin/reitit https://github.com/metosin/reitit [2]https://github.com/weavejester/hiccup https://github.com/weavejester/hiccup [3]https://www.hugsql.org/ https://www.hugsql.org/
- winrid 2y agoThose all look great, including HugSQL, thanks!