This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[datomic.api :as d]) | |
(d/create-database "datomic:mem://counter-example") | |
;=> true | |
(def c (d/connect "datomic:mem://counter-example")) | |
;=> #'user/c | |
;; The essential features of creating and using an auto-increment counter in datomic: | |
;; | |
;; 1. A counter entity must store the current value and a nonce. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Optimized MYSQL schema for datomic | |
-- Unfortunately the bin/sql/mysql-*.sql bootstrapping files for datomic are not | |
-- very good, and can actually cause failures if not adjusted. | |
-- One symptom of this is the following error: | |
-- SQL Error (1071): Specified key was too long; max key length is 767 bytes. | |
-- Reported here: https://support.cognitect.com/entries/28462168-MySQL-Caveats | |
-- This is caused by the default collation for the `id` column possibly being |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# Produce a squash-commit patch from a branch of changes | |
MASTER=$1 | |
PATCHBRANCH=$2 | |
SQUASHBRANCH="$PATCHBRANCH-squash" | |
MESSAGE=$3 | |
git checkout -b $SQUASHBRANCH $MASTER && | |
git merge --squash $PATCHBRANCH && | |
git commit -a -m "$MESSAGE" && |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns favila.eid-utils | |
"Utilities to construct or decompose entity ids on on-prem systems. | |
Many of these utilities replicate datomic.api functions because the peer api | |
lacks them. | |
The entity id format is: | |
sign-bit, reserved-bit, 20-partition-bits, 42-t-bits |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[datomic.api :as d]) | |
(defn last-touched-tx | |
"Return the tx of the oldest assertion on `entity` or any of its components." | |
[db entity] | |
(or (d/q '[:find (max ?tx) . | |
:in $ % ?root | |
:where | |
(component-entities ?root ?ce) | |
(union ?root ?ce ?e) | |
[?e _ _ ?tx]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn safe-merge | |
"Like merge, but throws if maps have the same keys but different values." | |
[& maps] | |
(reduce | |
(fn [m [m2k m2v :as re]] | |
(if-some [[_ mv :as le] (find m m2k)] | |
(if (= mv m2v) | |
m | |
(throw (ex-info "Attempted to safe-merge maps with conflicting entries" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Uses the h2 jar in a datomic distribution to give raw SQL access | |
# to the h2 database datomic "dev" storage uses. | |
# The 'SHUTDOWN COMPACT' command in particular performs all | |
# vaccum-like compaction of the h2 database file to remove | |
# unused blocks from deleted (garbage-collected) segments. | |
DATOMIC_HOME=${DATOMIC:-$HOME/lib/datomic/current} | |
DATOMIC_ADMIN_PASSWORD=${1:?Storage admin password must be provided} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns favila.read-edn.tag-readers | |
"Common tag-reader maps for edn." | |
(:require datomic.db | |
datomic.function | |
datomic.codec) | |
(:import java.net.URI)) | |
(defmethod print-method URI [^URI x ^Writer w] | |
(doto w | |
(.write "#uri ") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns kafka-workbench | |
(:require [franzy.clients.consumer.protocols :as c] | |
[franzy.clients.producer.protocols :as p] | |
[franzy.serialization.serializers :as serializers] | |
[franzy.serialization.deserializers :as deserializers] | |
[franzy.clients.consumer.client :as consumer] | |
[franzy.clients.producer.client :as producer])) | |
(def kafka-brokers []) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn tx-pipeline-inorder | |
"Transact transactions in core.async channel `from-ch` against datomic connection `conn` with a pipeline depth of `n`. | |
Returns a map with keys `:stop!` and `:result`. `:stop!` is a no-arg function you can call to immediately | |
cease sending transactions (already sent transactions cannot be stopped). `:result` is a promise channel | |
returning a variant of the result of the tx-pipelining after from-ch is closed and drained, or | |
:stop! is called and all send transaction futures are deref-ed, or a transaction produces an exception. | |
The variant returned from the :result channel may be one of: | |
NewerOlder