Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object inserted without calling add/put #1949

Open
pankajmyt opened this issue Apr 2, 2024 · 1 comment
Open

Object inserted without calling add/put #1949

pankajmyt opened this issue Apr 2, 2024 · 1 comment

Comments

@pankajmyt
Copy link

this is my dexie db file

class MytChatDB extends Dexie {

    channel!: Table<Channel, string>;

    constructor() {
        super(`test 123`);

        this.version(1).stores({
            channel: '&uuid, type', // Primary key and indexed props
            user: '&uuid'
        });

        this.channel.mapToClass(Channel);
    }
}

export const db = new MytChatDB();



export default class Member {
    uuid: string = ""
}

export default class Channel {

    uuid: string = "";

    members: Map<string, Member> = new Map();
    
}

we get a packet from server which we parse and try to add it to db

addCreatedGroup = async (res: RawPacket) => {

	const channel = new Channel()

	const channelId = res[Packet.Common.CHANNEL]

	channel.uuid = channelId
	//... other properties

	const myUser = await db.user.get("static-string-id")

	const member = new Member()

	member.uuid = myUser!.uuid
	//... other properties

	channel.members.set(Config.shared.myUUID(), member)

	const dbChannelItem = await db.channel.get(channelId)
	console.log("addCreatedGroup: id:", channelId, dbChannelItem)
	await db.channel.add(channel)
}

we are finding that the Channel object is auto inserted in db without us calling add/put.
if we call add it throws, Key already exists in the object store.\n ConstraintError: Key already exists in the object store

I have tried wrapping the function in dexie.ignoretransaction but that fails.

this is happening in all browsers for me [ latest patched as of date, chrome, safari, macOS 14.4.1 ]
I have tried dexie 3.2.x version and 4.0.1 versions.

@pankajmyt
Copy link
Author

I am sure that object does not exist in db before as I added the hook

 this.channel.hook('creating', function (primKey, obj, transaction) {
            console.log('log in mytChatDB', primKey, obj)
            return undefined
        })

it is able to read from db, then above hook is called, then I get an error of item already exists

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant