Closed ryanford closed 4 years ago
I also followed the tutorial and I couldn't reproduce this 😔 here is what the src/routes/account
index
function looks like after I generated it:
(defn index [request]
(let [{:db db} request
account (fetch-all db [:account])]
[:div
[:a {:href (url-for :account/new)} "New account"]
[:table
[:thead
[:tr
[:th "id"]
[:th "email"]
[:th "password"]
[:th "created-at"]
[:th "updated-at"]
[:th]
[:th]
[:th]]]
[:tbody
(map
(fn [{:id id :email email :password password :created-at created-at :updated-at updated-at}]
[:tr
[:td id]
[:td email]
[:td password]
[:td created-at]
[:td updated-at]
[:td
[:a {:href (url-for :account/show {:id id})} "Show"]]
[:td
[:a {:href (url-for :account/edit {:id id})} "Edit"]]
[:td
(form-for [request :account/destroy {:id id}]
(submit "Delete"))]])
account)]]]))
I should mention I'm using janet 1.6.0 and joy 0.5.2
this is what you should be getting i think:
(import joy :prefix "")
(defn account [request]
(let [db (get request :db)
id (get-in request [:params :id])]
(fetch db [:account id])))
(defn index [request]
(let [{:db db} request
account (fetch-all db [:account])]
[:div
[:a {:href (url-for :account/new)} "New account"]
[:table
[:thead
[:tr
[:th]
[:th]
[:th]]]
[:tbody
(map
(fn [{}]
[:tr
[:td
[:a {:href (url-for :account/show {:id id})} "Show"]]
[:td
[:a {:href (url-for :account/edit {:id id})} "Edit"]]
[:td
(form-for [request :account/destroy {:id id}]
(submit "Delete"))]])
account)]]]))
(defn show [request]
(let [account (account request)
{} account]
[:table
[:tr
]
[:tr
]]))
(def params
(params
(validates [] :required true)
(permit [])))
(defn form [request route]
(let [account (account request)]
(form-for [request route account]
(submit "Save"))))
(defn new [request]
(form request :account/create))
(defn create [request]
(let [{:db db} request
result (->> (params request)
(insert db :account)
(rescue))
[errors account] result]
(if (nil? errors)
(redirect-to :account/index)
(new (put request :errors errors)))))
(defn edit [request]
(form request :account/patch))
(defn patch [request]
(let [{:db db} request
account (account request)
result (->> (params request)
(update db :account account)
(rescue))
[errors account] result]
(if (nil? errors)
(redirect-to :account/index)
(edit (put request :errors errors)))))
(defn destroy [request]
(let [{:db db} request
account (account request)]
(delete db :account account)
(redirect-to :account/index)))
which is inline with https://github.com/joy-framework/joy/blob/master/src/joy/cli/routes.txt
Janet v 1.6.0-da93a73 Joy v 0.5.2
id
is defined locally in the account
What does your db/schema.sql
look like? It looks like the migrations didn't run and there aren't columns in the table
I did a git diff on my folder and it has this for my db/schema.sql
diff --git a/db/schema.sql b/db/schema.sql
new file mode 100644
index 0000000..4e469b0
--- /dev/null
+++ b/db/schema.sql
@@ -0,0 +1,8 @@
+CREATE TABLE schema_migrations (version text primary key)
+CREATE TABLE account (
+ id integer primary key,
+ email text not null unique,
+ password text not null,
+ created_at integer not null default(strftime('%s', 'now')),
+ updated_at integer
+)
I'm starting to think this is a linux/macos problem with the sqlite lib 🤔
You were close. There was no table. I had created an accounts
table and an account
route. Only error is a user error this time :see_no_evil:
Oh you know what though... joy should handle plural table names. I have an issue for it here https://github.com/joy-framework/joy/issues/21
Following https://github.com/joy-framework/joy/blob/master/docs/tutorial.md . After creating db, running migration and creating route, server fails to start.