Web Dev Cody
Web Dev Cody
CCConvex Community
Created by Web Dev Cody on 10/5/2024 in #support-community
Convex in stackblitz
has anyone gotten convex working in stackblitz
5 replies
CCConvex Community
Created by Web Dev Cody on 10/2/2024 in #support-community
Understanding usePaginatedQuery
or just don't use ids and instead use proper dates
23 replies
CCConvex Community
Created by Web Dev Cody on 10/2/2024 in #support-community
Understanding usePaginatedQuery
I could also probably just do order('desc') so that id 1 is the oldest I think
23 replies
CCConvex Community
Created by Web Dev Cody on 10/2/2024 in #support-community
Understanding usePaginatedQuery
const PAGE_SIZE = 5;

export const getPosts = query({
args: {
page: v.number(),
},
handler: async (ctx, args) => {
const startId = (args.page - 1) * PAGE_SIZE + 1;

const page = await ctx.db
.query("blogPosts")
.withIndex("incrementingId_index", (q) =>
q.gte("incrementingId", startId)
)
.take(PAGE_SIZE);

return page;
},
});
const PAGE_SIZE = 5;

export const getPosts = query({
args: {
page: v.number(),
},
handler: async (ctx, args) => {
const startId = (args.page - 1) * PAGE_SIZE + 1;

const page = await ctx.db
.query("blogPosts")
.withIndex("incrementingId_index", (q) =>
q.gte("incrementingId", startId)
)
.take(PAGE_SIZE);

return page;
},
});
23 replies
CCConvex Community
Created by Web Dev Cody on 10/2/2024 in #support-community
Understanding usePaginatedQuery
sorry I've modified since posting
23 replies
CCConvex Community
Created by Web Dev Cody on 10/2/2024 in #support-community
Understanding usePaginatedQuery
run it, then just do a take(PAGE_SIZE)
23 replies
CCConvex Community
Created by Web Dev Cody on 10/2/2024 in #support-community
Understanding usePaginatedQuery
going to add this export const addAutoIncrementingIdToPosts = internalMutation({ args: {}, async handler(ctx) { const posts = await ctx.db.query("blogPosts").order("desc").collect(); await Promise.all( posts.map((post, index) => ctx.db.patch(post._id, { incrementingId: index + 1 }) ) ); }, });
23 replies
CCConvex Community
Created by Web Dev Cody on 10/2/2024 in #support-community
Understanding usePaginatedQuery
order desc
23 replies
CCConvex Community
Created by Web Dev Cody on 10/2/2024 in #support-community
Understanding usePaginatedQuery
yeah I just want a list of blog posts by date
23 replies
CCConvex Community
Created by Web Dev Cody on 10/2/2024 in #support-community
Understanding usePaginatedQuery
and then calculate the page / offset using that with a .take max page length?
23 replies
CCConvex Community
Created by Web Dev Cody on 10/2/2024 in #support-community
Understanding usePaginatedQuery
easiest approach I can think is just add an auto incrementing id to the records
23 replies
CCConvex Community
Created by Web Dev Cody on 10/2/2024 in #support-community
Understanding usePaginatedQuery
@Hmza would the query on the convex query just need to return a pagination object?
23 replies
CCConvex Community
Created by Web Dev Cody on 9/30/2024 in #support-community
youtube api in action
const fileStream = file.stream();

const nodeReadableStream = new Readable({
async read(size) {
const reader = fileStream.getReader();
try {
while (true) {
const { done, value } = await reader.read();
if (done) {
this.push(null);
break;
}
this.push(Buffer.from(value));
}
} catch (error) {
this.destroy(error as Error);
} finally {
reader.releaseLock();
}
},
});
const fileStream = file.stream();

const nodeReadableStream = new Readable({
async read(size) {
const reader = fileStream.getReader();
try {
while (true) {
const { done, value } = await reader.read();
if (done) {
this.push(null);
break;
}
this.push(Buffer.from(value));
}
} catch (error) {
this.destroy(error as Error);
} finally {
reader.releaseLock();
}
},
});
5 replies
CCConvex Community
Created by Web Dev Cody on 9/30/2024 in #support-community
youtube api in action
I fixed this by wrapping the convex file stream with a node stream
5 replies
CCConvex Community
Created by Web Dev Cody on 9/24/2024 in #support-community
Custom Convex Domain
my thinking is that if I added a proxy http endpoint for my images, I'd want to put it behind cloudflare cdn to cache the images and lower any convex bandwidth charges, but if the project id is discoverable to an end user, someone could easily just write a script to hit my convex.site directly and keep downloading the same file
6 replies
CCConvex Community
Created by Web Dev Cody on 9/24/2024 in #support-community
Get all documents where storageId not null
yeah, just gt
const publicVideos = await ctx.db
.query("videos")
.withIndex("isPublic_index_videoFile", (q) =>
q.eq("isPublic", true).gt("videoFile", null as any),
)
.order("desc")
.take(20);
const publicVideos = await ctx.db
.query("videos")
.withIndex("isPublic_index_videoFile", (q) =>
q.eq("isPublic", true).gt("videoFile", null as any),
)
.order("desc")
.take(20);
6 replies
CCConvex Community
Created by Web Dev Cody on 9/24/2024 in #support-community
Get all documents where storageId not null
ty
6 replies
CCConvex Community
Created by Web Dev Cody on 9/21/2024 in #support-community
Delete all files
sorry for not seeing that 😅
17 replies
CCConvex Community
Created by Web Dev Cody on 9/21/2024 in #support-community
Delete all files
yes, this is perfect
17 replies
CCConvex Community
Created by Web Dev Cody on 9/21/2024 in #support-community
Delete all files
export const listAllFiles = query({
handler: async (ctx) => {
// You can use .paginate() as well
return await ctx.db.system.query("_storage").collect();
},
});
export const listAllFiles = query({
handler: async (ctx) => {
// You can use .paginate() as well
return await ctx.db.system.query("_storage").collect();
},
});
17 replies