Updating linked values from a table in edge-db using JavaScript Client returns error

36 Views Asked by At
import * as edgedb from 'edgedb';
import e from '../../dbschema/edgeql-js';

const client = edgedb.createClient();


let query = await e.params({ items: e.json }, (params) => {
            return e.for(e.json_array_unpack(params.items), (item) => {
                return e.update(e.basic_details, () => ({
                    filter_single: { id: resumeId },
                    set: {
                        name: e.cast(e.str, item.name),
                        email: e.cast(e.str, item.email),
                        phone: e.cast(e.str, item.phone),
                        designation: e.cast(e.str, item.designation),
                        summary: e.cast(e.str, item.summary),
                        template_design_type: e.cast(e.str, item.template_design_type),
                        address: e.update(e.address, () => ({
                            filter_single: { id: e.cast(e.uuid, item.address.id) },
                            set: {
                                address: e.cast(e.str, item.address.address),
                                city: e.cast(e.str, item.address.city),
                                country: e.cast(e.str, item.address.country),
                                state: e.cast(e.str, item.address.state),
                                postal_code: e.cast(e.str, item.address.postal_code)
                            }
                        })),
                        social_media: e.for(
                            e.op(
                                "distinct", e.json_array_unpack(item.social_media)), (sm) => {
                                    return e.insert(e.social_media, {
                                        id: e.cast(e.uuid, sm.id),
                                        platform: e.cast(e.str, sm.platform),
                                        url: e.cast(e.str, sm.url)
                                    }).unlessConflict((socail) => ({
                                        on: socail.id,
                                        else: e.update(e.social_media, () => ({
                                            filter_single: {id: e.cast(e.uuid, socail.id)},
                                            set: {
                                                platform: e.cast(e.str, socail.platform),
                                                url: e.cast(e.str, socail.url)
                                            }
                                        }))
                                    }))
                                }
                        )
                    }
                }));
            });
        });
        const result = await query.run(client, { items: Array.isArray(data) ? data : [data] });

with this code I'm trying to update social_media table with the link from basic_details. but it is returning

web-1     | QueryError: cannot assign to property 'id'
web-1     |     |
web-1     |  33 |           id := <std::uuid>(__forVar__1["id"]),
web-1     |     |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1     | Hint: consider enabling the "allow_user_specified_id" configuration parameter to allow setting custom object ids

Actually i don't want to enable the configuration. is there any way to fix this issue. or a better method to update the link.

i tried removing the id social_media insert section on that it was returning

web-1     | UnsupportedFeatureError: INSERT UNLESS CONFLICT ON does not support volatile properties
web-1     |     |
web-1     |  32 |         (INSERT default::social_media {
web-1     |     |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1     |  33 |           platform := <std::str>(__forVar__1["platform"]),
web-1     |     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1     |  34 |           url := <std::str>(__forVar__1["url"])
web-1     |     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1     |  35 |         }
web-1     |     | ^^^^^^^^^
web-1     |  36 |         UNLESS CONFLICT ON default::social_media.id
web-1     |     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1     |  37 |         ELSE ((WITH
web-1     |     | ^^^^^^^^^^^^^^^^^^^
web-1     |  38 |           __scope_2_defaultsocialmedia := default::social_media
web-1     |     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1     |  39 |         UPDATE __scope_2_defaultsocialmedia
web-1     |     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1     |  40 |         FILTER (__scope_2_defaultsocialmedia.id = <std::uuid>(DETACHED default::social_media.id))
web-1     |     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1     |  41 |         SET {
web-1     |     | ^^^^^^^^^^^^^
web-1     |  42 |           platform := <std::str>(DETACHED default::social_media.platform),
web-1     |     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
web-1     |  43 |           url := <std::str>(DETACHED default::social_media.url)
web-1     |     | ^

where is the issue and what should i do?

1

There are 1 best solutions below

0
On

i found a different method to update the link. i can update and add item to the link with with. but still I'm unable to delete the links that are removed

attaching the updated code for updating link as i mentioned above

let query = e.update(e.basic_details, () => ({
        filter_single: { id: resumeId },
        set: {
            name: data.name,
            email: data.email,
            phone: data.phone,
            designation: data.designation,
            summary: data.summary,
            template_design_type: data.template_design_type,
            address: e.update(e.address, () => ({
                filter_single: { id: data.address.id },
                set: {
                    address: data.address.address,
                    city: data.address.city,
                    country: data.address.country,
                    state: data.address.state,
                    postal_code: data.address.postal_code
                }
            })),
            social_media: e.assert_distinct(
                e.set(
                    ...data.social_media.map((sm) => {
                        if (sm.id)
                            return e.update(e.social_media, () => ({
                                filter_single: { id: sm.id },
                                set: {
                                    platform: sm.platform,
                                    url: sm.url
                                }
                            }));
                        else
                            return e.insert(e.social_media, {
                                platform: sm.platform,
                                url: sm.url
                            });
                    })
                )
            ),
        }
    }));