Collections
(ns fab.tutorial
(:require [fabrikk.alpha.core :as fab]))
(defn admin-email []
(str "admin-" (rand-int 10000) "@example.com"))
(def user
(fab/->factory
::user
{:primary-key :id
:template {:id (fab/sequence)
:name "John Smith"
:email "john@example.org"
:role "user"
:verified true}
:traits {:admin {:name (fab/derive :id (partial str "Admin-"))
:email admin-email
:role "admin"}
:unverified {:verified false}}}))
(def post
(fab/->factory
::post
{:template {:id random-uuid
:title "This one weird trick"
:content "Some content goes here...."
:author (fab/one ::user)
:author-name (fab/derive [:author] :name)}}))
(defonce my-store (atom {}))
(def collect (fnil conj []))
(defmethod fab/persist! :my-store [factory-id entity]
(let [persisted (assoc entity :id (case factory-id
::user (rand-int 1000000)
::post (random-uuid)))]
(swap! my-store update factory-id collect persisted)
persisted))
(fab/set-default-persistence :my-store)Building Collections
Creating Collections
Mixing building and creation
The 'many' Directive
Last updated