Questions tagged [hugsql]

A Clojure library for embracing SQL.

  • HugSQL is of the opinion that SQL is the right tool for the job when working with a relational database.
  • HugSQL uses simple conventions in your SQL files to define (at compile time) database functions in your Clojure namespace, creating a clean separation of Clojure and SQL code.
  • HugSQL supports runtime replacement of SQL Value Parameters (e.g., where id = :id), SQL Identifiers (i.e. table/column names), and SQL Keywords. You can also implement your own parameter types.
  • HugSQL features Clojure Expressions and Snippets providing the full expressiveness of Clojure and the composability of partial SQL statements when constructing complex SQL queries.
  • HugSQL has protocol-based adapters supporting multiple database libraries and ships with adapters for clojure.java.jdbc (default) and clojure.jdbc

From http://www.hugsql.org/

25 questions
1
vote
1 answer

Use custom function with HugSQL

I am using PostgreSQL version 10 on macOS 10.12.6 and would like to use a custom plpgsql function in a query which shall be accessible to HugSQL. The following ansatz works correctly: -- :name do-something! :! :1 CREATE OR REPLACE FUNCTION helper() …
user8472
  • 3,268
  • 3
  • 35
  • 62
1
vote
1 answer

Force hugsql query functions to throw an error when they return the wrong number of results

Using Clojure and hugsql. I define my queries as such. -- :name query-should-return-one-but-returns-multiple -- :result one -- :command :query SELECT v.id FROM some_table v; After using def-db-fns, this will create a function…
amoe
  • 4,473
  • 4
  • 31
  • 51
0
votes
0 answers

In HugSQL SQL, Chinese parameters are replaced with question marks

在HugSQL SQL中的中文参数,被替换成了问号。 In HugSQL SQL, Chinese parameters are replaced with question marks. -- :name save-message-1! :! :n -- :doc creates a new message INSERT INTO guestbook (name, message, timestamp) VALUES ('姓名', '消息测试', '2022-03-21…
Grant
  • 1
0
votes
1 answer

accessing map value by namespaced keyword

given a map in clojure, {::my-func {:meta {...}, :fn #function[hugsql.core/db-fn*]}, automagically defined, how do I retrieve :fn value? I've tried (get-in map [:my-func :fn]) (get-in map [::my-func :fn]) (get-in map [:current-namespace/my-func…
Dudley Craig
  • 157
  • 1
  • 5
0
votes
1 answer

Nested namespaced keys in HugSQL Query

I have a nested map with namespaced keys like this: { :model.person/primary {:model.person/name "John Smith"} } Instead of simpliying this into a flat map I'd like to pass it straight through to a HugSQL function. The docs say HugSQL supports a…
nogridbag
  • 3,521
  • 4
  • 38
  • 51
0
votes
1 answer

Using HugSQL to INSERT multiple rows at once into PostgreSQL table with ON CONFLICT DO UPDATE

I'm working with PostgreSQL and wanting to INSERT multiple rows at once with an ON CONFLICT DO UPDATE statement. I've got something like this: -- :name add-things! :! :n INSERT INTO my_table ( p, foo ) VALUES :tuple*:values ON CONFLICT (p) DO…
user2609980
  • 10,264
  • 15
  • 74
  • 143
0
votes
1 answer

How do I convert the returned maps to json csv in HugSQL results

I am trying to use HugSQL to select some records from my DB and I get back the records I have few problems when I try this code: f/attempt-all [_ (println "Getting DB records") db-records (oracle-db/get-records my-db) ;hangs…
Tabber
  • 151
  • 3
  • 16
0
votes
1 answer

Test error: how to use :id?

I'm trying to do this for the first time in luminus, h2, hugsql and clojure. The insert statement works fine when entered in a SQL client connected to the h2database, but fails in code. It seems it has to do with the WHERE id = :id clause of the…
Luis
  • 1,236
  • 5
  • 22
  • 31
0
votes
2 answers

match all key/val pairs

Original query: -- :name select*-list -- :command :query -- :result :raw -- :doc Select all lists. -- parameters() SELECT * FROM list; I want to pass in arbitrary key/val pairs and get matching results. For example: (select*-list db-spec {:name…
deadghost
  • 5,017
  • 3
  • 34
  • 46
0
votes
1 answer

Clojure getting data from db, transform and print into console

I have the following task. I need to create a console application which takes one param which is the number of data to generate. The data is person address and name. I create a table adress with state, city, zip-code fields. I also create a table…
1
2