Vishal Lohar
CCConvex Community
•Created by Vishal Lohar on 10/4/2024 in #support-community
Convex Ents Cascading Delete not working
import { defineEnt } from "convex-ents";
import { v } from "convex/values";
export const collectionsSchema = defineEnt({
name: v.string(),
description: v.optional(v.string()),
isPublic: v.boolean(),
updatedBy: v.id("users"),
})
.edge("workspace", {
field: "workspaceId",
})
.edge("user", {
field: "createdBy",
})
.edges("collectionScreens", {
ref: true,
})
.edges("collectionFlows", {
ref: true,
});
export const collectionScreensSchema = defineEnt({
updatedAt: v.union(v.null(), v.null()),
updatedBy: v.id("users"),
platormType: v.string(),
})
.edge("user", {
field: "createdBy",
})
.edge("collection", {
field: "collectionId",
})
.edge("screen", {
field: "screenId",
})
.edge("savedScreen", {
field: "savedScreenId",
});
export const collectionFlowsSchema = defineEnt({
updatedAt: v.union(v.null(), v.number()),
updatedBy: v.id("users"),
platormType: v.string(),
})
.edge("user", {
field: "createdBy",
})
.edge("collection", {
field: "collectionId",
})
.edge("flow", {
field: "flowId",
})
.edge("savedFlow", {
field: "savedFlowId",
});
import { defineEnt } from "convex-ents";
import { v } from "convex/values";
export const collectionsSchema = defineEnt({
name: v.string(),
description: v.optional(v.string()),
isPublic: v.boolean(),
updatedBy: v.id("users"),
})
.edge("workspace", {
field: "workspaceId",
})
.edge("user", {
field: "createdBy",
})
.edges("collectionScreens", {
ref: true,
})
.edges("collectionFlows", {
ref: true,
});
export const collectionScreensSchema = defineEnt({
updatedAt: v.union(v.null(), v.null()),
updatedBy: v.id("users"),
platormType: v.string(),
})
.edge("user", {
field: "createdBy",
})
.edge("collection", {
field: "collectionId",
})
.edge("screen", {
field: "screenId",
})
.edge("savedScreen", {
field: "savedScreenId",
});
export const collectionFlowsSchema = defineEnt({
updatedAt: v.union(v.null(), v.number()),
updatedBy: v.id("users"),
platormType: v.string(),
})
.edge("user", {
field: "createdBy",
})
.edge("collection", {
field: "collectionId",
})
.edge("flow", {
field: "flowId",
})
.edge("savedFlow", {
field: "savedFlowId",
});
40 replies
CCConvex Community
•Created by Vishal Lohar on 10/4/2024 in #support-community
Convex Ents and Convex authTables TS error
4 replies
CCConvex Community
•Created by Vishal Lohar on 8/19/2024 in #support-community
How can I filter, sort, and paginate queries using convex filter helper?
1 replies
CCConvex Community
•Created by Vishal Lohar on 8/13/2024 in #support-community
Can we optimize this query?
export const getTrendingFilterTags = query({
args: { platformType: v.string() },
handler: async ({ db }, args) => {
const dictionaryCategories = await getManyFrom(
db,
"dictionaryCategories",
"by_platform_type",
args.platformType,
"platformType",
);
const categoryIds = new Set(
dictionaryCategories.map((category) => category._id),
);
const dictionarySubCategories = await filter(
db.query("dictionarySubCategories"),
(subCategory) => categoryIds.has(subCategory.dictionaryCategoriesId),
).collect();
const subCategoryIds = new Set(
dictionarySubCategories.map((subCategory) => subCategory._id),
);
const dictionaryEntries = await filter(
db.query("dictionaryEntries"),
(entry) => subCategoryIds.has(entry.dictionarySubCategoriesId),
).collect();
const entryIds = new Set(dictionaryEntries.map((entry) => entry._id));
const bareTrendingTags = await filter(
db.query("trendingFilterTags"),
(tag) => entryIds.has(tag.dictionaryEntry),
).collect();
const trendingTags = await asyncMap(bareTrendingTags, async (tag) => {
const dictionaryEntry = dictionaryEntries.find(
(entry) => entry._id === tag.dictionaryEntry,
);
const dictionarySubCategory = dictionarySubCategories.find(
(subCategory) =>
subCategory._id === dictionaryEntry?.dictionarySubCategoriesId,
);
const dictionaryCategory = dictionaryCategories.find(
(category) =>
category._id === dictionarySubCategory?.dictionaryCategoriesId,
);
return //Something
return trendingTags;
},
});
export const getTrendingFilterTags = query({
args: { platformType: v.string() },
handler: async ({ db }, args) => {
const dictionaryCategories = await getManyFrom(
db,
"dictionaryCategories",
"by_platform_type",
args.platformType,
"platformType",
);
const categoryIds = new Set(
dictionaryCategories.map((category) => category._id),
);
const dictionarySubCategories = await filter(
db.query("dictionarySubCategories"),
(subCategory) => categoryIds.has(subCategory.dictionaryCategoriesId),
).collect();
const subCategoryIds = new Set(
dictionarySubCategories.map((subCategory) => subCategory._id),
);
const dictionaryEntries = await filter(
db.query("dictionaryEntries"),
(entry) => subCategoryIds.has(entry.dictionarySubCategoriesId),
).collect();
const entryIds = new Set(dictionaryEntries.map((entry) => entry._id));
const bareTrendingTags = await filter(
db.query("trendingFilterTags"),
(tag) => entryIds.has(tag.dictionaryEntry),
).collect();
const trendingTags = await asyncMap(bareTrendingTags, async (tag) => {
const dictionaryEntry = dictionaryEntries.find(
(entry) => entry._id === tag.dictionaryEntry,
);
const dictionarySubCategory = dictionarySubCategories.find(
(subCategory) =>
subCategory._id === dictionaryEntry?.dictionarySubCategoriesId,
);
const dictionaryCategory = dictionaryCategories.find(
(category) =>
category._id === dictionarySubCategory?.dictionaryCategoriesId,
);
return //Something
return trendingTags;
},
});
3 replies