Skip to content

Instantly share code, notes, and snippets.

(db/transact {:post/title "3 things you should know about Coast on Clojure"
:post/body "1. It's great. 2. It's tremendous. 3. It's making web development fun again."
:post/author-id 2})
(db/pull '[author/id
author/email
author/name
{(:author/posts :order post/created-at desc
:limit 10) [post/id
post/title
post/body]}]
[:author/name "Cody Coast"])
(db/pull '[author/id
author/email
author/name
{:author/posts [post/title
post/body]}]
[:author/name "Cody Coast"])
(db/q '[:pull [author/id
author/email
author/name
{:author/posts [post/title
post/body]}]
:where [author/name ?author/name]]
{:author/name "Cody Coast"})
; =>
@swlkr
swlkr / coast-query.clj
Created July 16, 2018 00:03
Coast Query
(ns your-project
(:require [coast.db :as db]))
(db/q '[:select author/id
author/name
post/id
post/title
post/body
:joins author/posts
:where [author/name ?author/name]
@swlkr
swlkr / coast-schema.clj
Last active July 15, 2018 23:48
Coast Schema
[{:db/ident :author/email
:db/type "text"}
{:db/ident :author/name
:db/type "text"}
{:db/rel :author/posts
:db/type :many
:db/joins :post/author}
@swlkr
swlkr / static-site-generator.clj
Last active August 8, 2021 14:08
A very naive static site generator in clojure
(ns core
(:require [clojure.string :as string]
[markdown.core :as md]
[clojure.java.io :as io]
[clojure.data.xml :as xml]))
(def pattern #"__([\w-]+)__")
(defn replacement [match m]
(let [fallback (first match)
(ns switch
(:require [clojure.pprint :as pprint]))
(defn project-clj-map [filename]
(->> (slurp filename)
(read-string)
(drop 1)
(partition 2)
(map vec)
(into {})))
(ns your-proj.views.posts
(:require [your-proj.components :as c]
[coast.core :as coast]))
(defn post [m]
(let [{:keys [id title body created-at]} m]
[:tr
[:td id]
[:td title]
[:td body]
(def routes
(-> (trail/resource :posts :only [:index :show])))
; =>
[
[:get "/posts" posts/index]
[:get "/posts/:id" posts/show]
]
(def routes