https://github.com/ilevd/hugsql-inline-plugin
Inline SQL parameters to SQL query string
https://github.com/ilevd/hugsql-inline-plugin
clojure hugsql inline
Last synced: 7 months ago
JSON representation
Inline SQL parameters to SQL query string
- Host: GitHub
- URL: https://github.com/ilevd/hugsql-inline-plugin
- Owner: ilevd
- Created: 2022-11-22T10:33:11.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-11-26T07:34:54.000Z (about 3 years ago)
- Last Synced: 2025-04-29T20:19:23.645Z (9 months ago)
- Topics: clojure, hugsql, inline
- Language: Clojure
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# hugsql-inline-plugin
[](https://clojars.org/org.clojars.ilevd/hugsql-inline-plugin)
[HoneySQL](https://github.com/seancorfield/honeysql#format) allows you to format the query as a
string with no parameters (e.g. to use the SQL statement in a SQL console)
by passing `:inline true` as an option to sql/format:
```clojure
(sql/format {:select [:a :b :c]
:from [:foo]
:where [:= :foo.a "baz"]}
{:inline true})
=>
["SELECT a, b, c FROM foo WHERE foo.a = 'baz'"]
```
The purpose of this plugin is to do the same for [HugSQL](https://github.com/layerware/hugsql).
Just require the library in namespace to load it before using HugSQL:
```clojure
(ns yournamespace.core
(require [husql-inline-plugin.core]))
```
And use it with `:inline true` option:
```clojure
(hugsql/sqlvec "SELECT :sql:sql, :i*:cols FROM table WHERE id IN (:v*:ids) AND t = :t:tuple AND ts = (:t*:tuple-list)"
{:inline true}
{:sql "count()"
:cols ["id" "name"]
:ids [10, 20, 30]
:key :keyword
:tuple ["string" true 104 nil]
:tuple-list [[1 "a"] [2 "b"]]})
=>
["SELECT count(), id, name FROM table WHERE id IN (10,20,30) AND t = ('string',TRUE,104,NULL) AND ts = ((1,'a'),(2,'b'))"]
```
And without `:inline` option it would be:
```clojure
(hugsql/sqlvec "SELECT :sql:sql, :i*:cols FROM table WHERE id IN (:v*:ids) AND t = :t:tuple AND ts = (:t*:tuple-list)"
{:sql "count()"
:cols ["id" "name"]
:ids [10, 20, 30]
:key :keyword
:tuple ["string" true 104 nil]
:tuple-list [[1 "a"] [2 "b"]]})
=>
["SELECT count(), id, name FROM table WHERE id IN (?,?,?) AND t = (?,?,?,?) AND ts = ((?,?),(?,?))"
10
20
30
"string"
true
104
nil
1
"a"
2
"b"]
```
## License
Copyright © 2022 ilevd
This program and the accompanying materials are made available under the
terms of the Eclipse Public License 2.0 which is available at
http://www.eclipse.org/legal/epl-2.0.