Bogdan
Bogdan
CCConvex Community
Created by Bogdan on 9/17/2023 in #support-community
Can i check equality like this?
the docs say to use combining operators if you want to for example return all documents where the name is either "Alex" or "Emma"
// Get all users named "Alex" or "Emma".
const usersNamedAlexOrEmma = await ctx.db
.query("users")
.filter((q) =>
q.or(q.eq(q.field("name"), "Alex"), q.eq(q.field("name"), "Emma"))
)
.collect();
// Get all users named "Alex" or "Emma".
const usersNamedAlexOrEmma = await ctx.db
.query("users")
.filter((q) =>
q.or(q.eq(q.field("name"), "Alex"), q.eq(q.field("name"), "Emma"))
)
.collect();
but i found that you could also do
const usersNamedAlexOrEmma = await ctx.db
.query("users")
.filter((q) =>
q.eq(q.field("name"), "Alex" || "Emma")
)
.collect();
const usersNamedAlexOrEmma = await ctx.db
.query("users")
.filter((q) =>
q.eq(q.field("name"), "Alex" || "Emma")
)
.collect();
is there a reason i should not use the ladder? it reads much better imo.
3 replies
CCConvex Community
Created by Bogdan on 9/12/2023 in #support-community
Handle client disconnecting?
On the backend, how would i listen for a client disconnecting? With socket.io i could just add a socket.on("disconnect", callbackFn()) to handle this, is there something similar built into convex? i thought about using beforeunload but it's unreliable. any ideas or suggestions?
55 replies
CCConvex Community
Created by Bogdan on 9/11/2023 in #support-community
Could not resolve "crypto"
I am trying to have a function that generates a code and returns it to the react client.
import crypto from 'crypto'
import { mutation } from "./_generated/server";

export const getSessionId = mutation({
args: {},
handler: async (ctx) => {
let sessionId = generateCode()
await ctx.db.insert("rooms", {sessionId: sessionId});
return sessionId
}
})

function generateCode() {
return crypto.randomBytes(3).toString('hex').toUpperCase()
}
import crypto from 'crypto'
import { mutation } from "./_generated/server";

export const getSessionId = mutation({
args: {},
handler: async (ctx) => {
let sessionId = generateCode()
await ctx.db.insert("rooms", {sessionId: sessionId});
return sessionId
}
})

function generateCode() {
return crypto.randomBytes(3).toString('hex').toUpperCase()
}
but then i get this error:
✘ [ERROR] Could not resolve "crypto"

src/convex/room.ts:1:19:
1 │ import crypto from 'crypto'
✘ [ERROR] Could not resolve "crypto"

src/convex/room.ts:1:19:
1 │ import crypto from 'crypto'
how would i resolve this? i also feel as though there is a gap in my understanding of how convex is supposed to work .
6 replies