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

What am I missing ? #22

Open
olymk2 opened this issue Jun 27, 2021 · 2 comments
Open

What am I missing ? #22

olymk2 opened this issue Jun 27, 2021 · 2 comments

Comments

@olymk2
Copy link

olymk2 commented Jun 27, 2021

Not tried using a state management library, I have followed the examples and have everything working.

What I do not get is how I reference state, so say I bring up the db in start how do I then access the db connection, normally I would (defonce crux-db (run-crux)) then reference crux-db in my code, I have found clip/ref but that seems not to return an instance of the command run in startup of clip.

how would I get the connection for a db like postgres or crux ?

The only examples I could find seem to pass the connection in to all functions instead of setting it globally.

@SevereOverfl0w
Copy link
Collaborator

You would configure clip to run your functions. For example, you'd create a closure over your ring handler(s) to pass it the db. Here's an example of doing that in the todo example linked in the README: https://github.com/prestancedesign/todo-backend-reitit/blob/c3d5974f679203f200089ca10f40fda75b7e6e33/resources/config.edn#L12

@olymk2
Copy link
Author

olymk2 commented Jun 30, 2021

lol I really don't get something, it looks like its being passed to the handler ie todo-backend.core/app-routes but looking at the code here

https://github.com/prestancedesign/todo-backend-reitit/blob/14fc57490fe03ac67d9e4ffd70eb129841640b47/src/todo_backend/core.clj#L26

it does not take a parameter, I guess ring/ring-handler could be storing a fn in app-routes which takes db.

then in this piece of code, it looks like its actually setting up the db from env and storing the instance in db rather than using clip at which point its global scope in that file and makes me wonder why its being used in clip.

https://github.com/prestancedesign/todo-backend-reitit/blob/3d56222cae188f653cf863c8019770c68e3b607d/src/todo_backend/store.clj#L9

I admit something in there are unfamiliar like nextjdbc, but to me the point is I use clip to start my db and http server in order and some how make the value available, I think mount for example inserts namespaces which you can import to get the reference to your instances.

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

2 participants