Compare commits
3 commits
5245c9a2dd
...
a90cabf605
| Author | SHA1 | Date | |
|---|---|---|---|
| a90cabf605 | |||
| a8038a604c | |||
| 6878e11a4c |
9 changed files with 37 additions and 9 deletions
|
|
@ -22,6 +22,8 @@ RUN clj -P
|
||||||
COPY build.clj config.edn ./
|
COPY build.clj config.edn ./
|
||||||
COPY src ./src
|
COPY src ./src
|
||||||
|
|
||||||
|
ENV DATOMIC_PATH=/datomic_data
|
||||||
|
ENV DATOMIC_ENV=prd
|
||||||
# construct the application jar
|
# construct the application jar
|
||||||
RUN clj -T:build uber && cp target/snippets-standalone.jar ./app.jar && rm -r target
|
RUN clj -T:build uber && cp target/snippets-standalone.jar ./app.jar && rm -r target
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,14 @@ $ fd -e clj | entr -r clojure -M -m snippets.main
|
||||||
|
|
||||||
### Repl
|
### Repl
|
||||||
|
|
||||||
|
Connect to the repl of running app
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ rlwrap nc localhost 5555
|
||||||
|
```
|
||||||
|
|
||||||
|
Or start up fresh repl
|
||||||
|
|
||||||
```
|
```
|
||||||
$ rlwrap clojure
|
$ rlwrap clojure
|
||||||
; print stuff
|
; print stuff
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"version": "1",
|
"version": "1",
|
||||||
"name": "CodeSnippets",
|
"name": "Snippets",
|
||||||
"type": "collection",
|
"type": "collection",
|
||||||
"ignore": [
|
"ignore": [
|
||||||
"node_modules",
|
"node_modules",
|
||||||
|
|
|
||||||
3
dev.sh
Executable file
3
dev.sh
Executable file
|
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
fd -e clj | entr -r clojure -M -m snippets.main
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
(:require
|
(:require
|
||||||
[ring.adapter.jetty :as jetty]
|
[ring.adapter.jetty :as jetty]
|
||||||
[clojure.pprint :as pprint]
|
[clojure.pprint :as pprint]
|
||||||
[clojure.string :as str]
|
|
||||||
[taoensso.telemere :as t]
|
[taoensso.telemere :as t]
|
||||||
[snippets.use-cases.view]
|
[snippets.use-cases.view]
|
||||||
[snippets.use-cases.delete]
|
[snippets.use-cases.delete]
|
||||||
|
|
|
||||||
|
|
@ -14,5 +14,7 @@
|
||||||
(defn get-config []
|
(defn get-config []
|
||||||
(->
|
(->
|
||||||
(static-config)
|
(static-config)
|
||||||
|
(assoc-in-not-nil [:datomic :storage-dir] (env :datomic-path))
|
||||||
|
(assoc-in-not-nil [:datomic :system] (env :datomic-env))
|
||||||
(assoc-in-not-nil [:jetty :host] (env :host))
|
(assoc-in-not-nil [:jetty :host] (env :host))
|
||||||
(assoc-in-not-nil [:jetty :port] (safe-parse-int (env :port)))))
|
(assoc-in-not-nil [:jetty :port] (safe-parse-int (env :port)))))
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,18 @@
|
||||||
[clojure.set :as set]
|
[clojure.set :as set]
|
||||||
[datomic.client.api :as d]
|
[datomic.client.api :as d]
|
||||||
[malli.core :as m]
|
[malli.core :as m]
|
||||||
|
[snippets.infra.config :as config]
|
||||||
[taoensso.telemere :as t]))
|
[taoensso.telemere :as t]))
|
||||||
|
|
||||||
;; Initialize the Datomic Local client
|
;; Initialize the Datomic Local client
|
||||||
;; :system "dev" groups your databases in the "dev" system
|
;; :system "dev" groups your databases in the "dev" system
|
||||||
;; In production, you'd set :storage-dir to a persistent path
|
;; In production, you'd set :storage-dir to a persistent path
|
||||||
;; TODO: add save file location for prod
|
;; TODO: add save file location for prod
|
||||||
(def client (d/client {:server-type :datomic-local
|
|
||||||
:system "dev"}))
|
(def datomic-config (:datomic (config/get-config)))
|
||||||
|
|
||||||
|
(def client (d/client (merge {:server-type :datomic-local
|
||||||
|
:system "dev"} datomic-config)))
|
||||||
|
|
||||||
(def db-name "snippets")
|
(def db-name "snippets")
|
||||||
|
|
||||||
|
|
@ -102,7 +106,7 @@
|
||||||
[entity]
|
[entity]
|
||||||
(m/validate create-schema entity))
|
(m/validate create-schema entity))
|
||||||
|
|
||||||
(defn- put-snippets
|
(defn create-snippets
|
||||||
"Create new snippets in the database."
|
"Create new snippets in the database."
|
||||||
[snippets]
|
[snippets]
|
||||||
(t/log! {:level :info, :data {:slugs (map :slug snippets)}} "Saving new snippets to db")
|
(t/log! {:level :info, :data {:slugs (map :slug snippets)}} "Saving new snippets to db")
|
||||||
|
|
@ -112,9 +116,6 @@
|
||||||
(d/transact conn {:tx-data entities})
|
(d/transact conn {:tx-data entities})
|
||||||
(throw (ex-info "Invalid snippet entity" {:entities entities})))))
|
(throw (ex-info "Invalid snippet entity" {:entities entities})))))
|
||||||
|
|
||||||
(def create-snippets
|
|
||||||
(wrap-snippet-return put-snippets))
|
|
||||||
|
|
||||||
;; read
|
;; read
|
||||||
(defn- get-snippet-by-slug-from-db
|
(defn- get-snippet-by-slug-from-db
|
||||||
"Get a single snippet by its slug."
|
"Get a single snippet by its slug."
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,20 @@
|
||||||
(ns snippets.main
|
(ns snippets.main
|
||||||
(:require
|
(:require
|
||||||
[snippets.infra.api :as api]
|
[snippets.infra.api :as api]
|
||||||
[snippets.infra.db2 :refer [start-up-check]])
|
[clojure.core.server]
|
||||||
|
[snippets.infra.db2 :refer [start-up-check]]
|
||||||
|
[taoensso.telemere :as t])
|
||||||
(:gen-class))
|
(:gen-class))
|
||||||
|
|
||||||
|
(defn start-repl-server []
|
||||||
|
(let [settings {:port 5555 :host "0.0.0.0"}]
|
||||||
|
(clojure.core.server/start-server
|
||||||
|
(merge
|
||||||
|
{:name "repl"
|
||||||
|
:accept 'clojure.core.server/repl} settings))
|
||||||
|
(t/log! {:level :info, :data {:settings settings}} "Starting repl server")))
|
||||||
|
|
||||||
(defn -main []
|
(defn -main []
|
||||||
(start-up-check)
|
(start-up-check)
|
||||||
|
(start-repl-server)
|
||||||
(api/run-server))
|
(api/run-server))
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
(let [limit (:limit options)
|
(let [limit (:limit options)
|
||||||
skip (:skip options)]
|
skip (:skip options)]
|
||||||
(->> (db/list-snippets)
|
(->> (db/list-snippets)
|
||||||
|
(sort-by :pub-date)
|
||||||
|
(reverse)
|
||||||
(drop skip)
|
(drop skip)
|
||||||
(take limit)
|
(take limit)
|
||||||
(map serialize-snippet)))))
|
(map serialize-snippet)))))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue