diff --git a/src/leiningen/new/yawt.clj b/src/leiningen/new/yawt.clj index 96976e9..6c1cc85 100644 --- a/src/leiningen/new/yawt.clj +++ b/src/leiningen/new/yawt.clj @@ -58,9 +58,11 @@ ["src/{{path}}/views.clj" (render "src/root_ns/views_webservice.clj" data)] ["dev/user.clj" (render "dev/user_webservice.clj" data)]]) +(defn get-sql-files [data] + ["migrations"]) + (defn get-postgresql-files [data] - ["migrations" - ["src/{{path}}/db.clj" (render "src/root_ns/db_postgresql.clj" data)]]) + [["src/{{path}}/db.clj" (render "src/root_ns/db_postgresql.clj" data)]]) (defn get-couchdb-files [data] [["src/{{path}}/db.clj" (render "src/root_ns/db_couchdb.clj" data)]]) @@ -72,6 +74,7 @@ (get-base-files data) (if (:webapp data) (get-webapp-files data)) (if (:webservice data) (get-webservice-files data)) + (if (:sql data) (get-sql-files data)) (if (:postgresql data) (get-postgresql-files data)) (if (:couchdb data) (get-couchdb-files data))))) @@ -91,14 +94,29 @@ (println "*** If neither 'webapp' or 'webservice' is specified, 'webapp' is assumed") (println "*** Specifying no options will default to use only 'webapp'")) +(defn add-webapp-default [options] + (if-not (or (some #{"webapp"} options) + (some #{"webservice"} options)) + (conj options "webapp") + options)) + +(defn add-sql-option [options] + (if (some #{"postgresql"} options) + (conj options "sql") + options)) + +(defn add-nosql-option [options] + (if (some #{"couchdb"} options) + (conj options "nosql") + options)) + (defn get-final-requested-options [requested-options] - (let [options (if (seq requested-options) - (set requested-options) - default-options)] - (if-not (or (some #{"webapp"} options) - (some #{"webservice"} options)) - (conj options "webapp") - options))) + (->> (if (seq requested-options) + (set requested-options) + default-options) + (add-webapp-default) + (add-sql-option) + (add-nosql-option))) (defn yawt "Creates a new YAWT (web app/service) project." diff --git a/src/leiningen/new/yawt/env-resources/dev/config.edn b/src/leiningen/new/yawt/env-resources/dev/config.edn index 13e6e27..ba4a45a 100644 --- a/src/leiningen/new/yawt/env-resources/dev/config.edn +++ b/src/leiningen/new/yawt/env-resources/dev/config.edn @@ -1,11 +1,11 @@ {:dev true -{{#postgresql}} +{{#sql}} :db {:host "localhost" :name "db_name" :port 5432 :username "username" :password "password"} - {{/postgresql}} + {{/sql}} {{#couchdb}} :db {:url "http://localhost:5984/" :username "username" diff --git a/src/leiningen/new/yawt/env-resources/repl/config.edn b/src/leiningen/new/yawt/env-resources/repl/config.edn index 7ffc40f..2655707 100644 --- a/src/leiningen/new/yawt/env-resources/repl/config.edn +++ b/src/leiningen/new/yawt/env-resources/repl/config.edn @@ -1,13 +1,13 @@ {:dev true :repl true :auto-start-server? true -{{#postgresql}} +{{#sql}} :db {:host "localhost" :name "db_name" :port 5432 :username "username" :password "password"} -{{/postgresql}} +{{/sql}} {{#couchdb}} :db {:url "http://localhost:5984/" :username "username" diff --git a/src/leiningen/new/yawt/env-resources/uberjar/config.edn b/src/leiningen/new/yawt/env-resources/uberjar/config.edn index aca4442..0997987 100644 --- a/src/leiningen/new/yawt/env-resources/uberjar/config.edn +++ b/src/leiningen/new/yawt/env-resources/uberjar/config.edn @@ -1,11 +1,11 @@ {:release true -{{#postgresql}} +{{#sql}} :db {:host "localhost" :name "db_name" :port 5432 :username "username" :password "password"} -{{/postgresql}} +{{/sql}} {{#couchdb}} :db {:url "http://localhost:5984/" :username "username" diff --git a/src/leiningen/new/yawt/project.clj b/src/leiningen/new/yawt/project.clj index 7cb3e74..c1665e5 100644 --- a/src/leiningen/new/yawt/project.clj +++ b/src/leiningen/new/yawt/project.clj @@ -25,10 +25,12 @@ {{#webservice}} [hiccup "1.0.5"] {{/webservice}} -{{#postgresql}} +{{#sql}} [org.clojure/java.jdbc "0.4.2"] - [org.postgresql/postgresql "9.4-1202-jdbc42"] [clojurewerkz/ragtime "0.4.0"] +{{/sql}} +{{#postgresql}} + [org.postgresql/postgresql "9.4-1202-jdbc42"] {{/postgresql}} {{#couchdb}} [com.ashafa/clutch "0.4.0"] @@ -44,9 +46,9 @@ {{#webapp}} [lein-cljsbuild "1.1.2"] {{/webapp}} -{{#postgresql}} +{{#sql}} [clojurewerkz/ragtime.lein "0.4.0"] -{{/postgresql}} +{{/sql}} [lein-pprint "1.1.1"]] {{#webapp}} @@ -88,10 +90,10 @@ :dev {:resource-paths ["env-resources/dev"] :dependencies [{{#webapp}}[com.cemerick/piggieback "0.2.1"]{{/webapp}} [pjstadig/humane-test-output "0.7.1"]] -{{#postgresql}} +{{#sql}} :ragtime {:migrations ragtime.sql.files/migrations - :database "jdbc:postgresql://localhost:5432/db_name?user=username&password=password"} -{{/postgresql}} + :database "jdbc:{{#postgresql}}postgresql{{/postgresql}}://localhost:5432/db_name?user=username&password=password"} +{{/sql}} :injections [(require 'pjstadig.humane-test-output) (pjstadig.humane-test-output/activate!)]} :repl {:resource-paths ["env-resources/repl"] diff --git a/src/leiningen/new/yawt/src/root_ns/core.clj b/src/leiningen/new/yawt/src/root_ns/core.clj index 238bca4..b9e92d2 100644 --- a/src/leiningen/new/yawt/src/root_ns/core.clj +++ b/src/leiningen/new/yawt/src/root_ns/core.clj @@ -14,9 +14,9 @@ {{/webapp}} [edn-config.core :refer [env]] [prone.middleware :as prone] -{{#postgresql}} +{{#sql}} [{{root-ns}}.db :as db] -{{/postgresql}} +{{/sql}} [{{root-ns}}.routes :refer [main-public-routes api-routes]] [{{root-ns}}.middleware :refer [wrap-exceptions not-found-handler]])) @@ -37,14 +37,14 @@ (when (env :dev) (info "Running in :dev environment.")) {{/webservice}} -{{#postgresql}} +{{#sql}} (try (db/init!) (info "Database access initialized.") (catch Exception ex (throw (Exception. "Database not available or bad connection information specified." ex)))) -{{/postgresql}} +{{/sql}} (info "Application init finished."))