-
Notifications
You must be signed in to change notification settings - Fork 32
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
help: intsert data and get id #137
Comments
Hey there. you actually have an extra, unnecessary query in there. You can just run |
By the way, here's a link to the code in question: https://github.com/planetscale/database-js/blob/main/src/index.ts#L34 If you do |
Hmmm, okay that's interesting. We'll look into insertId not working with UUIDs, do you know if the equivalent works with regular MySQL? |
Okay, @vatheara , I found the problem. This is a MySQL level constraint. According to MySQL's documentation, |
To add to this, part of the benefits of UUIDs as well in practice is that you can generate the ID client side, which it appears you're doing. It appears you're doing like: const params = {id: uuid(), ...} This So you could either do like, const userId = uuid();
const params = {id: userId}; Or just grab const params = {id: uuid()};
...
const userId = params.id; There's not particularly a reason to fetch this from the server. If the INSERT succeeded, you already have the ID you need. And a last point, the syntax you're referring to, specifically |
Appreciate it thanks you! |
@iheanyi I see that |
That's how MySQL works, it'll return the last insert id when auto incrementing. But this guarantees they are sequential within a single batch, so if you wrote 5 rows, you know the range is |
i try to do this but got syntax error
is there anyway to get the id of the inserted data ?
The text was updated successfully, but these errors were encountered: