sonandmjy
sonandmjy
CCConvex Community
Created by sonandmjy on 2/4/2025 in #support-community
filtering documents with getPage
I'm looking at the getPage function so I can control the pagination more. But I can't seem to figure out how the filtering works. For example, I have a messages table that stores messages all the messages from many companies. However, I'm not sure how I would only include those results in the getPage return since I don't see a param that allows me to filter my index 🤔 eg this is my function right now and I only want the results with only a particular channelId and destinationId. How would I achieve this? Thank you for any advice in advance!
const { page: _page, ...response } = yield* Effect.promise(() =>
getPage(ctx, {
table: "messages",
index: "by_destination_and_channel_id",
schema: schema,
order,
startIndexKey: args.startIndexKey,
endIndexKey: args.endIndexKey,
endInclusive: args.endInclusive,
startInclusive: args.startInclusive,
}),
);
const { page: _page, ...response } = yield* Effect.promise(() =>
getPage(ctx, {
table: "messages",
index: "by_destination_and_channel_id",
schema: schema,
order,
startIndexKey: args.startIndexKey,
endIndexKey: args.endIndexKey,
endInclusive: args.endInclusive,
startInclusive: args.startInclusive,
}),
);
11 replies
CCConvex Community
Created by sonandmjy on 1/21/2025 in #support-community
How would you handle third party subscriptions in convex
Hi, I am using convex and trigger to do background task processing and I am looking at trigger's realtime SDK. In some bit of code, they 'subscribe' to changes to the task run like in this example they gave. Was wondering is this safe to do in a convex action? Or would it cause the action to hang indefinitely or eat up a lot of bandwidth? Any advice is very much appreciated thank you! link to the docs: https://trigger.dev/docs/realtime/overview
import { runs, tasks } from "@trigger.dev/sdk/v3";

// Somewhere in your backend code
async function myBackend() {
const handle = await tasks.trigger("my-task", { some: "data" });

for await (const run of runs.subscribeToRun(handle.id)) {
// This will log the run every time it changes
console.log(run);
}
}
import { runs, tasks } from "@trigger.dev/sdk/v3";

// Somewhere in your backend code
async function myBackend() {
const handle = await tasks.trigger("my-task", { some: "data" });

for await (const run of runs.subscribeToRun(handle.id)) {
// This will log the run every time it changes
console.log(run);
}
}
5 replies
CCConvex Community
Created by sonandmjy on 12/25/2024 in #support-community
search index multiple chained filter fields behaviour not as expected
Hi there, I have a schema that looks like this
export const Destinations = Table("destinations", {
type: VDestinationTypes,
contactId: v.optional(v.id("contacts")),
value: v.string(),
isDeleted: v.boolean(),
organizationId: v.id("organizations"),
lastMessageId: v.optional(v.record(v.id("channels"), v.id("messages"))),
lastInboundMessageId: v.optional(
v.record(v.id("channels"), v.id("messages")),
),
lastOutboundMessageId: v.optional(
v.record(v.id("channels"), v.id("messages")),
),
});
export const Destinations = Table("destinations", {
type: VDestinationTypes,
contactId: v.optional(v.id("contacts")),
value: v.string(),
isDeleted: v.boolean(),
organizationId: v.id("organizations"),
lastMessageId: v.optional(v.record(v.id("channels"), v.id("messages"))),
lastInboundMessageId: v.optional(
v.record(v.id("channels"), v.id("messages")),
),
lastOutboundMessageId: v.optional(
v.record(v.id("channels"), v.id("messages")),
),
});
and I am trying to add a searchIndex like this
Destinations.table
.index("by_contact_id", [
"organizationId",
"contactId",
"isDeleted",
"type",
])
.index("by_value", ["organizationId", "type", "value", "isDeleted"])
.searchIndex("by_search_value", {
searchField: "value",
filterFields: ["organizationId", "type", "isDeleted", "contactId"],
})
Destinations.table
.index("by_contact_id", [
"organizationId",
"contactId",
"isDeleted",
"type",
])
.index("by_value", ["organizationId", "type", "value", "isDeleted"])
.searchIndex("by_search_value", {
searchField: "value",
filterFields: ["organizationId", "type", "isDeleted", "contactId"],
})
but when I try to filter it using a query
ctx.db
.query("destinations")
.withSearchIndex("by_search_value", (q) => {
return q
.search("value", args.searchQuery)
.eq("organizationId", ctx.user.defaultOrganizationId!)
.eq("type", "phone_number")
.eq("isDeleted", false)
.eq("contactId", undefined);
})
.take(20)
ctx.db
.query("destinations")
.withSearchIndex("by_search_value", (q) => {
return q
.search("value", args.searchQuery)
.eq("organizationId", ctx.user.defaultOrganizationId!)
.eq("type", "phone_number")
.eq("isDeleted", false)
.eq("contactId", undefined);
})
.take(20)
it seems that it is still returning results where contactId IS defined. Also when I change .eq("type", "phone_number") => .eq("type", "email") it is still returning results where the type is of phone_number. When I only have 1 .eq the filter seems to be working fine but when I chain them they are not. Just want to check if I am misunderstanding some limitations of how to use this filter or if it is a bug
4 replies
CCConvex Community
Created by sonandmjy on 12/21/2024 in #support-community
Hitting error "found wrong number of app bundles" in dev CLI
Hi there! I am hitting an error in which whenever I add a convex.config.ts file to install components, I get a "found wrong number of app bundles" in the CLI. I have tried searching the docs and github but haven't managed to find anything. This is pretty much all that is in my convex.config.ts file right now. I am using remix in the same repo if that is of any significance. Any help would be appreciated! 😀 Thank you
import { defineApp } from "convex/server";

const app = defineApp();
export default app;
import { defineApp } from "convex/server";

const app = defineApp();
export default app;
12 replies