Compare commits

..

No commits in common. "a90cabf605c6d23efed9276fad8c32677d29ae93" and "5245c9a2dd3aeb39e6ab53205e682d4a2d242eef" have entirely different histories.

9 changed files with 9 additions and 37 deletions

View file

@ -22,8 +22,6 @@ 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

View file

@ -32,14 +32,6 @@ $ 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

View file

@ -1,6 +1,6 @@
{ {
"version": "1", "version": "1",
"name": "Snippets", "name": "CodeSnippets",
"type": "collection", "type": "collection",
"ignore": [ "ignore": [
"node_modules", "node_modules",

3
dev.sh
View file

@ -1,3 +0,0 @@
#!/bin/sh
fd -e clj | entr -r clojure -M -m snippets.main

View file

@ -2,6 +2,7 @@
(: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]

View file

@ -14,7 +14,5 @@
(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)))))

View file

@ -3,18 +3,14 @@
[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
(def datomic-config (:datomic (config/get-config))) :system "dev"}))
(def client (d/client (merge {:server-type :datomic-local
:system "dev"} datomic-config)))
(def db-name "snippets") (def db-name "snippets")
@ -106,7 +102,7 @@
[entity] [entity]
(m/validate create-schema entity)) (m/validate create-schema entity))
(defn create-snippets (defn- put-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")
@ -116,6 +112,9 @@
(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."

View file

@ -1,20 +1,9 @@
(ns snippets.main (ns snippets.main
(:require (:require
[snippets.infra.api :as api] [snippets.infra.api :as api]
[clojure.core.server] [snippets.infra.db2 :refer [start-up-check]])
[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))

View file

@ -15,8 +15,6 @@
(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)))))