duct

roelof 2021-01-07T09:25:36.058Z

Good morning

roelof 2021-01-07T09:26:03.058500Z

Im trying to follow the tutorial on duct

roelof 2021-01-07T09:26:19.059Z

and have to add something for migrations

roelof 2021-01-07T09:26:33.059400Z

so I did change the file to this :

{:duct.profile/base
 {:duct.core/project-ns todo

  :duct.router/ataraxy
  {:routes {[:get "/"] [:todo.handler/index]}}
   [:duct.handler.static/ok :todo.handler/index]
 {:body {:entries "/entries"}}}
 
:duct.migrator/ragtime
{:migrations [#ig/ref :todo.migration/create-entries]}

[:duct.migrator.ragtime/sql :todo.migration/create-entries]
{:up ["CREATE TABLE entries (id INTEGER PRIMARY KEY, content TEXT)"]
 :down ["DROP TABLE entries"]}
 
 :duct.profile/dev   #duct/include "dev"
 :duct.profile/local #duct/include "local"
 :duct.profile/prod  {}

 :duct.module/logging {}
 :duct.module.web/api
 {}
 :duct.module/sql
 {}}

roelof 2021-01-07T09:27:13.060Z

but now I see this error message

Execution error (IllegalArgumentException) at clojure.java.jdbc/get-connection (jdbc.clj:292).
db-spec null is missing a required parameter

kwrooijen 2021-01-07T09:29:04.060700Z

I think you at least need to move :duct.migrator/ragtime and [:duct.migrator.ragtime/sql :todo.migration/create-entries] into the :duct.profile/base map

kwrooijen 2021-01-07T09:29:26.061Z

(They are one level higher, in the module level)

kwrooijen 2021-01-07T09:30:23.061400Z

I'm not sure if that'll solve everything though, but that needs to be fixed

roelof 2021-01-07T09:30:46.061800Z

hmm, when I check the { it looks the code is inside the map

roelof 2021-01-07T09:31:20.062100Z

all the code seems to be in the map

roelof 2021-01-07T09:31:28.062400Z

or I misunderstood you

kwrooijen 2021-01-07T09:32:16.062600Z

Here is a fixed version:

{:duct.profile/base
 {:duct.core/project-ns todo

  :duct.router/ataraxy
  {:routes {[:get "/"] [:todo.handler/index]}}

  [:duct.handler.static/ok :todo.handler/index]
  {:body {:entries "/entries"}}

  :duct.migrator/ragtime
  {:migrations [#ig/ref :todo.migration/create-entries]}

  [:duct.migrator.ragtime/sql :todo.migration/create-entries]
  {:up ["CREATE TABLE entries (id INTEGER PRIMARY KEY, content TEXT)"]
   :down ["DROP TABLE entries"]}}

 :duct.profile/dev   #duct/include "dev"
 
 :duct.profile/local #duct/include "local"
 
 :duct.profile/prod  {}
 
 :duct.module/logging {}
 
 :duct.module.web/api {}
 
 :duct.module/sql {}}

kwrooijen 2021-01-07T09:32:47.063300Z

the two keys I mentioned are now inside of the map of :duct.profile/base , not in the top level map

kwrooijen 2021-01-07T09:33:21.063500Z

(You can see the difference in indentation)

roelof 2021-01-07T09:34:27.064900Z

thanks, but if I copy/paste your code the layout is messed up

kwrooijen 2021-01-07T09:34:56.065100Z

Because of Slack you mean?

roelof 2021-01-07T09:35:08.065300Z

no idea

roelof 2021-01-07T09:35:48.066Z

it looks now this in vs code :

{:duct.profile/base
 {:duct.core/project-ns todo  :duct.router/ataraxy
  {:routes {[:get "/"] [:todo.handler/index]}}  [:duct.handler.static/ok :todo.handler/index]
  {:body {:entries "/entries"}}  :duct.migrator/ragtime
  {:migrations [#ig/ref :todo.migration/create-entries]}  [:duct.migrator.ragtime/sql :todo.migration/create-entries]
  {:up ["CREATE TABLE entries (id INTEGER PRIMARY KEY, content TEXT)"]
   :down ["DROP TABLE entries"]}} :duct.profile/dev   #duct/include "dev" :duct.profile/local #duct/include "local" :duct.profile/prod  {} :duct.module/logging {} :duct.module.web/api {} :duct.module/sql {}}

kwrooijen 2021-01-07T09:36:00.066200Z

Yeah that's not good lol

kwrooijen 2021-01-07T09:36:38.066700Z

Try this

roelof 2021-01-07T09:38:11.067Z

that is better

roelof 2021-01-07T09:38:15.067200Z

thanks a lot

kwrooijen 2021-01-07T09:38:34.067400Z

Do you see what's different now?

roelof 2021-01-07T09:39:06.067800Z

yep, on my old code everything was intented the same

roelof 2021-01-07T09:39:12.068200Z

now not

kwrooijen 2021-01-07T09:39:55.068700Z

Hopefully it'll fix your error. Here's a small overview about the difference between base / profile / module configs https://github.com/duct-framework/duct/wiki/Configuration#duct-base-profiles-and-modules

kwrooijen 2021-01-07T09:40:02.068900Z

Might be useful

roelof 2021-01-07T09:58:20.069100Z

thanks

roelof 2021-01-07T10:10:49.069500Z

hmm maybe a error in the tutorial

First, add a new POST route:

:duct.router/ataraxy
{:routes
 {[:get "/"]        [:todo.handler/index]
  [:get "/entries"] [:todo.handler.entries/list]

  [:post "/entries" {{:keys [description]} :body-params}]
  [:todo.handler.entries/create description]}}

The new Ataraxy route not only matches the method and URI of the request, it also destructures the request body and places the description of the todo entry into the result.

When we come to write the associated handler, we need some way of getting the information from the result. Ataraxy places the result into the :ataraxy/result key on the request map, so we can destructure the request to find the description of the new entry:

[:duct.handler.sql/insert :todo.handler.entries/create]
{:request {[_ description] :ataraxy/result}
 :sql     ["INSERT INTO entries (description) VALUES (?)" description]}

roelof 2021-01-07T10:11:21.070200Z

must the last line not be :duct.handler.sql/create ....

roelof 2021-01-07T10:11:44.070600Z

because of this error message :

Missing definitions for refs: :todo.handlers.entries.create

kwrooijen 2021-01-07T10:13:00.071Z

Can you link the tutorial?

roelof 2021-01-07T10:15:12.071200Z

of course https://github.com/duct-framework/docs/blob/master/GUIDE.rst

kwrooijen 2021-01-07T10:18:36.071700Z

Do you have [duct/handler.sql "0.4.0"] as a dependency in project.clj?

kwrooijen 2021-01-07T10:19:33.072300Z

Also I've never used sql handlers, I feel that it doesn't really give me enough control over my handlers

roelof 2021-01-07T10:25:49.072600Z

yes, I have

roelof 2021-01-07T10:26:03.072900Z

:dependencies [[org.clojure/clojure "1.10.0"]
                 [duct/core "0.7.0"]
                 [duct/handler.sql "0.4.0"]
                 [duct/module.logging "0.4.0"]
                 [duct/module.web "0.7.0"]
                 [duct/module.ataraxy "0.3.0"]
                 [duct/module.sql "0.5.0"]
                 [org.xerial/sqlite-jdbc "3.25.2"]]

kwrooijen 2021-01-07T10:27:32.073100Z

Can you show me your config?

roelof 2021-01-07T10:28:38.073500Z

you mean project.clj or config.edn ?

kwrooijen 2021-01-07T10:28:43.073700Z

config.edn

kwrooijen 2021-01-07T10:31:10.074500Z

Oh I see, you have :todo.handlers.entries.create but I think that should be :todo.handlers.entries/create

kwrooijen 2021-01-07T10:31:27.074900Z

The error is saying it can't find a key for :todo.handlers.entries.create, which makes sense

roelof 2021-01-07T10:33:56.075400Z

chips, that sort of errors do I overlooked very often

roelof 2021-01-07T10:34:16.075800Z

now another problem not related to duct I think

http post :3000/entries description="Write Duct guide"

http: error: ConnectionError: HTTPConnectionPool(host='localhost', port=3000): Max retries exceeded with url: /entries (Caused by NewConnectionError('&lt;urllib3.connection.HTTPConnection object at 0x7f7c4f0ff4f0&gt;: Failed to establish a new connection: [Errno 111] Connection refused')) while doing POST request to URL: <http://localhost:3000/entries>

kwrooijen 2021-01-07T10:35:44.076Z

I guess the server isn't started?

kwrooijen 2021-01-07T10:36:04.076300Z

Or wrong port

roelof 2021-01-07T10:36:37.076700Z

hmm, you mean the duct server or the sqlite server

kwrooijen 2021-01-07T10:37:02.076900Z

Duct server

kwrooijen 2021-01-07T10:37:32.077300Z

That HTTPie error sounds like it can't connect because it doesn't exist

roelof 2021-01-07T10:38:00.077500Z

hmm

roelof 2021-01-07T10:38:21.078Z

this is telling me that the duct server is working

roelof 2021-01-07T10:38:24.078300Z

user=&gt; (dev)
:loaded

kwrooijen 2021-01-07T10:38:59.078900Z

(dev) switches you to the development namespace (`dev.clj`). Afterwards to start the server you have to use (go)

roelof 2021-01-07T10:39:11.079200Z

i saw it

roelof 2021-01-07T10:39:31.079700Z

and now the error re appears again

Execution error (ExceptionInfo) at integrant.core/missing-refs-exception (core.cljc:191).
Missing definitions for refs: :todo.handlers.entries/create

kwrooijen 2021-01-07T10:39:40.079900Z

😕

kwrooijen 2021-01-07T10:40:03.080100Z

Typo again

kwrooijen 2021-01-07T10:40:10.080300Z

s/handlers/handler

roelof 2021-01-07T10:41:02.080500Z

finally it worked

roelof 2021-01-07T10:50:51.081200Z

maybe after this one look for a tutorial where duct is used to ask a external api

roelof 2021-01-07T12:23:36.081700Z

hmmm, and another wierd error:

{:duct.profile/base
 {:duct.core/project-ns todo

  :duct.router/ataraxy
  {:routes {[:get "/"] [:todo.handler/index]
            [:get "/entries"] [:todo.handler.entries/list]

            [:post "/entries" {{:keys [description]} :body-params}]
            [:todo.handler.entries/create description]

            [:get "/entries/" id] [todo.handler.entries/find ^int id]
            [:delete "entries/" id] [todo.handler.entries/destroy ^int id]}}

  [:duct handler.sql/query-one :todo.handler.entries/find]
  {:request {[_ id] :ataraxy/result}
   :sql ["SELECT * FROM entries WHERE id = ?" id]
   :hrefs {:href "entries/{id}"}}

  [:duct.handler.sql/execute :todo.handler.entries/destroy]
  {:request {[_ id] :ataraxy/result}
   :sql ["DELETE FROM entries WHERE id =?" id]}

  [:duct.handler.static/ok :todo.handler/index]
  {:body {:entries "/entries"}}

  [:duct.handler.sql/query :todo.handler.entries/list]
  {:sql ["SELECT * FROM entries"]
   :hrefs {:href "/entries/{id}"}}

  [:duct.handler.sql/insert :todo.handler.entries/create]
  {:request {[_ description] :ataraxy/result}
   :sql     ["INSERT INTO entries (description) VALUES (?)" description]
   :location "entries/{last_insert_rowid}"}

  :duct.migrator/ragtime
  {:migrations [#ig/ref :todo.migration/create-entries]}

  [:duct.migrator.ragtime/sql :todo.migration/create-entries]
  {:up ["CREATE TABLE entries (id INTEGER PRIMARY KEY, description TEXT)"]
   :down ["DROP TABLE entries"]}}

 :duct.profile/dev   #duct/include "dev"
 :duct.profile/local #duct/include "local"
 :duct.profile/prod  {}
 :duct.module/logging {}
 :duct.module.web/api {}
 :duct.module/sql {}}

roelof 2021-01-07T12:23:56.082Z

reset)
:reloading ()
Execution error (AssertionError) at integrant.core/eval3789$fn (core.cljc:64).
Assert failed: (namespace parent)

kwrooijen 2021-01-07T12:30:13.082800Z

The error is super cryptic (A bit of an Integrant issue). But I looks like you have a typo here: [:duct handler.sql/query-one :todo.handler.entries/find]

kwrooijen 2021-01-07T12:30:18.083200Z

Missing a dot

roelof 2021-01-07T12:34:02.083400Z

pff changed it

roelof 2021-01-07T12:34:11.083700Z

but now see this :

Execution error (AssertionError) at ataraxy.core/parse (core.clj:105).
Assert failed: (valid? routes)

kwrooijen 2021-01-07T12:34:35.083900Z

haha

roelof 2021-01-07T12:34:44.084300Z

not funny

kwrooijen 2021-01-07T12:34:52.084500Z

Apparently the syntax isn't correct for :routes

kwrooijen 2021-01-07T12:35:04.084700Z

https://github.com/weavejester/ataraxy

roelof 2021-01-07T12:36:46.085600Z

oke, I copied the code from the tutorial and everything is working

roelof 2021-01-07T13:43:59.086300Z

oke, done that one

roelof 2021-01-07T13:44:27.086900Z

are there more tutorials I can follow to get more familiar with duct ?

kwrooijen 2021-01-07T13:45:58.087500Z

There aren't many tutorials sadly. But be sure to understand how Integrant works https://github.com/weavejester/integrant/

âž• 1
kwrooijen 2021-01-07T13:46:10.087900Z

Because that's about 90% of what Duct is

roelof 2021-01-07T13:47:27.088100Z

thanks,

roelof 2021-01-07T13:47:33.088400Z

Will read that well

roelof 2021-01-07T13:47:58.089100Z

and maybe it is then better to write my own toy-project

roelof 2021-01-07T13:48:06.089300Z

but no today

roelof 2021-01-07T13:53:12.090Z

maybe a piece of a galllery I wanted to build or a part of a crm I have in mind