Comments (12)
Thanks @rcanepa I'm also doing something similar
from hugsql.
@csummers Is this feature supposed to work for UPDATE
statements too? Postgres also supports this.
from hugsql.
This happens because statements executed with execute
(:!
in HugSQL) are not expected to return result sets. You can get around this issue by using :?
for your insert w/ returning statements.
However, I'm going to keep this open. The HugSQL docs should indicate this, I should add a test to show this, and I'm thinking about adding a command type that would indicate this. Also, this is tangentially related to issue #8.
from hugsql.
Hi @sthomp, I use that pattern (:i*:fields)
in combination with something like this:
(s/defn create-office :- {s/Keyword s/Uuid}
[db :- ConnectionMap
office :- schemas/Office]
(let [office (select-keys office schemas/office-db-fields) ;; remove read only fields
fields (map name (keys office)) ;; get fields as strings
values (vals office) ;; get values
sql-args {:fields fields
:values values}]
(execute! db :insert-office sql-args)))
from hugsql.
I can confirm this bug. I noticed it yesterday. My exception was "Received result when none was expected"
Using the latest version of hugsql, and funcool/clojure.jdbc adapter.
from hugsql.
@csummers great!. I can confirm that it solves the problem. All I had to do was change my query to something like this:
-- :name insert-contact! :? :1
-- :doc Insert a contact record.
INSERT INTO contacts
(:i*:fields)
VALUES
(:v*:values)
RETURNING id;
Thanks!
from hugsql.
As of the 0.4.0, there is a :command
type of :returning-execute
, or :<!
for short. This still executes as a query like :?
, but provides a bit more semantic value. See Insert for an example.
from hugsql.
Excellent!... I will update my code and let you know if I something doesn't work!... Keep the good work!!
from hugsql.
Just came across this issue and wanted to suggest adding an example to the Insert examples of how to insert with dynamic columns (ie: the (:i*:fields)
notation used above). All the current examples use fixed columns.
from hugsql.
Thanks for the suggestion. I could add a couple of examples to this effect. I think a likely scenario instead of the separate fields and values vectors would use a hashmap of {"field1" "value1"...}
. This is hinted at with the generic update example in the Clojure Expressions portion of the docs.
from hugsql.
That would be really nice. The {field value ..
syntax is probably the best feature about Korma that other libraries are missing
from hugsql.
Works with upsert using INSERT ON CONFLICT statement as well, if there was any doubt.
from hugsql.
Related Issues (20)
- Optional null parameters HOT 1
- Way to get generated SQL without executing? HOT 1
- Add support for next.jdbc.sql/insert-multi! HOT 1
- Avoid calling apply in 'hugsql.adapter.clojure-java-jdbc' HOT 5
- Incorrect Arities Shown in Docs for def-fb-fns HOT 1
- HugSql fails during AOT compilation with depstar HOT 4
- Switch to newer groupId of next.jdbc dependency in hugsql-adapter-next-jdbc HOT 1
- How to use a function from the database? HOT 2
- Migration fails if a comment is present on line with semicolon HOT 2
- Babashka support HOT 2
- No comments in doc on mobile? HOT 1
- Using classpath resource sql functions breaks cider HOT 3
- Hugsql 0.5.3 still requires SQL files on uberjar compilation (with leiningen) HOT 1
- strange key with jsonb HOT 3
- Should hugsql switch to next.jdbc by default ? HOT 2
- Cannot look up by UUID HOT 2
- Bulk update? HOT 1
- Inline parameters
- Doesn't work with AOT compilation
- Migrations DSL HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hugsql.