kysely icon indicating copy to clipboard operation
kysely copied to clipboard

Support "returning" functionality for MySQL dialect

Open kiryasolod opened this issue 1 year ago • 1 comments

Hi everyone! Thanks for such a great library! Could you please add "returning" functionality for MySQL? MySQL supports it from version 8.0.27 Thanks!

kiryasolod avatar Sep 05 '24 23:09 kiryasolod

Yep, let's do this.

For now you should be able to enable it by overriding one property of MysqlAdapter https://kyse.link/MYZCF.

koskimas avatar Sep 10 '24 04:09 koskimas

Where is the source on this? Can you provide a link to the docs? I'm on MySQL 8.0.31 and if I try to use RETURNING on INSERT it throws an error.

thelinuxlich avatar Oct 24 '24 14:10 thelinuxlich

No mention of RETURNING here: https://dev.mysql.com/doc/refman/8.4/en/insert.html

thelinuxlich avatar Oct 24 '24 14:10 thelinuxlich

No such thing in MySQL. https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-27.html

igalklebanov avatar Oct 24 '24 15:10 igalklebanov

Sorry to raise an old thread, but using a mysql adapter and chaining a returning or returningAll method, it seems as though Kysely produces invalid SQL

input

await db
  .insertInto("pet")
  .values({
    name: "Fluffy",
    owner_id: 1,
    species: "hamster",
  })
  .returningAll()
  .executeTakeFirstOrThrow();

output

INSERT INTO
  `pet` (`name`, `owner_id`, `species`)
VALUES
  (?, ?, ?) returning *

AFAICT there are no versions of mysql which support RETURNING, so I would expect, at the very least, for this to raise a type error.

I'm running MySQL 8.4.3 and the above SQL query returns the following error:

Query 1 ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'returning *' at line 4

Just wanted to double check before opening a new issue, I rarely work with mysql so my knowledge may be inaccurate.

christiannaths avatar Feb 18 '25 21:02 christiannaths

Hey @christiannaths 👋

Kysely outputs what you want it to. WYSIWYG and Bring Your Own SQL Knowledge are core principles.

igalklebanov avatar Feb 19 '25 05:02 igalklebanov

@igalklebanov Ok, got it. Thanks for the reply :)

christiannaths avatar Feb 19 '25 14:02 christiannaths