Skip to content

Latest commit

 

History

History
62 lines (43 loc) · 1.4 KB

hugsql.org

File metadata and controls

62 lines (43 loc) · 1.4 KB

REF: https://www.hugsql.org/#start

Keys

:namename of function to create
:docdocstring of funciton
:commandunderlying command to run
:resultexpected result type

:snip, :meta, :require (see docs)

Commands

:?query
:!any statement}
:<!returning

Result

:1one
:*many
:nnumber of rows affected
:rawpassthru result

Parameter Types

:param-name
  • or -
:param-type:param-name

Deep Get

The parameter name can optionally use a “deep get” syntax to drill down into a parameter data structure. This syntax consists of keywords and integers joined by a period .. A keyword is a key for a hashmap. An integer is a vector index. For example:

-- first-employee :? :1
select * from employees where id = :value:employees.0.id
(first-employee db {:employees [{:id 1} {:id 2}]})
;=> {:id 1 :name "Al"}

Returning ID of inserted

It is often the case that you want to return the record just inserted or at least the auto-generated ID.

You can specify your SQL insert statement command type to be :returning-execute, or :<! for short:

-- :name insert-into-test-table-returning :<!
-- :doc insert with an sql returning clause
insert into test (id, name) values (:id, :name) returning id