Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding guestbook-datomic #5

Open
Folcon opened this issue Jun 9, 2018 · 15 comments
Open

Adding guestbook-datomic #5

Folcon opened this issue Jun 9, 2018 · 15 comments

Comments

@Folcon
Copy link
Contributor

Folcon commented Jun 9, 2018

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.

@Folcon
Copy link
Contributor Author

Folcon commented Jun 9, 2018

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.

@yogthos
Copy link
Member

yogthos commented Jun 9, 2018

ah good call on adding a comment, I'll take a look

@Folcon
Copy link
Contributor Author

Folcon commented Jun 9, 2018

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?

@Folcon
Copy link
Contributor Author

Folcon commented Jun 10, 2018

@yogthos Other than the above issue, I've got it mostly working. Would like to get this wrapped up today if possible.

@yogthos
Copy link
Member

yogthos commented Jun 10, 2018

👍

@yogthos
Copy link
Member

yogthos commented Jun 10, 2018

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.

@Folcon
Copy link
Contributor Author

Folcon commented Jun 10, 2018

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?

@Folcon
Copy link
Contributor Author

Folcon commented Jun 10, 2018

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!

@yogthos
Copy link
Member

yogthos commented Jun 10, 2018

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.

@rberger
Copy link

rberger commented Nov 5, 2018

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.

@yogthos
Copy link
Member

yogthos commented Nov 5, 2018

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.

@Folcon
Copy link
Contributor Author

Folcon commented Nov 5, 2018

@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.

@yogthos
Copy link
Member

yogthos commented Nov 5, 2018

@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.

@Folcon
Copy link
Contributor Author

Folcon commented Nov 18, 2018

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.

@yogthos
Copy link
Member

yogthos commented Nov 18, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants