Adding guestbook-datomic
Folcon opened this issue · 15 comments
Issue to coordinate adding a guestbook-datomic example.
The template for this example was created with the flags below.
lein new luminus guestbook-datomic +datomic +re-frame
The code is at https://github.com/folcon/examples.
One thing that might be useful to add to the template in dev-config.edn
is this message:
; Don't forget you can also use the datomic mem db which can be useful when developing
; :database-url "datomic:mem://guestbook_datomic_dev"
Not sure how you template the project name.
ah good call on adding a comment, I'll take a look
So I'm getting a fun problem. My datomic keys are being converted to json incorrectly I believe?
My code feeds the result straight to the response function:
(response/ok (db/get-messages db/conn))
So for example, a message list such as:
[{:db/id 17592186045418 :message/id #uuid "bc7024b1-c8c0-4c8d-b7d1-a7d9e5044ad0" :message/name "Test name" :message/message "Test message"}]
is converted to:
[{":db/id":17592186045418,":message/id":"bc7024b1-c8c0-4c8d-b7d1-a7d9e5044ad0",":message/name":"Test name",":message/message":"Test message"}]
Which then is read out as:
{::db/id 17592186045418, ::message/id "bc7024b1-c8c0-4c8d-b7d1-a7d9e5044ad0", ::message/name "Test name", ::message/message "Test message"}
I was expecting it to convert to json automatically. Am I calling this incorrectly?
@yogthos Other than the above issue, I've got it mostly working. Would like to get this wrapped up today if possible.
Regarding the JSON conversion, you probably would want to use transit between the client and the server. As I recall the middleware uses the accept
header to infer what format things should get serialized in. As I recall cljs-ajax should be defaulting to transit though.
Hmm, it doesn't seem to be working well. In both cases I get message keys like:
":db/id", ":message/id", ":message/name"
Which get converted to:
::db/id, ::message/id, ::message/name
The same as when I do:
(keyword ":message/name")
;=> ::message/name
Whereas I want:
(keyword "message/name")
;=> :message/name
Because
encoding(input) => output
decoding(output) => input
right?
Perhaps I should be converting the output of the datomic db? Which currently gives:
[{:db/id 17592186045418 :message/id #uuid "bc7024b1-c8c0-4c8d-b7d1-a7d9e5044ad0" :message/name "Test name" :message/message "Test message"}]
transmit+json gives:
[["^ ",":db/id",17592186045418,":message/id","~u016b7492-0e35-45d5-afea-f0ac31ba38af",":message/name","Test message",":message/message","Test message",":message/timestamp","~m1528575843965"]]
Also I could push what I currently have if you're puzzled about the issue I'm coming across?
Ok @yogthos, worked out the issue. Had done the pull syntax incorrectly. I didn't realise you could get it to wrap elements in strings. More flexible than I expected.
I've pushed an update, give it a look when you have some time and tell me if you want me to make some updates to it!
Thanks, I'll try take a look shortly. I think you should be able to send Datomic results directly to the client as long as they're in EDN format. Once transit+json is deserialized, it should look like the original data on the other end.
Is there a tutorial to go along with guestbook-datomic?
Though what I'm really looking for is a tutorial for using re-frame with Luminus. This is the closest I could find.
There isn't a tutorial to go along with the sample project at the moment. This re-frame workshop might be helpful though. Luminus just sets up the basic scaffolding for re-frame, so how you structure the app beyond that is mostly up to you.
@rberger What kinds of things would you like to see in a tutorial?
I've been using datomic more and more in my reframe app, so happy to try and document things and put it back into tutorial form =)...
Also @yogthos, sorry about not getting back in touch sooner, if you have improvements you'd like me to make to what I've documented, could spend some more time on that.
@Folcon if you have a chance I'd suggest adding a small walkthrough in the readme for the guestbook-datomic project. Alternatively, you could add a Datomic section in the database doc page. I'd focus on Luminus specific aspects of getting Datomic up and running, and refer to the official docs for further details.
Gah, sorry @yogthos, I keep meaning to respond when I have something and unfortunately at the moment most of my focus is on the frontend side of development. However the datomic code I have working is in production, so there's little chance of me not doing this, if only to ensure I document it for myself to read in the future ;)...
It's just that I doubt I'll be going anywhere near it until at least January. My plan is to document useful stuff as I go when I next touch it so the intent is to put that here then.
No rush, it's going to be pretty great to have docs based on actual real world experience though. :) I'm also open to improving the Datomic profile to make things smoother if you have any ideas there.