subscribe
I'm trying to use this as a realtime DB (firebase replacement) on the SERVER to listen to events.
How do i listen for changes on a collection, or subscribe to a query?
A bit like useQuery hook but for server side?
Or do I have to resort to something with actions?
react.js | Convex Developer Hub
These exports are not directly available in the convex package!
19 Replies
https://docs.convex.dev/functions/query-functions#caching--reactivity
"clients can subscribe to queries "how do i do this without looking into the hooks implementation for client side web apps (i'd like to do it server side). i think i read somewhere this was the last part of the convex puzzle that hasn't been built yet?
Queries | Convex Developer Hub
Queries are the bread and butter of your backend API. They fetch data from the
@DCsan do you want this for a server you're running? If it can connect with a websocket you can use the base client or the React client on the server, things like this https://observablehq.com/@ballingt/hello-convex-beta
Observable
Hello Convex
How do you get shared, reactive server-side state for an Observable notebook? There are many ways: AWS, firebase, a slick solution from Tom Larkworthy — and now there's one more, Convex. You can sign up for the Convex at convex.dev. To use Convex in a webapp or from Node.js the standard
npm install convex
etc. is recommended, but in Observable...yes server side
To create a client in Node.js you need to pass a couple options, let me see if we have an example posted
is this the incantation?
or is that also client side code?
You don't need that stuff, that's to build a generator of results
after that is a nonReactiveQuery, which isn't what i want... i think?
That example is client side but it also works server side
so ...
client = new c.ConvexReactClient(url)
?
then i use the reactHooks ? (not on this article?)
so there isn't a documented way to listen to events on the server side?Yep, that's it, no React hooks, just methods on the client
maybe
?
like, what methods? should i do reflection on the client to try and figure it out?
ok looks good, tx.
We should absolutely have a dedicated doc for this, above is doing this with the React client but we need an example without React
is this not a supported use case or something? i'm wondering why its not in the docs, it seems a primary benefit of convex is realtime stuff?
your example doesn't use react right? unless i'm missing some import/deps
ConvexReactClient
oops
ok so importing that into node without a DOM should work?
also, were there some limitations that I can only listen to "pure" functions? where as anything that touches the DB must by definition be non deterministic.This is supported, we've just found it a lot rarer so have focused on the client-side applications. This works without a DOM, but requires you have React installed which isn't ideal. When folks want to talk to the database from Node.js usually they've wanted non-reactive reads, so https://docs.convex.dev/quickstart/nodejs is the common path
I'll get an example up that shows subscriptions from Node.js without React, it's a couple more lines of code.
:ty:
would rather not import all of react into a SS app
also, were there some limitations that I can only listen to "pure" functions? where as anything that touches the DB must by definition be non deterministic.That's one of the big pieces we do special, accessing the DB counts as deterministic When you run a query we track which ranges of which tables and indexes were accessed by that query. Because it's deterministic, we know we only need to rerun that query if data in those ranges is modified. If it is, we rerun the query and send the new result down the websocket.
ok doke, ty