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

docs: add comments for UpdateResult #993

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

movahhedi
Copy link

@movahhedi movahhedi commented May 18, 2024

Closes #988.
References #428, #431.

Based on:

/**
* This is defined for insert, update, delete and merge queries and contains
* the number of rows the query inserted/updated/deleted.
*/
readonly numAffectedRows?: bigint
/**
* This is defined for update queries and contains the number of rows
* the query changed.
* This is optional and only provided by some drivers like node-mysql2.
*/
readonly numChangedRows?: bigint

Copy link

vercel bot commented May 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
kysely ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 29, 2024 11:53am

@igalklebanov igalklebanov added the documentation Improvements or additions to documentation label May 18, 2024
@movahhedi
Copy link
Author

movahhedi commented May 18, 2024

Although I've written the comment, I haven't yet truly understood what "Changed Rows" means.
I've seen these words:

  • Matched rows
  • Affected rows
  • Updated rows
  • Changed rows

What do each mean? Can we make the comment any better?

Correct me if I'm wrong:

  • Matched rows: Rows that match the condition[s] of any query.
  • Affected rows: Rows that have been affected (inserted, updated [even if not changed], or deleted) by an INSERT/UPDATE/DELETE query.
  • Updated rows: Rows affected by an UPDATE query, even if the content of it hasn't changed after the execution of the query.
  • Changed rows: Rows affected by an UPDATE query that had their content changed.

@igalklebanov
Copy link
Member

igalklebanov commented May 27, 2024

  • Matched rows: Rows that match the condition[s] of any query.

No such concept.

  • Affected rows: Rows that have been affected (inserted, updated [even if not changed], or deleted) by an INSERT/UPDATE/DELETE query.

Kind of. It varies per query kind, at least in MySQL.
https://dev.mysql.com/doc/c-api/8.0/en/mysql-affected-rows.html

  • Updated rows: Rows affected by an UPDATE query, even if the content of it hasn't changed after the execution of the query.

No such concept outside of Kysely. It is the affected rows value under a different, friendlier, and fitting to context, name.

  • Changed rows: Rows affected by an UPDATE query that had their content changed.

I'm not sure this is only relevant to UPDATE. Might be also relevant to INSERT INTO ... ON DUPLICATE KEY UPDATE. And yes, it counts only the rows that actually had column values change.

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

Successfully merging this pull request may close these issues.

Documentation for UpdateResult
2 participants