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
14
votes
2 answers

how to have postgres ignore inserts with a duplicate key but keep going

I am inserting record data in a collection in memory into postgres and want the database to ignore any record that already exists in the database (by virtue of having the same primary key) but keep going with the rest of my inserts. I'm using…
THX1137
  • 903
  • 6
  • 15
12
votes
1 answer

How to avoid unresolved symbol with clj-kond when using hugSQL def-db-fns macro?

I write Clojure using the VS Code Calva extension, which uses clj-kondo to perform static analysis of my code. I'm using HugSQL to create Clojure functions from SQL queries and statements. I'm aware that I could handle the database connection and…
jackdbd
  • 4,583
  • 3
  • 26
  • 36
9
votes
1 answer

Handling nil parameters with Clojure/Hugsql

I'm using Hugsql with Clojure to access a Postgresql db. Several of my database tables have optional columns - for a simple example consider a "users" table with various address columns - address1, address2, city, etc. When I write the Hugsql query…
5
votes
2 answers

Log sql statments/queries executed by HugSQL

I want to log all SQL strings executed by HugSQL. I looked through the docs, but couldn't find anything. Whats the recommended way?
Frederik Claus
  • 574
  • 4
  • 15
4
votes
1 answer

PGobject type conversion in Clojure

I'm having trouble with a type conversion problem in Clojure, using Hugsql. I'm new to Clojure and newer to SQL, and I'd appreciate any help I can get. We recently migrated our PostgreSQL db so one column is a json array instead of a string -- the…
emmagras
  • 1,378
  • 2
  • 18
  • 25
2
votes
1 answer

HugSQL Error: column "date_answer" is of type date but expression is of type character varying?

I am using clojure hugSQL to insert data into PostgreSQL database. I am trying to insert multiple rows into an answer table using :tuple* parameter. When passing a date I get the following error: Error: column "date_answer" is of type date but…
2
votes
2 answers

How to expand HugSQL parameter into multiple like statements

Does anyone know how this can be accomplished? (get-lists ["free" "food"]) -> Select name From Lists Where name like '%free%' and name like '%food%' I have tried: -- :name get-lists :? :* Select id, name from Lists where --~ (clojure.string/join…
MaDhAt2r
  • 75
  • 6
2
votes
2 answers

Casting Multiple Values in HugSQL or YesQL with Postgres

I'm trying to cast a list of ip addresses to ::inet but only the last element in the list gets converted. I've tried the following but nothing seems to work. select * from ip_addresses where address in (:addresses::inet) select * from ip_addresses…
BWStearns
  • 2,567
  • 2
  • 19
  • 33
1
vote
1 answer

HugSQL defined function not found

This will probably be very thin but I am running out of options... I am using clojure with hugsql and I am a true beginner with database tech. I am trying to call an user-defined function that a colleague has defined in the database. So, my problem…
1
vote
2 answers

Why am I seeing Parameter Mismatch error in Luminus (Clojure)?

Edit (fixed)... If you are following the Luminus guestbook tutorial or adapting parts of it, you may come across an error like Parameter Mismatch: :name parameter data not found., and it may not go away, regardless of what parameters you use. You…
Matt Lally
  • 435
  • 1
  • 3
  • 13
1
vote
1 answer

Building WHEN clause with a clojure expression in hugsql

I have a database with a status entity that I'd like to be able to fetch in many different ways. As a result, I'd like to build the WHEN clause of my query based on the content of a map. For instance, like this: (get-status *db* {:message_id 2…
little-dude
  • 1,544
  • 2
  • 17
  • 33
1
vote
0 answers

Unable to mock HugSQL generated database functions with Midje

I'm having a problem mocking database access functions generated from HugSQL templates with the Conman helper library. These functions are defined at runtime like this: (conman/bind-connection *db* file) In my case, I'm unit testing this service…
Kristian Salo
  • 350
  • 3
  • 9
1
vote
1 answer

YesQL/pgsql "could not determine data type of parameter $1"

I'm trying to use NULL to reuse queries for both specific searches as well as returning index (basically implementing the idea discussed here http://dev.solita.fi/2015/12/29/SQL-in-applications.html). However, I'm getting ERROR: could not determine…
BWStearns
  • 2,567
  • 2
  • 19
  • 33
1
vote
0 answers

Avoid timezone changes with HugSQL

I have created an empty Clojure application where I read and write a date field to and from a database. The type of the column in MYSQL appears as DATETIME and in the application, I use the JDBC driver and clj-time to operate with dates. I have…
Jacob
  • 1,886
  • 2
  • 25
  • 40
1
vote
5 answers

Hugsql can not read my sql file

I am truely lost here. I have a very simple application. All it does is to insert a user into the user table in my Database. I using Postgres. The code is (ns signupper.db (:require [hugsql.core :as hugsql])) (hugsql/def-db-fns "sql/q.sql") Inside…
eitan
  • 59
  • 8
1
2