This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-10-17
Channels
- # announcements (2)
- # aws (44)
- # beginners (96)
- # calva (10)
- # cider (7)
- # cljdoc (5)
- # cljsrn (2)
- # clojure (38)
- # clojure-dev (19)
- # clojure-europe (6)
- # clojure-italy (16)
- # clojure-nl (10)
- # clojure-norway (44)
- # clojure-spec (7)
- # clojure-uk (74)
- # clojurescript (133)
- # cloverage (1)
- # cursive (54)
- # datomic (78)
- # duct (11)
- # graalvm (5)
- # instaparse (4)
- # joker (3)
- # kaocha (5)
- # nrepl (2)
- # off-topic (10)
- # pathom (56)
- # pedestal (1)
- # reagent (7)
- # reitit (17)
- # shadow-cljs (144)
- # slack-help (2)
- # sql (35)
- # testing (5)
- # tools-deps (22)
- # vim (22)
- # xtdb (11)
I can do SELECT (<uuid> NOT IN (SELECT id FROM table));
. I'm not sure how to represent this in honey though. My first attempts are
{:select [(hdb/sql-fn :not-in field-id
{:select :id
:from :table})]}
but its erroring saying don't know how to create ISEQ from keyword{:select [:id] :from :table}
(this is why I tend to use the helpers instead of trying to construct the data structures directly!)
i need the t. I'm doing a sequence of checks for the UI for some data wrangling. So I need the info "this field isn't used in smart tasks" "this field isn't used in ..."
user=> (-> (select :id) (from :table))
{:select (:id), :from (:table)}
user=>
so the analogue is to select id not in table-1 as check-1, not in table-2 as check-2, etc
What is hdb
?
I'm not sure how to write that in HoneySQL either. It doesn't expect arguments to "functions" to be SQL statements, just expressions.
{:select [[(hdb/sql-fn :not-in field-id
{:select [:field-id]
:from [:svc.custom_fields]})
:custom-field]]}
thanks as always @seancorfieldHmm, I guess I was still doing something wrong locally then... This may be a place that the helper functions can't help...
user=> (-> (select [(sql/call :not-in "uuid" (-> (select :id) (from :table))) :custom_field]) (h/format))
["SELECT (? not in (SELECT id FROM table)) AS custom_field" "uuid"]
user=>
Where sql
is honeysql.types
. It's a place where the tagged literal form of call doesn't work (`#sql/call`).
@seancorfield it is possible to put a prefix in the generated table name from honeySql?
The "generated table name" is whatever you pass in as the table name, pretty much, so you already control it. I don't think HoneySQL should do much translation there.
well, the problem that I have is that, in some setups the tables has prefixes, and in others it don't , and the prefix can be any thing, so I would like to create generic sql sentences , but make table prefix dynamic
What do you mean by "prefix" here?
for example
ps_
as prefix and product
as table name , then the result would be ps_product
as the table name, the problem is that the prefix can be anything, but it is shared among all the tablesThat's an edge case caused by poor schema design. Not something HoneySQL should support, sorry.
If you write your generic sql in functions that take the prefix as the argument and use it to build the table names, you could at least minimize the duplication.
yeah, that's a possible solution, or hack into honeysql source , which on the other hand I would learn how it works 🙂
@vachichng I just pulled up the HoneySQL source and there is a dynamic variable you can bind: *name-transform-fn*
So you could try (binding [*name-transform-fn* #(str "ps_" %)] ,,,)
but I'm pretty sure that will transform all identifiers, not just table names.
I'm pretty sure HoneySQL doesn't distinguish between table names and other identifiers in the SQL. I guess you could have your name transform function look at the identifier and conditionally prefix it, if it is one of your tables -- but I think you'd run into problems if you have a column that matches any of those table names.
@seancorfield thank you for your time, I will have a look on that, for now, I will just run a script that renames the tables in the database, deleting the prefix
That would be my preference 🙂