This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-07-27
Channels
- # admin-announcements (1)
- # aws-lambda (2)
- # beginners (48)
- # boot (231)
- # capetown (1)
- # cider (35)
- # cljs-dev (25)
- # cljsrn (74)
- # clojure (273)
- # clojure-austin (2)
- # clojure-berlin (5)
- # clojure-hk (1)
- # clojure-poland (1)
- # clojure-russia (50)
- # clojure-spec (63)
- # clojure-uk (58)
- # clojurescript (51)
- # cursive (5)
- # datomic (39)
- # defnpodcast (3)
- # dirac (13)
- # editors (6)
- # emacs (3)
- # hoplon (86)
- # jobs (2)
- # lein-figwheel (1)
- # liberator (3)
- # off-topic (10)
- # om (113)
- # onyx (34)
- # protorepl (29)
- # re-frame (2)
- # reagent (8)
- # remote-jobs (1)
- # ring (4)
- # test-check (42)
- # untangled (31)
- # yada (2)
@dpsutton: re: simple-query — that’s a pretty old version of java.jdbc (0.4.2)… the API has changed quite a bit since then… You mind find folks running into conflicts if they’re on a more recent version in their code already.
(although now I look at your code it looks like you don’t expose any options or anything beyond using java.jdbc/query
so you will likely be fine)
Given how query
works, you could just pass ~db
directly without using with-db-connection
— any reason you used the latter?
it's really worked out well. we've built a whole reporting website for a rewrite that we are building
Nice! Always glad to see someone using java.jdbc heavily 🙂
Yeah, I’m the primary maintainer.
I ported it from the old monolithic contrib back in 2011...
It’s gone through several API rewrites since then
We use it with MySQL at World Singles — supporting millions of queries/updates/etc every day.
i see you use 0.6.2-alpha2
as the current release. Is it standard for a production release to be an alpha?
But I test it with MS SQL Server, with both the MS Type 4 driver and the jtds driver.
0.6.1 is the stable version
0.6.2 only really has optional clojure.spec support in it
I've seen people say to use the MS Type 4 driver but i've got the 3 in there (I think) and it has worked out well
Well, the few other minor things in 0.6.2-alpha1 compared to 0.6.1 https://github.com/clojure/java.jdbc/blob/master/CHANGES.md
The new feature we’re starting to use heavily is :qualifier
so we can produce namespace-qualified keys directly from a query
...
But, yeah, any version I release is likely already in heavy production use at work.
i'm not sure how common it is but i built a little function to remove the prefixes of column names
Many of the changes since 0.2.x have been driven by what we need at World Singles.
Well, you could use :identifiers
to specify a function to rename columns as they’re turned into keywords.
The default is just clojure.string/lower-case
but you could pass any function that, given a string, produces a new string (then the library turns it into a keyword).
So a variant of your remove-prefix
would work:
(defn remove-prefix [prefix]
(fn [s] (clojure.string/replace s (re-pattern (str "^" prefix)) "")))
(java.jdbc/query db-spec ["select * from sometable"]
{:identifiers (remove-prefix "sometable")})
Something like that...
(and your first
of the result set could be (query ~db [~sql ~@params] {:result-set-fn first})
, just FYI)
@seancorfield: is it possible to do Oracle stored procedures calls with java.jdbc? (don't ask why I want it, it's not my choice :)
If you can call them via SQL, yes, it should be possible. There’s no special support for stored procs (yet).
There’s an open issue in JIRA for it http://dev.clojure.org/jira/browse/JDBC-48
seeing the syntax it almost removes the necessity for the macros. didn't realize it could be so succinct
@dpsutton: We have a lot of places where we just call (query db-spec ["select * from …" p1 p2])
and that’s it.
yeah. our reporting tool is basically just a read only display some tables and do some manipulations
didn't know your library had that style syntax. I was thinking it required the jdbc/with-db-connection .... stuff
@sgdread: The main obstacle to JDBC-48 is that I just don’t have any exposure to stored procs so I’m not confident about being able to design/test the feature properly 🙂
@dpsutton: You only need with-db-connection
if you want to get a connection and reuse it across multiple statements, otherwise it’s automatic.
And we use a connection pooling library (c3p0) anyway so it’s low overhead to get & close a "connection" on every single query.
well sean, you run a nice project there, great documentation, and you are super helpful on slack. thanks so much
Always looking for feedback to make it better!
http://stackoverflow.com/questions/6330688/connecting-to-microsoft-sql-server-using-clojure
it might be nice if there was some article, blogpost, whatever that could replace that at the top of google
@seancorfield: If you're interested in test cases, I might get some samples of Oracle sprocs with parameters binding. I also know how to deal with them in Java and can share some samples. Oracle has express edition of the database.
Is there a Docker image I can easily use? That's how I test Postgres. I can't realistically install Oracle on any of my machines here.
@dpsutton: Hard to compete with SO on Google scores...
you could create a provisioning script that loads up oracle, exposes some ports and then you can hit it from your normal machine
then vagrant destroy
wipes that thing away, but the provisioning script is still alive
best thing is that these scripts can be checked in. So you could have a subfolder in jdbc with vagrant files for machines with different db types and a standard database schema/ some data
@dpsutton: I kind of skipped Vagrant and went straight to Docker 🙂
did vagrant so that all of my school projects still have a version controled environment next to the code
With that SO I downvoted the older answer and upvoted the newer one so at least the outdated version will be lower.
I'll try to find time tomorrow to edit that answer to make it more up to date and simpler (it's way more complex than it needs to be!).
(added to OneNote!)
Our stack has a lot of moving parts so Dockerizing it really helps. To run our stack locally you need: MySQL, MongoDB, Discovery (a search engine), Redis, Tomcat, and multiple standalone Clojure apps that all communicate...
We'll be adding DynamoDB to that mix soon. Docker makes that possible without having developers installing, configuring, and running it all individually.
And we're also the crazy company that has a lot of ColdFusion code and we run Clojure inside that 🙂
I built a bridge library back in 2011 and it's core to our platform...
Hahaha 🙂
FYI, ColdFusion calling Clojure https://github.com/seancorfield/datamapper/blob/master/Service.cfc#L70-L77
(modern CFML looks like JS -- the WS "object" is actually a Clojure namespace so WS.data.find_by_keys( name, args, orderBy )
is really just (WS.data/find-by-keys name args orderBy)
is there already a java interop so that this isn't as crazy as it seems or did you really build some crazy stuff here?
The "magic" code relies on two key things: Clojure's Java API and CFML onMissingMethod()
so we can call "non-existent" methods and it re-routes them through a .invoke()
call.
There's some rather terrifying stuff behind the scenes: https://github.com/framework-one/fw1/blob/develop/framework/cfmljure.cfc
oh it runs on the jvm. I didn't know anything about it so i thought you were reaching across some really crazy boundaries
CFML compiles on-demand to JVM bytecode (just like Clojure). Has done for about 15 years.
Prior to that it was interpreted (the interpreter was written in C++ for five years earlier).
There's a Clojure version of FW/1 too: https://github.com/framework-one/fw1-clj
We use for some web apps that are pure Clojure
It requires discipline to use, but we like what it's making us do... I blogged about it recently...
No, query
is based on a protocol and there's an implementation using java.jdbc
And an implementation extended to hash maps as well 🙂
yeah. for some reason i was thinking that it knew you did updates which hadn't ocmmited yet so it queried the ram instead of the underlying db
The nice thing about the idiom is that it extends to things like message queues, email systems, generator processes etc
At World Singles we have Committable data stores that implement all sorts of things... and Queryable data stores for all sorts of stuff too
Any time. Feel free to DM me if you ever have java.jdbc Qs
Is there a take-last that returns the individual items I'm looking for wrapped in a vector?
no, like
Say I'm running through a log
take-last gives me (x line y line z line)
vec take-last [x line y line z line]
i'm looking for ([x line] [y line] [z line])
modding take-last doesnt look like itd be trivial either
(map vec (partition 2 (take-last X coll)))
why partition 2?
the nil
to break your collection up into subcollections of 2 items each
why 2 items?
> (map vec (partition 2 (take-last 4 [1 2 3 4 5 6]))) ;; ([3 4] [5 6])
oh, i get it
i meant
([line] [line] [line])
my mistake
your solution did work though, thanks!
> (map vec (partition 1 (take-last 4 [1 2 3 4 5 6]))) ;; ([3] [4] [5] [6])
😁
exactly
sequence function composition ftw
god bless fp
bit of an addiction, tbh
agreed
I'll turn my workplace into a clojure shop just yet hehehehe
in the partition 1
case you can simplify it to > (map vector (take-last 4 [1 2 3 4 5 6]))
and if your input is a vector, it would be better to use subvec: (mapv vector (subvec [1 2 3 4 5 6] (- (count [1 2 3 4 5 6]) 4)))
Is anyone developing in a docker container using emacs and cider? If so, are you able to jump to fn definitions in a different ns? I keep getting no source locations and https://github.com/clojure-emacs/cider/issues/589 doesnt' seem to address it for me
recommend asking in #C0617A8PQ as well, @petr
any ideas why I wouldn't be able to iterate through that vector?
I'm trying to run it through a map but nothing's really happening
(map (fn [ln] (println ln)) line-list)
doall then
is for lazy too? it was also failing with that
there should be a flag for non-lazy mapping
well yes
and now it seems to get stuck at the last result and stay put forever, boy am I having trouble today
that's what I get for not changing the text processing function as well, got it.
Is there a recommended plugin for lein that will generate dockerfiles? I’ve looked at the palletops one, lein-uberimage, but it seems to be abandoned.
alexmiller: I was in here asking about an issue with transit-clj a few days ago; I opened an issue there, but now I’m wondering if that should be on transit-java instead? (https://github.com/cognitect/transit-clj/issues/33)
and I think the issue is in the version of org.msgpack/msgpack that transit-java is using
I don’t know that it matters much which of those it was filed on
interesting if it’s a version issue - why do you think so?
the newer version of msgpack seems to be doing the reading of bytes in a difference way
https://github.com/msgpack/msgpack-java/blob/develop/RELEASE_NOTES.md
anything there look relevant?
actually, maybe that’s not the right lib
I think the package name changed at some point, from org.msgpack/msgpack to org.msgpack/msgpack-core
I guess it is - it’s a little confusing but looks like that lib has artifact-id msgpack, so that’s right
transit-java is using 0.6.10
looks related - that was fixed in 0.6.11
no, 0.6.12
I’m a big fan of existing fixes to thorny problems :)
so that gives you a workaround - exclude the dep and add your own msgpack version
I’ll prod someone about updating and verifying transit-java
excellent; for now I’ve just been making sure the strings are < 127 or > 255 bytes 😛
I feel like I'm missing something really obvious here:
(defn f [& {:keys [a b c] :as args}]
(println a b c))
(defn g [& {:keys [a b c] :as args}]
;; do some stuff & then pass args on to f
(f args))
(f args)
throws an error. I can do it as (apply f (flatten (seq {:a 2 :b 3 :c 4})))
, but that's totally ridiculous. What idiom am I forgetting here?
Or of course I can do it as (f :a a :b b :c c)
but that's manual and annoying.@dpsutton: I don't love that option, because I want it to be easy for people to omit any subset of params.
optional parameters and destructuring rest arguments have become quite unpopular for their lack of composability.
eggsyntax: maybe you should use common lisp instead, for it's excessive lambda list madness. there you get all you want and more in argument list specification 🙂
@dpsutton: Not sure I understand what you're saying. Desired calling convention is like (g :a 2 :c 3)
(or any variant thereof).
eggsyntax: if you stick with clojure, though, i can really suggest that you forget about believing that it has keyword arguments
I'm just used to clj destructuring being so rich that it surprised me there isn't an obvious way to do it. But sounds like there's not.
dpsutton: not only that, but you can also determine whether a certain keyword has been specified or defaulted.
I do miss Python's handling of optional args; it's one of the few things I miss in Clojure.
@eggsyntax: You can provide default values in the destructured arg with :or
.
(note on the Python version: it was great for the common case, but had a deeply ugly pitfall: defaults were set at function definition time, which meant that if the default value was an array or other mutable object, changes to it would persist across function calls.)
Which is the most reliable SMTP server one can use? I found https://github.com/whilo/bote which is kind of interesting, it uses SubEtha SMTP
yeah @hiredman I think you are kind of right
I found an odd behavior, maybe it is expected, but just wanted a confirmation if anyone know
(every? true? nil) ;=>> true
(every? true? [nil]) ;=>> false
the first line is odd and I just found out a test was passing but it shouldn't have
sorry I corrected above
oh right...it is the old story of an AND when no items are tested? There is an example actually here: http://clojuredocs.org/clojure.core/every_q
yeah I was kind of forgetting that
it is a 101/interview question 😄
well, I have made my gaffe of the year, I can now retire 😄
Sometimes I find it helpful to mentally translate to: “there is no item in coll
which does not satisfy pred
."
I actually had an interview yesterday and one of the questions was why in Java (Integer.valueOf(-128) == Integer.valueOf(-128))
is true (I answered that it should be false)
but ok that's not a logic question
it is a side effecting Java quirk of caching objects for number within some range
ah that's because integers are objects and the common ones are created at start up but when you ask for ones outside of a small core range they are newed so to speak? And the == test here is using reference equality?
is there a common term for things that manage resources that can have multiple users and dispose them when there's no user left?
Yeah Python has that behavior for boxed integers as well. All the boxed integers are singletons, and the ones in a small range around 0 never get GC'd.
The Java cached primitives are never disposed
It's actually mandated in the spec
Can someone explain to me if such a question in an interview has any value (no pun intended) ?
@lprefontaine: creating quality tech interview questions is a difficult thing because most are subjective and on a job you could look it up. But I agree that it seems particularly and purposefully obscure to try to have the (maybe stressed) interviewee identify that you’re comparing two objects using == and then also knowing about Java caching certain numbers
@alexmiller: yes it is in the specs, I did not know that
didn't want to open a flame as I guess we all have our idea on what to ask in interviews, the interviewers were actually superfriendly and wanted to go in deep but always smiling and knowing that these things are kind of...well...imho worthless
In my world I deliver value. The fact that an implementation has such quirks is irrelevant to what I can deliver. The industry seems to be in such a disarray to select candidates that I am not surprised of its lack of throughput if this is the kind of discriminant factor it's using to select 'the best candidate's. I would have left the interview at the first question of this kind. Everyone should. This world is sick.
at least now they know that I did not read the Java spec, for them is worth knowing that
btw I got an offer
so the interview went well
because it is clear maybe that you can go deep, but also clear that you cannot know everything
ouf, 😂
which is healthy
Congratulations on that. And yes, I feel like it’s probably also a benefit to know someone didn’t just spend their free time reading the Java spec for no particular reason
I would rather read some byte code on a sheet of toilet paper 😬
^ many lol (it is a Java job so now I dunno what to do, other flame open :D)
have a nice start on your new job, I'll get back to my clojure/jdbc/oracle/unfamiliar schema problem...