This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-01-29
Channels
- # architecture (14)
- # beginners (184)
- # boot (25)
- # cider (23)
- # clara (9)
- # cljsjs (13)
- # cljsrn (5)
- # clojure (140)
- # clojure-austria (1)
- # clojure-dev (24)
- # clojure-greece (15)
- # clojure-italy (7)
- # clojure-nl (1)
- # clojure-norway (1)
- # clojure-sanfrancisco (10)
- # clojure-spec (39)
- # clojure-uk (28)
- # clojured (1)
- # clojurescript (26)
- # core-async (3)
- # cursive (13)
- # datomic (44)
- # docs (3)
- # emacs (31)
- # events (2)
- # figwheel (4)
- # fulcro (6)
- # graphql (2)
- # hoplon (5)
- # jobs (11)
- # juxt (4)
- # keechma (19)
- # leiningen (1)
- # off-topic (8)
- # om (8)
- # onyx (18)
- # parinfer (2)
- # re-frame (18)
- # reagent (24)
- # ring (4)
- # rum (2)
- # shadow-cljs (26)
- # sql (15)
- # timbre (6)
- # vim (2)
Can I just go on the record and say I hate ORMs? 🙂
https://blog.codinghorror.com/object-relational-mapping-is-the-vietnam-of-computer-science/ -- inspired by -- http://blogs.tedneward.com/post/the-vietnam-of-computer-science/
Clojure definitely helps make the choice to avoid ORMs, because of how well the language emphasizes programming with values
(let [db-uri "jdbc: "
_ (Class/forName "org.postgresql.Driver")
conn (java.sql.DriverManager/getConnection db-uri "foo" "bar")
stmt (.createStatement conn)
]
(.executeUpdate stmt "CREATE DATABASE foobar"))
With MySQL you'd specify :dbname "mysql"
which always exists and provide a user/password that has rights to create databases.
For the code you have above, I'd do that whole thing via java.jdbc
(which is how we do our DB creation).
(jdbc/db-do-commands {:dbtype "postgres" :dbname "" :user "foo" :password "bar"} "CREATE DATABASE foobar")
would probably work (empty :dbname
)...Yup, confirmed that works as expected (with MySQL, at least).
Interesting, PostgreSQL doesn't let you run CREATE DATABASE
in a transaction so you have to use this:
(jdbc/db-do-commands {:dbtype "postgres" :dbname "" :user "clojure_test" :password "******"} false "CREATE DATABASE foobar")
-- note the false
argument to disable transaction-wrapping!@souenzzo I maintain a lot of SQL applications with nothing more than a runner for sql-based migrations and HoneySQL
I like HoneySQL since a lot of the SQL I need is dynamic in nature (which tables to join against and such)
the Clojure community is possibly the most hostile towards ORMs that I've encountered, with the three most common solutions being "sql strings with a jdbc wrapper", honeysql (queries represented as data with a query compiler), and yesql/hugsql (sql is stored in sql files on the resource path)
although there is no reason you couldn't use a Hibernate or write your own ORM. It's probably a useful exercise to write your own ORM for the insights gained (in particular, why you probably don't need/want one)
Interesting, PostgreSQL doesn't let you run CREATE DATABASE
in a transaction so you have to use this:
(jdbc/db-do-commands {:dbtype "postgres" :dbname "" :user "clojure_test" :password "******"} false "CREATE DATABASE foobar")
-- note the false
argument to disable transaction-wrapping!