This file contains hidden or 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
(def routes | |
(-> (trail/resource :posts :only [:index :show]))) | |
; => | |
[ | |
[:get "/posts" posts/index] | |
[:get "/posts/:id" posts/show] | |
] | |
(def routes |
This file contains hidden or 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
; v 1.13.0 | |
(trail/resource :posts) | |
; => | |
; GET /posts => posts/index | |
; GET /posts/:id => posts/show | |
; GET /posts/new => posts/new- | |
; GET /posts/:id/edit => posts/edit | |
; POST /posts => posts/create | |
; PUT /posts/:id => posts/update- | |
; DELETE /posts => posts/delete |
This file contains hidden or 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 your-project.models.items | |
(:require [oksql.core :as oksql]) | |
(:refer-clojure :exclude [update])) | |
(def db {:connection-uri "postgres://localhost:5432/your_project_db"}) | |
(defn create [m] | |
(oksql/insert db :items m)) | |
(defn update [id m] |
This file contains hidden or 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
-- name: where | |
where id = :id | |
returning * |
This file contains hidden or 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 your-project.models.items | |
(:require [oksql.core :as oksql]) | |
(:refer-clojure :exclude [update])) | |
(def db {:connection-uri "postgres://localhost:5432/your_project_db"}) | |
(def query (partial oksql/query db)) | |
(defn create [m] | |
(query :items/insert m)) |
This file contains hidden or 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 your-project.models.items | |
(:require [oksql.core :as oksql])) | |
(def db {:connection-uri "postgres://localhost:5432/your_project_db"}) | |
(def query (partial oksql/query db)) | |
(defn all [] | |
(query :items/all)) |
This file contains hidden or 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
-- name: insert | |
-- fn: first | |
insert into items (id, name, created_at) | |
values (:id, :name, :created_at) | |
returning * | |
-- name: update | |
-- fn: first | |
update items | |
set name = :name |
This file contains hidden or 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
create table items ( | |
id serial primary key, | |
name text, | |
created_at timestamp | |
) |
This file contains hidden or 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
-- name: fetch | |
-- fn: first | |
select * | |
from items | |
where id = :id | |
-- name: all | |
select * | |
from items | |
order by created_at desc |
This file contains hidden or 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 your-proj.controllers.posts-controller | |
(:require [coast.core :as coast] | |
[your-proj.models.posts :as posts] | |
[your-proj.views.posts :as views.posts])) | |
(defn index [request] | |
(let [posts (posts/all)] | |
(views.posts/index (assoc request :posts posts)))) | |
(defn show [request] |