This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-10-22
Channels
- # 100-days-of-code (3)
- # announcements (7)
- # beginners (147)
- # cider (22)
- # cljdoc (24)
- # cljs-dev (71)
- # cljsrn (8)
- # clojars (3)
- # clojure (45)
- # clojure-conj (11)
- # clojure-dev (1)
- # clojure-italy (21)
- # clojure-nl (2)
- # clojure-spec (76)
- # clojure-sweden (2)
- # clojure-uk (100)
- # clojurebridge (3)
- # clojurescript (15)
- # cursive (7)
- # data-science (2)
- # datomic (7)
- # emacs (9)
- # events (2)
- # figwheel-main (4)
- # fulcro (117)
- # jobs (2)
- # jobs-discuss (21)
- # leiningen (184)
- # nyc (4)
- # off-topic (50)
- # planck (6)
- # re-frame (14)
- # reagent (25)
- # ring-swagger (5)
- # shadow-cljs (96)
- # spacemacs (5)
- # sql (26)
- # tools-deps (12)
- # uncomplicate (1)
- # yada (3)
I'm not familiar with that form of DATETIME
but we regularly do this sort of thing DATE_SUB( NOW(), INTERVAL ? DAY )
and that works just fine (MySQL) @martinklepsch
might be a sqlite thing but yeah, fair point to look for a datetime helper that takes a number as input
it because jdbc's syntax using '?' isn't a kind of blind search an replace, the '?' token is only valid in certain places, and it isn't valid in the middle of a string literal
Ah, I didn't notice it was in a string in the first piece of code -- no, that definitely won't work. The example I gave isn't using a string. Good 👀 there @hiredman!
hey guys, need some help here I’m doing a CRUDish application and I have the follow relations
Session 1--------* Orders 1-------* Gateway-Transactions (gonna call transactions only )
|1
|1
Movements
just a simple usecase to exemplify the relations
the system A creates a session with our service (payment system) and will register one sale
POST /sessions/1/sale
we are going to create one entry into Orders , another one into Transactions ( braintree/paypal/stripe whatever ) and the result , on success, we are going to register one movement ( CREDIT ).
easy enough isn’t ?
my problem is how to manage relationships using clojure.
I’m using hugsql + defrecords to map my tables
I would love, without N+1, fetch for instance, all movements with the transactions associated with themI’m doing some joins into my Movement domain to fetch all data related with movements and transactions. but I need to map to the proper defrecord (Transaction) for instance
It's just data. A joined query will be a sequence of hash maps.
You can transform it in memory to whatever shape you would prefer.
(ORMs are evil 🙂 )
yeah @seancorfield , (need to get that into my brain ) the shape (defrecord ) make my life easy to map to tables. so my problem is that the Movement namespace will require the Transaction namespace to shape the result
(ns movement)
(defn find-all-with-transactions-by-session [session-id]
(SQL QUERY WITH JOIN RETURN ALL DATA))
what I’m doing is:
(defn find-all-with-transactions-by-session [session-id]
(map create-movement-transaction (SQL QUERY WITH JOIN RETURN ALL DATA))
something like that and I’m felling dirty , really dirty ( like OO into functional )
Do you really need to separate these things out into separate namespaces? These aren't classes. If movements and transactions are related and you can't have one without the other, why have separate namespaces?
Also, why use records here rather than plain ol' maps?
hello @seancorfield! I'm using clojure.java.jdbc/query
to query my database and everything is just fine... but... now I'm facing an issue because I need to extract the column types of the first row for a given query... it works just fine if the columns for that first row all have values, because it is a map, so, doing (type a-column-value)
works. But when a column is null on database, a-column-value
is also null (`nil`) and I can't get the type
so I think that if I could get the ResultsetMetadata I could get the type of that column.
But I can't figure out how to do that.
Sounds like you want the metadata for the table really, not for the query?
http://clojure-doc.org/articles/ecosystem/java_jdbc/using_ddl.html#accessing-metadata -- that's a rough example that gets metadata for all tables... I'd have to look at the docs for .getTables
in the Java SQL API docs for how to get just the one table you want...
(and part of me wonders why you need the types of the columns? @gleisonsilva)
Here's the Java docs for calling .getTables
and specifying catalog, schema, and table name https://docs.oracle.com/javase/7/docs/api/java/sql/DatabaseMetaData.html#getTables(java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String[])
> (and part of me wonders why you need the types of the columns?) because I need to generate a Avro schema for dumping the results of those queries as Avro files
Oh, OK. Well, using the metdata from the tables themselves is going to be a better approach anyway I think.