Skip to content

refactor: use pragma method in better-sqlite3 - #10684

Merged
gioboa merged 2 commits into
typeorm:masterfrom
mohd-akram:improve-better-sqlite3
Dec 1, 2025
Merged

gioboa merged 2 commits into
typeorm:masterfrom
mohd-akram:improve-better-sqlite3

Conversation

@mohd-akram

Copy link
Copy Markdown
Contributor

Description of change

Use the pragma method in better-sqlite3. This is the recommended way to run pragmas.

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • npm run format to apply prettier formatting
  • npm run test passes with this change
  • The new commits follow conventions explained in CONTRIBUTING.md

This is the recommended way to run pragmas.

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you @mohd-akram for your help.
Are any drawbacks about this change?

@mohd-akram

Copy link
Copy Markdown
Contributor Author

@gioboa No drawbacks that I'm aware of.

@gioboa

gioboa commented Jan 22, 2025

Copy link
Copy Markdown
Collaborator

@gioboa No drawbacks that I'm aware of.

Thanks 👍

@alumni

alumni commented Jan 22, 2025 •

Copy link
Copy Markdown
Collaborator

Are any drawbacks about this change?

If you want to use bun's sqlite driver (similar to better-sqlite3), it won't have the pragma method 😛

Bun-related issue: #11236

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

So this is not working with bun 🤔
An idea is to check the runtime and create a condition in the code eg. detect Bun.
What do you think?

@alumni

alumni commented Jan 24, 2025 •

Copy link
Copy Markdown
Collaborator

We don't support bun at the moment, so my comment was there just in case we would like to 🤷🏻

I played a bit with bun:sqlite and I was able get it to work with typeorm for a basic use case with only with 2 minor changes (see the linked issue).

Later edit: bun has a ticket to add support for .pragma: oven-sh/bun#2023

@angelxmoreno

Copy link
Copy Markdown

what is the status of this PR? have the admins agreed or disagreed to review/merge this work?

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It looks good to me
Thanks @mohd-akram

@seepine seepine mentioned this pull request Sep 20, 2025
2 of 18 tasks
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Code Suggestions ✨

No code suggestions found for the PR.

@pkg-pr-new

pkg-pr-new Bot commented Dec 1, 2025

Copy link
Copy Markdown
  • typeorm-sql-js-example

    npm i https://pkg.pr.new/typeorm/typeorm@10684
    

commit: d435d68

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 80.758%. remained the same
when pulling d435d68 on mohd-akram:improve-better-sqlite3
into c4f5d12 on typeorm:master.

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Tests are fine.
What's the benefit of using pragma ? is it faster? reliable?

@alumni

alumni commented Dec 1, 2025

Copy link
Copy Markdown
Collaborator

hmm, better-sqlite3 does not mention exactly what:

It's better to use this method instead of normal prepared statements when executing PRAGMA, because this method normalizes some odd behavior that may otherwise be experienced.

https://github.com/WiseLibs/better-sqlite3/blob/master/docs/api.md#pragmastring-options---results

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for your help @mohd-akram

@gioboa
gioboa merged commit ec3ea10 into typeorm:master Dec 1, 2025
@mohd-akram
mohd-akram deleted the improve-better-sqlite3 branch December 1, 2025 21:44
ThbltLmr pushed a commit to ThbltLmr/typeorm that referenced this pull request Dec 2, 2025
mgohin pushed a commit to mgohin/typeorm that referenced this pull request Jan 15, 2026
kranners pushed a commit to kranners/typeorm that referenced this pull request Mar 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants