Skip to content

Instantly share code, notes, and snippets.

@codonnell
Created June 22, 2020 11:32
Show Gist options
  • Save codonnell/51d87e6a9f85607525142c21e8721e1a to your computer and use it in GitHub Desktop.
Save codonnell/51d87e6a9f85607525142c21e8721e1a to your computer and use it in GitHub Desktop.
Honeysql + clojure.java.jdbc returning example
(ns returning-example.core
(:require [clojure.java.jdbc :as jdbc]
[honeysql.core :as sql]
[honeysql.format]
[honeysql-postgres.format]))
(def db-spec
{:dbtype "postgresql"
:dbname "postgres"
:user "postgres"
:password "password"
:port 25432})
(comment
(jdbc/execute! db-spec ["CREATE TABLE my_table (id serial primary key, v text)"])
(jdbc/query db-spec ["SELECT * FROM my_table"])
(jdbc/query db-spec (sql/format {:insert-into :my_table
:values [{:v "test"}
{:v "test2"}]
:returning [:id :v]}))
)
{:deps
{org.clojure/java.jdbc {:mvn/version "0.7.11"}
honeysql {:mvn/version "1.0.444"}
nilenso/honeysql-postgres {:mvn/version "0.2.6"}
org.postgresql/postgresql {:mvn/version "42.2.12"}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment