Fork me on GitHub
#biff
<
2022-12-25
>
DenisMc23:12:54

Hi, I want to deploy the first version of our company website, plus some basic crud functionalities for our api service (primary target is flutter on mobile devices). Our backend is Postgres. Biff sounds like it could be a good candidate to help us do this quickly, but I’m slightly worried because we’re using Postgres and not xtdb. Is this concern justified, or is it straightforward to use Postgres? I would anticipate most (if not all if we’re lucky) of our backend interactions to be via our REST api anyhow but better to be aware of any obvious constraints up front.

Jacob O'Bryant23:12:36

Hi! Using Postgres instead of XT should be fine. Just need to tweak a few things in the default project to omit xtdb. I'll make an FAQ section for this soon; it's come up a couple times in the past.

Jacob O'Bryant16:12:28

> Example of starting a simple biff w no db. heh, I suppose that is true! of course that code snippet also leaves out a bunch of other stuff that you'd want to leave in

Jacob O'Bryant16:12:02

I can give a few more details now that I'm at my desk. This is the main change you'd need to make to a new project, in your main namespace:

diff --git a/example/src/com/example.clj b/example/src/com/example.clj
index ea247a0..f143453 100644
--- a/example/src/com/example.clj
+++ b/example/src/com/example.clj
@@ -43,9 +43,7 @@
 (def components
   [biff/use-config
    biff/use-random-default-secrets
-   biff/use-xt
    biff/use-queues
-   biff/use-tx-listener
    biff/use-outer-default-middleware
    biff/use-jetty
    biff/use-chime
@@ -56,6 +54,10 @@
 (defn start []
   (biff/start-system
    {:com.example/chat-clients (atom #{})
+    ;; By default, merge-context-fn is set to com.biffweb/assoc-db, which sets
+    ;; the :biff/db key to an XT database value in incoming Ring requests (and
+    ;; in a few other situations). This turns merge-context-fn into a no-op.
+    :biff/merge-context-fn identity
     :biff/features #'features
     :biff/after-refresh `start
     :biff/handler #'handler
Other than that, the new project template does come with a few XT transactions and queries throughout the app, but you'll want to just delete those anyway. One caveat is that the XTDB dependencies will still be pulled in by com.biffweb/biff , and if you exclude them, requiring com.biffweb will fail. Long ago I had Biff organized into a bunch of separate mini libraries, but I decided the overhead wasn't worth it and merged them all into com.biffweb/biff. I have thought about providing some dummy versions of Biff's larger dependencies, so if you wanted to e.g. use Biff without XT, you could put something like this in your dependencies:
...
 :deps {com.biffweb/biff {:git/url "..."
                          :sha "..."
                          :exclusions [com.xtdb/xtdb-core
                                       com.xtdb/xtdb-jdbc
                                       com.xtdb/xtdb-rocksdb]}
        com.biffweb/xtdb-noop {:git/url "..."
                               :sha "..."}
...
(In this case, if you called any of Biff's functions that depend on XT, like com.biffweb/submit-tx, then they'd throw an UnsupportedOperationException)

👍 1