-
-
Save Ferossgp/7509e14d22e8a3a555c82a7039dde760 to your computer and use it in GitHub Desktop.
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 datascript.controller | |
(:require [datascript.protocols :as pt] | |
[keechma.next.controller :as ctrl] | |
[datascript.core :as d])) | |
(defn missing-pull-result [query] | |
(when (some #{:db/id} query) | |
{:db/id nil})) | |
(deftype DataScriptApi [ctrl conn*] | |
pt/IDataScriptApi | |
(transact! [_ attributes] | |
;; TODO: Inspect the usage of db-with instead of d/transact? | |
(ctrl/transact ctrl #(d/transact! conn* attributes)) | |
nil) | |
(q [_ query args] | |
(apply (partial d/q query @conn*) args)) | |
(entity [_ eid] | |
(d/entity @conn* eid)) | |
(pull [_ query id] | |
(cond | |
(integer? id) | |
(d/pull @conn* query id) | |
(vector? id) | |
(if-let [eid (d/entid conn* id)] | |
(d/pull @conn* query eid) | |
(missing-pull-result query)) | |
(nil? id) | |
(missing-pull-result query))) | |
(pull-many [_]) | |
(filter [_ pred] | |
(d/filter @conn* pred))) | |
(defmethod ctrl/api :keechma/datascript [{:keys [state*] :as ctrl}] | |
(->DataScriptApi ctrl state*)) | |
(defmethod ctrl/start :keechma/datascript [ctrl _ _ _] | |
;; TODO: Maybe integrate with datascript listeners to avoid extra query | |
(d/empty-db (:keechma.datascript/schema ctrl))) |
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 controllers.datascript | |
(:refer-clojure :exclude [filter]) | |
(:require [datascript.protocols :as pt] | |
[keechma.next.protocols :as keechma-pt] | |
[datascript.core :as d] | |
[datascript.controller])) | |
(derive :keechma/datascript :keechma/controller) | |
(def transact! (keechma-pt/make-api-proxy pt/transact!)) | |
(def q (keechma-pt/make-api-proxy pt/q)) | |
(def entity (keechma-pt/make-api-proxy pt/entity)) | |
(def pull (keechma-pt/make-api-proxy pt/pull)) | |
(def pull-many (keechma-pt/make-api-proxy pt/pull-many)) | |
(def filter (keechma-pt/make-api-proxy pt/filter)) | |
(def touch d/touch) |
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 datascript.protocols | |
(:refer-clojure :exclude [filter])) | |
(defprotocol IDataScriptApi | |
(transact! [_ attributes]) | |
(q [_ query args]) | |
(entity [_ eid]) | |
(pull [_ query id]) | |
(pull-many [_]) | |
(filter [_ pred])) |
Author
Ferossgp
commented
Nov 2, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment