Fork me on GitHub
#biff
<
2022-08-04
>
macrobartfast01:08:29

Where can one find the value for db to supply to

(biff/q db
        '{:find email
          :where [[user :user/email email]]})
for repl based xtdb interaction? Is it in @com.biffweb/system? I’m trying to interact with the database from the repl in a running app, but I may be off base in my approach.

Jacob O'Bryant01:08:06

you're thinking about it the right way. take a look at get-sys in the repl.clj file.

Jacob O'Bryant01:08:33

the XT node is stored at (:biff.xtdb/node @com.biffweb/system) so you can pass that to (xtdb.api/db node) to get the db. There's a helper fn com.biffweb/assoc-db which will take your system map and then assoc a db value onto :biff/db

Jacob O'Bryant01:08:56

so i.e. I do repl interaction like this:

(defn get-sys []
  (biff/assoc-db @biff/system))

(comment
 (let [{:keys [biff/db] :as sys} (get-sys)]
   (q db
      '{...})))
(by evaluating the let form)

macrobartfast01:08:13

Aha… I was getting the node from @com.biffweb/systemand trying to use that as the db; I was missing a step.

🎅 1
macrobartfast01:08:49

Nice! Worked. All set now.👍

Jeff03:08:08

New lisper here. For a solo dev trying to choose between fulcro and biff. Any advice you’d offer to them to help make the right choice?

Jacob O'Bryant04:08:35

In a nutshell I'd say Biff is better for small projects and Fulcro is better for large projects. Biff is pretty lightweight. It mostly just ties together a bunch of libraries for you. Fulcro on the other hand has its own set of abstractions you need to learn in order to become productive with it. I tried using Fulcro for 6 weeks at the end of 2019 and never really figured it out, despite hours of reading the docs and source code. That was part of the impetus for making Biff a few months later--I wanted something optimized for the solo dev use-case. So for your case, if you're mainly interested in just getting productive quickly, I'd recommend Biff. But if you're interested in expanding your horizons and don't mind spending more time in the learning phase, then Fulcro could be good.

Jacob O'Bryant04:08:59

If you haven't already seen it, https://kit-clj.github.io/ is another good contender. It's relatively new but it's the successor to https://luminusweb.com/ which has been around for a long time. I haven't used Kit (or Luminus) but my understanding is that it tries to be more modular than Biff. Kit provides tools for mixing and matching different libraries whereas Biff basically says "here, just use X, Y and Z" (although if you do end up wanting to do things a different way, Biff is designed so you can take it apart without too much trouble). I'd still recommend Biff myself, but of course I'm biased 😉

Jacob O'Bryant04:08:08

also for context on this: > Biff is better for small projects The https://thesample.ai/ I've built with Biff is about 20k lines of code, so I'm confident in saying Biff can handle a project of at least that size.

Jeff05:08:30

I see. What do you think of perfomance of biff? Also, if am also interested in learning ins and outs of web dev, is biff still a good choice?

Jacob O'Bryant06:08:45

Performance should be fine. It'll mainly depend on the libraries Biff uses, all of which are battle-tested (e.g. https://www.eclipse.org/jetty/, https://github.com/metosin/reitit, and https://xtdb.com/). If you get to a point where you need to make it go faster, then you can start switching things out. I think there are other web servers faster than Jetty for instance. If you're planning to build something particularly intensive, it wouldn't hurt to become familiar with XTDB and make sure it fits your needs (there's an #xtdb channel too fyi). > Also, if am also interested in learning ins and outs of web dev, is biff still a good choice? Yep! After you have something working, you can start reading through Biff's source code to learn how it pieces things together. That'll help you learn about the underlying libraries. To get started reading the source code, you'd want to first make sure you understand the https://biffweb.com/docs/#system-composition section in the docs. Then you can pick any of the component functions and start reading the source from there. For example, https://github.com/jacobobryant/biff/blob/master/example/src/com/example.clj#L78 to see the list of components in your app, and then look for the source https://github.com/jacobobryant/biff/blob/master/src/com/biffweb.clj#L39. (I'm planning to write a bunch of tutorials/a small book that'll take readers through that process, but it won't be finished any time soon)

Jacob O'Bryant06:08:35

also, the entire source--not including the application template, which is copied into your project--is only 1.5k lines, so it shouldn't take terribly long to read.

Jacob O'Bryant06:08:22

The main thing you won't learn from Biff is ClojureScript. It's pretty common for Clojure web apps to use CLJS for the frontend with a react wrapper like https://reagent-project.github.io/, and often https://github.com/day8/re-frame. Biff omits all of that intentionally in an attempt to keep things simpler, with https://htmx.org/ basically as a stopgap solution. imo you can go pretty far with that, but if you know you want to use CLJS/React (e.g. if you're building something highly interactive, akin to google docs), Kit would probably be better than Biff since I'm pretty sure it includes some template code for CLJS.