Morning, I am looking for an example of how to add an as
alias to a subquery?
Like this?
user=> (sql/format {:with [[:query {:select [:foo] :from [:bar]}]]})
["WITH query AS (SELECT foo FROM bar)"]
<https://github.com/seancorfield/honeysql/blob/develop/test/honeysql/format_test.cljc#L62>
If not, maybe some of the tests might give a clue?
Thx @dharrigan @borkdude. I think that {:with …}
example might work but thru trial and error I found this worked:
{:select [:sub.id]
:from
[[{:select [:id :name1 :name2]]
:from [:table1]
:modifiers [:distinct-on :name1 :name2]
:order-by [:name1 :name2]} :sub]]}
Suitably anonymised table names and columns plus sub query is simplified.fantastic! 🙂
Sorry, the video wasn't related to your question, I just posted it here because it was about honeysql
Information is good, more information is better!
I need to look at babashka as I think it may solve a bunch of issues with observability and debugging in my current client.
Hi there. Quick question about using HoneySQL/next.jdbc: Is there a nice or recommended way to handle conversion between dashes and underscores in keywords? There's :allow-dashed-names true but that's just allowing HoneySQL to include dashes in the formatted string. Thanks in advance.
In my code, I use dashes for keywords, i.e., tenant-id
, that will automatically convert to tenant_id
on the rendered SQL that goes out to the db.
Not had an issue.
I actually showed that in the video earlier today and wondered where this was done. Later I saw this is in the format.clj namespace
Ah so it's automatic with no configuration I assume?
not had to configure anything 🙂
Splendid! Thanks a lot 🙂
you're most welcome
I recommend using v2 (the alpha one): it has cool new features, like passing in maps as values
Yes, I agree. If you're starting off on something new 🙂 I don't think it'll be that long before 2.0.0 Alpha2 becomes a beta, then a final 🙂
I've converted my applications to use honeysql v2 (on branches atm) works wonderfully well.
and easier too!
> passing in maps as values How do you mean sorry?
(helpers/values [{:a 1 :b 2}])
you must omit the column names if you are using that though
because they will be inferred from the maps
check the video above if you want to know how this works :)
I think that's already available in the current version? At least that's what the doc is telling me:
(-> (insert-into :properties)
(values [{:name "John" :surname "Smith" :age 34}
{:name "Andrew" :surname "Cooper" :age 12}
{:name "Jane" :surname "Daniels" :age 56}])
sql/format)
oh really? I thought that was new, sorry
but totally agree that it is awesome to use 😄
@seancorfield would it be possible for honeysqlv2 support create/edit/drop materialized view
? which is the same as create view
for postgresql?
would be supar handy
I would replace this (-> (sql/raw (str "refresh materialized view " view " with data"))
and (-> (sql/raw (str "create materialized view " view " with data"))
I can raise a jira if you are willing, no issues if not 🙂
jira!?
wtf
I'm too "enterprisey"
Sure, create a GH issue so I don't forget.
w00t
done. thank you.
Quick Q @dharrigan Is create view
different from create materialized view
?
Ah, yes, different syntax. So many options.
:thumbsup:
Not suggesting perhaps to support all the options, maybe even refresh materialized view <blah> with [no] data
would be great 🙂