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

feat(database): add support for BunSQLite and refactor related code #2944

Merged
merged 9 commits into from
Jan 7, 2025

Conversation

felixrydberg
Copy link
Contributor

@felixrydberg felixrydberg commented Jan 2, 2025

πŸ”— Linked issue

#2936

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Resolves #2936

Added bun:sqlite as an alternative to better-sqlite-3, both for database and _localDatabase config options.
Refactored localDatabase function that used better-sqlite-3 to be extendable with more options in the future.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@felixrydberg
Copy link
Contributor Author

I havnt updated the documentation yet, Just want to discuss which category or section I should put it in

src/module.ts Outdated
Comment on lines 96 to 102
if (!process.versions.bun && options.database.type === 'bunsqlite') {
logger.warn('BunSQLite is not available in this environment. Falling back to SQLite.')
options.database = {
type: 'sqlite',
filename: options.database.filename,
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This is a duplicate of previous if
Lets change it and check for using sqlite in bun environment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Im checking both the _localDatabase aswell as the database key in options. Dont we want to check both?

What we could do is check if the database type is sqlite and then just use the new method getDefaultSqliteAdapter and if there was a mismatch log a warning

Copy link
Member

@farnabaz farnabaz left a comment

Choose a reason for hiding this comment

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

Thank you for the PR
There is an issue that we should fix. running built version with Bun fails because Bun does not support CompressionStream internally.

As for documentation, we can mention bunsqlite alongside other database adapters https://content3.nuxt.dev/docs/getting-started/configuration#database

@farnabaz
Copy link
Member

farnabaz commented Jan 6, 2025

I was wondering what if, instead of creating a separate adapter for bunsqlite we handle bun inside existing sqlite adapter.

This way it would be less confusing and Content will have one sqlite adapter which works in all environments. WDYT?

Added suggested Polyfill

Co-authored-by: Farnabaz <farnabaz@gmail.com>
@felixrydberg
Copy link
Contributor Author

felixrydberg commented Jan 6, 2025

I was wondering what if, instead of creating a separate adapter for bunsqlite we handle bun inside existing sqlite adapter.

This way it would be less confusing and Content will have one sqlite adapter which works in all environments. WDYT?

That would work aswell, I just made it into 2 adapters instead since they will have seperate calls. Bun has taken some stuff from better-sqlite3 when it comes to their methods and overall structure but there are differences. Just thought it better to split the code into 2 different files.

We could remove the options for bun for both _localDatabase and database and just default it to the environment one.

@felixrydberg
Copy link
Contributor Author

@farnabaz I have looked over the things you said and I think I have covered it all.
I did remove all the bunsqlite interfaces along with combinding them into /adapter/sqlite instead of seperate files for each runtime.

Copy link
Member

@farnabaz farnabaz left a comment

Choose a reason for hiding this comment

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

LGTM
Thanks ❀️

@farnabaz farnabaz merged commit db77463 into nuxt:v3 Jan 7, 2025
1 check passed
@felixrydberg
Copy link
Contributor Author

@farnabaz Do you have an estimate on when this will be released?

Copy link
Member

@felixrydberg alpha.9 is released. https://github.com/nuxt/content/releases/tag/v3.0.0-alpha.9

@felixrydberg
Copy link
Contributor Author

@farnabaz I have found a very specific issue with our Polyfill.

I have created a reproduction repo here: https://github.com/felixrydberg/content-bun-error

It works fine when running the output file, but when building it into a single bun executable the polyfill will get an unexpected end of file from node:zlib

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

Successfully merging this pull request may close these issues.

Bettersqlite-3 doesnt work with Bun
2 participants