This guide will get you up and running with Sandbar in minutes.
Clone the repository and install dependencies:
git clone <repository-url>
cd sandbar
lein deps
Sandbar requires a running Datomic transactor. Start it in a separate terminal:
# For Datomic Dev
cd /path/to/datomic
bin/transactor config/dev-transactor.properties
The default configuration expects Datomic at datomic:dev://localhost:4334/sandbar.
lein run
The server starts on http://localhost:8080.
lein repl
Once in the REPL:
;; Start the system
(go)
;; The system is now running:
;; - HTTP server on port 8080
;; - nREPL server on port 28888
;; Stop the system
(stop)
;; Restart after code changes
(stop)
(go)
curl http://localhost:8080/api/status
Expected response:
{
"time": "2024-01-15T10:30:00.000Z",
"clojure": {"major": 1, "minor": 12, "incremental": 4}
}
curl http://localhost:8080/api/store/classes
Expected response:
{
"count": 42,
"classes": ["db.type/bigdec", "db.type/bigint", "db.type/boolean", ...]
}
curl http://localhost:8080/api/store/classes/dt/Resource
Expected response:
{
"class": "dt/Resource",
"description": {...},
"abstract?": false,
"slots": ["db/doc", "db/ident", "dt/label", "dt/namespace", "dt/type"],
"subclasses": ["dt/Class", "dt/List", "dt/Literal", "dt/Property", "dt/Ref", ...]
}
Connect to the nREPL server (port 28888) from your editor, or use the command line:
lein repl :connect 28888
(require '[sandbar.db.datatype :as dt])
;; List all classes
(dt/all-classes)
;; => (:dt/Class :dt/Property :dt/Resource :model/User ...)
;; Get class hierarchy
(dt/ancestors-of :model/User)
;; => (:dt/Ref :dt/Resource)
(dt/subclasses-of :dt/Ref)
;; => (:dt/Any :dt/Fn :model/Twit :model/User)
;; Query slots
(dt/slots-of :model/User)
;; => #{:db/doc :db/ident :dt/label :dt/context :dt/type :user/login :user/secret :user/uuid}
;; Check type relationships
(dt/subclass-of? :dt/Resource :model/User)
;; => true
(require '[sandbar.db.datatype :as dt])
;; Create a new User instance
(def alice (dt/make :model/User {:user/login "alice"
:user/secret "hashed-password"}))
;; Verify the type
(:dt/type alice)
;; => :model/User
;; Validate the entity
(dt/valid? alice)
;; => true
# Run all tests
lein test
# Run a specific test namespace
lein test sandbar.api-store-test
Ensure the Datomic transactor is running:
# Check if transactor is listening
nc -zv localhost 4334
Change the HTTP port in config/config.edn:
{:http-port 8081}
Check that all required schema files are listed in config/config.edn:
{:required-schema [:meta :literal :ref :fn :any :user :twit]}
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |