#query return only one column

8 messages · Page 1 of 1 (latest)

sharp basin
#

is it possible for a query to just return the id
I am loading a bunch of data in one function but than getting an error because the check if data already exists is reading to much data I think
Too many bytes read in a single function execution

can I just get the _id back instead of reading the entire document

sharp coral
#

It's not today but we recognize this would be useful. Do you have an index on the check that the data already exists?

fervent cypress
#

Yeah, this is likely caused by a lack of index (loading too many documents), not by the individual documents themselves being large

sharp basin
#

`export const patchPodcastRssJson = mutation({
args: { id: v.id("podcast"), rss_json: v.any(), },
handler: async (ctx, args) => {
const { id, rss_json } = args;
const items = rss_json.rss.channel.item
const max_episode = items.length

    ctx.db.patch(id, { number_of_episodes: max_episode })
    for (const [index, item] of rss_json.rss.channel.item.entries()) {
        const e_n = Math.ceil(max_episode - index)
        console.log("podcast_id:%s episode_number:%", args.id, e_n)
        const episode = await ctx.db.query("episode")
            .withIndex("podcast_episode_number")
            .filter((q) => q.and(q.eq(q.field("podcast_id"), args.id), q.eq(q.field("episode_number"), e_n)))
            .unique()
        // patch or insert
        if (episode) {
            ctx.db.patch(episode._id, {
                podcast_id: args.id,
                episode_number: Math.ceil(max_episode - index),
                body: item
            })
        } else {
            ctx.db.insert("episode", {
                podcast_id: args.id,
                episode_number: Math.ceil(max_episode - index),
                body: item
            })
        // }
    }`
#

the body can be large, but I think the problem is that its looping over all the episodes for a podcast in one transaction

#

it works fine if it just inserts, but it blows up if its running the query too

sharp basin
#

looks like my syntax is wrong

#

const episode = await ctx.db.query("episode")
.withIndex("podcast_episode_number")
.filter((q) => q.and(q.eq(q.field("podcast_id"), args.id), q.eq(q.field("episode_number"), e_n)))