does anyone know how to interpolate a vector of ids into jdbc/update!
e.g. I want my WHERE clause to be where id in ?
and then pass in a vector
You might be able to create a connection, and create parameters for that. I had a lot of trouble with this though.
You cannot
The underlaying java jdbc drivers expect arrays (not vectors)
So at the very least, you need to pass it an array not a vector
clojure.java.jdbc also uses setObject which if I recall doesn't work right with arrays even if you pass one in
I believe that is overridable though
@ccann HoneySQL takes care of that for you (by building the appropriate where id in (?,?,?,?,..,?)
clause given your vector of IDs.
@seancorfield Iām working on a legacy project where we only have jdbc pulled in and trying to hotfix something
but definitely would prefer to use honeysql
If you are using PostgreSQL and next.jdbc
you might be able to do this via the array syntax -- see the PostgreSQL Tips and Tricks in the next.jdbc
docs.
But I think with clojure.java.jdbc
you're out of luck in that case.
if your vector gets too large, you'll quickly run into parameter count limits (for PG it's something like Short/MAX_VALUE
). but you can do something like below to get around that:
(j/update! db-conn :my-table ["id = ANY(?)" (into-array TheProperClass my-ids)])
@ddouglass Does that work with clojure.java.jdbc
? I know it works with next.jdbc
(that syntax is what is recommended in the next.jdbc
Tips & Tricks for PostgreSQL)
@seancorfield it does. Weāre currently using clojure.java.jdbc
and that was a sanitized chunk of code from one of our apps
Wishing a good day to fellow Clojurians š±
Does anyone know a recurrence implementation in Clojure? (as defined by https://tools.ietf.org/html/rfc5545#section-3.3.10) Or maybe in Java[Script].
Thinking about a plain rule parsing / compiling for starters. They look like RRULE:FREQ=WEEKLY;UNTIL=20110701T170000Z
Iāve found http://github.com/jakubroztocil/rrule, but I hope it could be done both easier and simpler, in like 200 lines of thoughtful Clojure code.
UPD:
Iāve been advised to use spec or malli to build a parser. Canāt say yet if thatās a good idea or not.
Does anyone here recall a recent call for an upcoming virtual Clojure conference? Maybe within the past 30 days. Seems like they were asking for ~20 minute talks. I can't remember if I saw it here, on twitter, reddit, ... too many platforms.
Thanks! I tried euroclojure, clojuretre, clojureD,....
is anyone aware of a DSL/macro library for Clojure bit operations?
idk about you but I find (unchecked-byte (bit-and (bit-shift-right inv 8) 16rff)
way harder to read than the Java equivalent
seems like you could get pretty far with a few well chosen defs
yeah, Iāll probably whip something up but curious to see if anyone else has dealt with this before š
|
, >>
, <<
are all valid function names
also why use 16rff instead of 0xff?
I thought that was not a thing in Clojure?
ahh, itās 0bxxxx
thatās not a thing, I misremembered, thanks!
user=> (= 255 0xff 16rff 2r11111111)
true
forgot to include 0377 above :D
octal, everyoneās favorite š
@schmee an idea:
(ins)user=> (def |b unchecked-byte)
#'user/|b
(ins)user=> (def |& bit-and)
#'user/|&
(ins)user=> (def |>> bit-shift-right)
#'user/|>>
(ins)user=> (|b (|& (|>> 292928 8) 0xff))
120
neat!
actually it works without the | on every name, I didn't realize &
was a valid function name but it is
I found https://github.com/rm-hull/infix, which I have seen before but it actually seems perfect for this
normally I wouldnāt consider using infix, but when I have to write pages of byte manipulation I might make an exception
having done most of my bit fiddling in assembly, I find breaking the ops into one per line more helpful than infix :D
but ymmv clearly
appreciate the input! :thumbsup:
as a reader of code, I'd rather review a java file than infix in the middle of a clojure file
yeah Iām not sold on it either, but Iāll give it a try and see how it pans out
Nice. Thanks!
Cuteā¦ I thought that the special form would get upset with this, but it doesnāt
(def & bit-and)
(defn f [& b] (& (first b) (second b)))
=> (f 3 9)
1
right, I think this is because [& ...]
is a special case in arg list parsing rather than a special form
since it's not used in call position
though (special-symbol? '&)
does return true
any Clojure projects out there that actually want Hacktoberfest participation?
For all practical purposes the right data structure for my problem is nested vectors. Except one thing: it needs a small piece of data attached that I want to lookup by it's key. Is it okay to put that into metadata, or should I force everything to be a map with 2 keys (data and a vector with maps of same shape)?
it might help to see an example data value, but one is the data you are considering putting in meta data actually meta data?
example:
=> {:grid [[{:grid [[{:grid [[{}
{}]]
:cursor [311708 475413]}]
[{:grid [[{}]
[{:grid [[{}
{}]]
:cursor [121699 68040]}
{:grid nil
:cursor [930988 26115]}]]
:cursor [136580 790398]}]]
:cursor [162873964 1315]}
{}]]
:cursor [42984 203305]}
the data I'm considering putting is not a meta data, it's pretty much very important data
but this structure makes lookups and updates hard, since I have to switch maps and vecs all the time, instead of doing assoc-in
/ get-in
using only coordinates
why not just make a function that looks like assoc-in
/ get-in
but works with these structures?
that's what I did for now
I just don't like it. It could be get-in
, but it has to be a separate function that interposes items with :grid
a common problem I feel like I see a lot is entangling the kind of logical structure of data with the physical structure.
one way this happens a lot is people writing games with grids try to represent the logical grid structure as a physical nesting of vectors, since that is the physical structure that most closely kind of looks like a grid
but a grid is just an index
a way to look up values by column, row, and maybe a combination of column and row
and once you treat it as a general index/lookup function you can start hanging other data in there and other indices and ways to do lookups
I concur with @hiredman
so the common advice is to make it a map with a pair [col, row] as keys
and depending on what you are doing that might be enough, but it isn't a fully general indexing system (you can't lookup all the items in a colum or all the items in a row, etc)
looks like nested vectors is the more flexible then š
absolutely not
well, for you grid example, query individual columns or row is trivial
I think focusing on the data type and what abstract operations it should fulfill is a good idea. you can then change the underlying implementation as needed depending on usage and performance
well, for all the uses I have nested vectors beat maps. I need to know last row. Given a row, I need to know last column. In the app there will A LOT of such data structures, so memory is also concern
but you can't hang any additional data anywhere, and you can't efficiently do inverted queries "give me all the column ids that a value bar somewhere in them"
I don't have such use case
"Except one thing: it needs a small piece of data attached that I want to lookup by it's key."
That one thing is "given coordinate path, I want to lookup a cursor at that path"
poor wording in the initial description, sorry
updates another place where conflating the logical structure with the physical structure makes things tricky
it is a lot easier to update a "flat" index (thing a normalized database schema) then a deeply nested tree structure
But I do have nesting, it's not a matrix NxM, it's a rows of varying length, where every item is itself a rows of varying length
that is literally the description of the logical structure of data in a graph database
where the data itself is stored in a flat index structure
hmm
Is there a way with tools.deps to list all dependencies (including transitive ones)? I want to be able to search for a specific dependency to see if it's included in my classpath?
clj -Stree
-Stree Print dependency tree
from clj --help
So I noticed that a library I was using (cljs-ajax) has deprecated EDNĀ as a HTTP request format in favor of Transit, which got me thinking: what are the downsides of using EDN over HTTP? And how is Transit better?
cool, thanks for the elaborate response :)
(so you know where to find help with that in the future)
https://github.com/JulianBirch/cljs-ajax/issues/47#issuecomment-51251520 Couldn't find where exactly EDN is "explicitly not recommended for browser API" though.
Another bit of useful information: https://groups.google.com/g/clojure/c/9ESqyT6G5nU/m/2Ne9X6JBUh8J
alright, thanks
sounds to me like there arenāt any clear drawbacks to using EDN per se, except that there arenāt good parsers in most languages
I guess another drawback could be that thereās less tooling for e.g. routing or deep packet inspection for EDN payloads than for JSON
I think there were some other reasons. The one that I can remember is that compression is built into transit, which is nice to have.