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

sqlite,test,doc: accept Buffer and URL as paths #56991

Merged
merged 12 commits into from
Feb 27, 2025

Conversation

geeksilva97
Copy link
Contributor

@geeksilva97 geeksilva97 commented Feb 10, 2025

Closes #56940

This PR adds the capability to the sqlite module to accept Buffer and URL as the database location.

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. sqlite Issues and PRs related to the SQLite subsystem. labels Feb 10, 2025
@geeksilva97 geeksilva97 force-pushed the sqlite-accept-buffer branch 3 times, most recently from 2a608e1 to 5b5a8cf Compare February 20, 2025 01:37
@geeksilva97 geeksilva97 marked this pull request as ready for review February 20, 2025 01:38
Copy link

codecov bot commented Feb 20, 2025

Codecov Report

Attention: Patch coverage is 88.33333% with 7 lines in your changes missing coverage. Please review.

Project coverage is 90.25%. Comparing base (c864dea) to head (7d1111f).
Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
src/node_sqlite.cc 88.33% 2 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #56991      +/-   ##
==========================================
- Coverage   90.33%   90.25%   -0.08%     
==========================================
  Files         630      630              
  Lines      184537   184681     +144     
  Branches    36077    36138      +61     
==========================================
- Hits       166693   166686       -7     
- Misses      10950    11021      +71     
- Partials     6894     6974      +80     
Files with missing lines Coverage Δ
src/node_sqlite.cc 78.79% <88.33%> (+0.21%) ⬆️

... and 29 files with indirect coverage changes

@geeksilva97 geeksilva97 force-pushed the sqlite-accept-buffer branch 4 times, most recently from 06d30bf to 4561203 Compare February 21, 2025 12:49
@geeksilva97 geeksilva97 changed the title [WIP] sqlite,test,doc: accept Buffer and URL as paths sqlite,test,doc: accept Buffer and URL as paths Feb 21, 2025
@cjihrig
Copy link
Contributor

cjihrig commented Feb 25, 2025

I think this needs a rebase to fix the CI issue.

cc: @nodejs/sqlite since this PR was opened before the team existed.

@@ -256,6 +274,15 @@ suite('DatabaseSync.prototype.exec()', () => {
});
});

test('throws if the URL does not have the file: scheme', (t) => {
Copy link
Contributor

@louwers louwers Feb 25, 2025

Choose a reason for hiding this comment

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

You should also check the happy path.

Can you try URL("file://path/to/db.db?mode=ro") and verify that writes error out?

Passing a file:// or file: as URL as a string or Buffer should also be supported.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@nodejs-github-bot
Copy link
Collaborator

@cjihrig cjihrig requested a review from Copilot February 26, 2025 17:39

Choose a reason for hiding this comment

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

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

test/parallel/test-sqlite-backup.mjs:53

  • [nitpick] Consider clarifying the error message terminology: while a Buffer is used in tests, the message refers to Uint8Array. Explicitly mentioning Buffer (or clarifying that Buffer is acceptable since it is a Uint8Array) could reduce potential confusion.
message: 'The "destination" argument must be a string, Uint8Array, or URL without null bytes.'

test/parallel/test-sqlite-database-sync.js:31

  • [nitpick] For consistency with tests using Buffer objects, consider updating the error message to explicitly mention Buffer, or note that Buffer instances are valid as they are a subtype of Uint8Array.
message: /The "path" argument must be a string, Uint8Array, or URL without null bytes/
@cjihrig
Copy link
Contributor

cjihrig commented Feb 26, 2025

You can ignore the review by Copilot. I was curious to see if it would generate anything helpful.

There are actual failures on Windows in the CI though:

duration_ms: 385.002
exitcode: 1
severity: fail
stack: |-
  (node:6684) ExperimentalWarning: SQLite is an experimental feature and might change at any time
  (Use `node --trace-warnings ...` to show where the warning was created)
  Can't clean tmpdir: c:\workspace\node-test-binary-windows-js-suites\node\test\.tmp.736
  Files blocking: [ 'database-2.db', 'database-3.db' ]

  c:\workspace\node-test-binary-windows-js-suites\node\test\common\tmpdir.js:80
      throw e;
      ^

  Error: EPERM, Permission denied: \\?\c:\workspace\node-test-binary-windows-js-suites\node\test\.tmp.736 '\\?\c:\workspace\node-test-binary-windows-js-suites\node\test\.tmp.736'
      at Object.rmSync (node:fs:1246:18)
      at rmSync (c:\workspace\node-test-binary-windows-js-suites\node\test\common\tmpdir.js:31:8)
      at onexit (c:\workspace\node-test-binary-windows-js-suites\node\test\common\tmpdir.js:65:5)
      at process.<anonymous> (c:\workspace\node-test-binary-windows-js-suites\node\test\common\tmpdir.js:54:14)
      at process.emit (node:events:519:35) {
    errno: 1,
    code: 'EPERM',
    path: '\\\\?\\c:\\workspace\\node-test-binary-windows-js-suites\\node\\test\\.tmp.736',
    syscall: 'rm'
  }

  Node.js v24.0.0-pre

@geeksilva97
Copy link
Contributor Author

geeksilva97 commented Feb 26, 2025

You can ignore the review by Copilot. I was curious to see if it would generate anything helpful.

There are actual failures on Windows in the CI though:

duration_ms: 385.002
exitcode: 1
severity: fail
stack: |-
  (node:6684) ExperimentalWarning: SQLite is an experimental feature and might change at any time
  (Use `node --trace-warnings ...` to show where the warning was created)
  Can't clean tmpdir: c:\workspace\node-test-binary-windows-js-suites\node\test\.tmp.736
  Files blocking: [ 'database-2.db', 'database-3.db' ]

  c:\workspace\node-test-binary-windows-js-suites\node\test\common\tmpdir.js:80
      throw e;
      ^

  Error: EPERM, Permission denied: \\?\c:\workspace\node-test-binary-windows-js-suites\node\test\.tmp.736 '\\?\c:\workspace\node-test-binary-windows-js-suites\node\test\.tmp.736'
      at Object.rmSync (node:fs:1246:18)
      at rmSync (c:\workspace\node-test-binary-windows-js-suites\node\test\common\tmpdir.js:31:8)
      at onexit (c:\workspace\node-test-binary-windows-js-suites\node\test\common\tmpdir.js:65:5)
      at process.<anonymous> (c:\workspace\node-test-binary-windows-js-suites\node\test\common\tmpdir.js:54:14)
      at process.emit (node:events:519:35) {
    errno: 1,
    code: 'EPERM',
    path: '\\\\?\\c:\\workspace\\node-test-binary-windows-js-suites\\node\\test\\.tmp.736',
    syscall: 'rm'
  }

  Node.js v24.0.0-pre

Thanks, Colin. I had forgotten to close the database connection 😅

Comment on lines +638 to +641
if (file_url->type != ada::scheme::FILE) {
THROW_ERR_INVALID_URL_SCHEME(env->isolate());
return std::nullopt;
}
Copy link
Contributor Author

@geeksilva97 geeksilva97 Feb 26, 2025

Choose a reason for hiding this comment

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

I removed the FileURLToPath because it was stripping the query params out. We should keep them since SQLite supports them.

Guaranteeing that a valid URL is given we can return the URL href it is.

@geeksilva97 geeksilva97 force-pushed the sqlite-accept-buffer branch 3 times, most recently from 22e4331 to e145acb Compare February 27, 2025 01:07
@cjihrig cjihrig added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 27, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 27, 2025
@nodejs-github-bot
Copy link
Collaborator

@cjihrig cjihrig added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. and removed needs-ci PRs that need a full CI run. labels Feb 27, 2025
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Feb 27, 2025
@nodejs-github-bot nodejs-github-bot merged commit c7cf677 into nodejs:main Feb 27, 2025
66 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in c7cf677

aduh95 pushed a commit that referenced this pull request Mar 9, 2025
PR-URL: #56991
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. sqlite Issues and PRs related to the SQLite subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make sqlite module consitent with other modules like fs
5 participants