Skip to content

Commit 0ee3739

Browse files
committed
Remove SQL steps from 'Hello World' web section
1 parent dbf0123 commit 0ee3739

File tree

1 file changed

+15
-90
lines changed

1 file changed

+15
-90
lines changed

index.adoc

Lines changed: 15 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ While Duct can be used for any server-side application, its most common
539539
use-case is developing web applications and services. This section will
540540
take you through writing a '`todo list`' web application in Duct.
541541

542-
=== Hello World Wide Web
542+
=== Hello World
543543

544544
We'll begin by creating a new project directory.
545545

@@ -549,24 +549,16 @@ mkdir todo-app && cd todo-app
549549
----
550550

551551
The first thing we'll need is a `deps.edn` file that to provide the
552-
project dependencies. This will include Duct main and three additional
553-
modules: logging, sql and web.
554-
555-
https://www.sqlite.org/index.html[SQLite] will be our database, so we'll
556-
need the SQLite JDBC adapter as well. To give us a Clojure-friendly way
557-
of querying the database, we'll also add
558-
https://github.com/seancorfield/next-jdbc[next.jdbc].
552+
project dependencies. This will include Duct main and two additional
553+
modules: logging and web.
559554

560555
.deps.edn
561556
[,clojure]
562557
----
563558
{:deps {org.clojure/clojure {:mvn/version "1.12.0"}
564559
org.duct-framework/main {:mvn/version "0.1.3"}
565560
org.duct-framework/module.logging {:mvn/version "0.6.5"}
566-
org.duct-framework/module.sql {:mvn/version "0.7.1"}
567-
org.duct-framework/module.web {:mvn/version "0.11.0"}
568-
org.xerial/sqlite-jdbc {:mvn/version "3.47.0.0"}
569-
com.github.seancorfield/next.jdbc {:mvn/version "1.3.955"}}
561+
org.duct-framework/module.web {:mvn/version "0.11.1"}}
570562
:aliases {:duct {:main-opts ["-m" "duct.main"]}}}
571563
----
572564

@@ -578,106 +570,41 @@ is the default directory Clojure uses to store source files.
578570
$ mkdir src
579571
----
580572

573+
IMPORTANT: It is especially important to ensure the source directory
574+
exists before starting a REPL, otherwise the REPL will not be able to
575+
load source changes.
576+
581577
As this is a Duct application, we'll need a `duct.edn` file. This will
582-
contain the three modules we added to the project's dependencies.
578+
contain the two modules we added to the project's dependencies.
583579

584580
.duct.edn
585581
[,clojure]
586582
----
587583
{:system
588584
{:duct.module/logging {}
589-
:duct.module/sql {}
590-
:duct.module/web {}}}
591-
----
592-
593-
Will this minimal configuration work? Let's find out.
594-
595-
[,shell]
596-
----
597-
duct --main
598-
✗ Initiating system...
599-
Execution error (ExceptionInfo) at integrant.core/unbound-vars-exception (core.cljc:343).
600-
Unbound vars: jdbc-url
601-
602-
Full report at:
603-
/tmp/clojure-14769356862243778775.edn
604-
----
605-
606-
Oh dear, it looks like there's a configuration var, `jdbc-url`, that has
607-
not been assigned a value. But where did it come from?
608-
609-
In this case it came from the `:duct.module/sql` module. Libraries can
610-
add their own vars by using Integrant's keyword annotations. We can see
611-
these new vars if we check the `--help`.
612-
613-
[,shell]
614-
----
615-
$ duct --help
616-
Usage:
617-
clojure -M:duct [--main | --repl]
618-
Options:
619-
-c, --cider Start an NREPL server with CIDER middleware
620-
--init Create a blank duct.edn config file
621-
-p, --profiles PROFILES A concatenated list of profile keys
622-
-n, --nrepl Start an NREPL server
623-
-m, --main Start the application
624-
-r, --repl Start a command-line REPL
625-
-s, --show Print out the expanded configuration and exit
626-
-v, --verbose Enable verbose logging
627-
-h, --help Print this help message and exit
628-
--jdbc-url JDBC-URL The JDBC database URL
629-
--port PORT The HTTP server port (default: 3000)
630-
----
631-
632-
At the bottom we can see that the modules have added two new options:
633-
`--jdbc-url` and `--port`. The server port has a default value of 3000,
634-
but there's no obvious default for a database URL, at least not one
635-
that will suit every project.
636-
637-
However, we can add own own default by updating the configuration.
638-
639-
.duct.edn
640-
[,clojure]
641-
----
642-
{:vars {jdbc-url {:default "jdbc:sqlite:todo.db"}}
643-
:system
644-
{:duct.module/logging {}
645-
:duct.module/sql {}
646585
:duct.module/web {}}}
647586
----
648587

649-
Now when we run the application we get a more promising result.
588+
We can now start the application with `--main`.
650589

651590
[,shell]
652591
----
653592
$ duct --main
654593
✓ Initiating system...
655-
2024-11-25T02:51:08.268Z :warn :duct.migrator.ragtime/missing-file {:path "migrations.edn"}
656594
2024-11-25T02:51:08.279Z :report :duct.server.http.jetty/starting-server {:port 3000}
657595
----
658596

659-
The application warns about a missing `migrations.edn` file, but starts
660-
up the web server. The web application should now be up and running at:
597+
The web application should now be up and running at:
661598
http://localhost:3000/
662599

663600
Visiting that URL will result in a '`404 Not Found`' error page, because
664601
we have no routes defined. The error page will be in plaintext, because
665602
we haven't specified what _features_ we want for our web application.
666603

667604
We'll fix both these issues, but before we do we should terminate the
668-
application with Ctrl-C and make a `src` directory.
669-
670-
[,shell]
671-
----
672-
mkdir -p src/todo
673-
----
674-
675-
IMPORTANT: The source directory must be created before running the REPL.
676-
This is because Clojure looks for source files in the Java classpath,
677-
and directories that don't exist yet will be omitted from this.
678-
679-
Then we'll start a REPL. We'll keep this running while we develop the
680-
application.
605+
application with Ctrl-C and start a REPL. We'll keep this running while
606+
we develop the application to avoid costly restarts and to give us a way
607+
of querying the running system.
681608

682609
[,shell]
683610
----
@@ -702,10 +629,8 @@ route to handle a web request to the root of our application.
702629
.duct.edn
703630
[,clojure]
704631
----
705-
{:vars {jdbc-url {:default "jdbc:sqlite:todo.db"}}
706-
:system
632+
{:system
707633
{:duct.module/logging {}
708-
:duct.module/sql {}
709634
:duct.module/web
710635
{:features #{:site}
711636
:routes [["/" {:get :todo.routes/index}]]}}}

0 commit comments

Comments
 (0)