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

[libsql] Add null check to normalizeRow #1050

Closed
wants to merge 8 commits into from

Conversation

lightyaer
Copy link

A simple null check for normalizeRow function in libsql.

Fixes: #1049

let me know if this is a correct fix, I'm happy to learn more about this and implement any suggestions.
Thanks.

@lightyaer lightyaer changed the title Add null check to normalizeRow in libsql [libsql] Add null check to normalizeRow Aug 15, 2023
Copy link
Contributor

@dankochetov dankochetov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test that verifies this behavior.

drizzle-orm/src/libsql/session.ts Outdated Show resolved Hide resolved
@lightyaer
Copy link
Author

@dankochetov
I found out that the normalizedRow function gets undefined, when we don't use returning() before get(),

We do have type-tests for this, but this behaviour is kinda weird, ideally, we shouldn't have a get() function in intellisense (dropdown on a dot after a function in IDE) incase of libsql after the values(), onConflictDoNothing() and onConflictDoUpdate(), incase of libsql.

I have changed the PR to throw an error incase we use get() without returning() in libsql.

Let me know, if the error message is good to go.

Code used to reproduce the error:

      const x = {
            id: "asd",
            createdAt: new Date().toISOString(),
            email: "[email protected]",
            emailVerified: new Date().toISOString(),
            updatedAt: new Date().toISOString(),
            name: "asdasd",
            picture: "asdasd",
            username: "asdoihsdfo",
        };

        const newUser = await db
            .insert(users)
            .values(x)
            .onConflictDoUpdate({
                target: users.email,
                set: {
                    email: `${new Date().getTime()}@gmail.com`,
                    id: `${new Date().getTime()}-sodhfoh`,
                    updatedAt: new Date().toString(),
                    name: `askd${new Date().getTime()}`,
                },
            })
            // no returning()
            .get()
           


        console.log(newUser.id);

The following images show when id is being accessed from newUser

In webstorm

Screenshot 2023-08-27 at 2 15 59 PM

In vscode.

Screenshot 2023-08-27 at 2 15 48 PM

@lightyaer
Copy link
Author

closing out his PR since the purpose of this was fulfilled elsewhere.

@lightyaer lightyaer closed this Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG]: libsql error's out while inserting
3 participants