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(sql): support for SQLite pragma and encryption pragmas #2553

Open
wants to merge 4 commits into
base: v2
Choose a base branch
from

Conversation

HuakunShen
Copy link

@HuakunShen HuakunShen commented Mar 20, 2025

resolve #7

  • Introduced libsqlite3-sys dependency for SQLite support.
  • Updated the load method to accept optional pragmas for database connections.
  • Enhanced the JavaScript API to demonstrate loading databases with encryption keys and custom pragmas.
  • Added VSCode settings for Rust analyzer to enable SQLite feature, to facilitate development.
  • Updated Rust code to handle SQLite options and pragmas in the database connection logic.

Now sqlite encryption can be enabled like this.

const db = await Database.load("sqlite:encrypted.db", {
  sqlite: { pragmas: { "key": "encryption_key" } }
});

I already tested on Mac, further testing needed on Windows and Linux.

- Introduced `libsqlite3-sys` dependency for SQLite support.
- Updated the `load` method to accept optional pragmas for database connections.
- Enhanced the JavaScript API to demonstrate loading databases with encryption keys and custom pragmas.
- Added VSCode settings for Rust analyzer to enable SQLite feature, to facilitate development.
- Updated Rust code to handle SQLite options and pragmas in the database connection logic.
@HuakunShen HuakunShen requested a review from a team as a code owner March 20, 2025 12:01
@HuakunShen
Copy link
Author

Preload doesn't support pragma yet, because that will introduce breaking APIs here

preload: Vec<String>,

If we have to support pragma in preload, then maybe something like this?

{
  "plugins": {
    "sql": {
      "preload": ["sqlite:mydatabase.db"],
      "sqlite_options": {
        "sqlite:mydatabase.db": {
          "pragmas": {
            "journal_mode": "WAL",
            "foreign_keys": "ON"
          }
        }
      }
    }
  }
}

@HuakunShen
Copy link
Author

HuakunShen commented Mar 21, 2025

I realized one problem, there are two load commands now, one for sqlite one for others. So the current implementation doesn't support multiple features. Either sqlite only or turn off sqlite feature.
Will need a more robust design.

Problem fixed, the latest version supports connecting to sqlite, mysql and postgres at the same time

@haexhub
Copy link

haexhub commented Mar 25, 2025

I'm desperately waiting for this feature

@HuakunShen
Copy link
Author

HuakunShen commented Mar 25, 2025

I'm desperately waiting for this feature

No one is reviewing this PR.

In the meanwhile, if anyone wants to try this, you can set dependency to my branch in Cargo.toml.
And for JS dependency, you may want to clone my branch and link to it with pnpm/npm/bun link.

@roniemartinez
Copy link

+1 on this! I am also waiting to move from my custom implementation to fully adapting to this plugin. Thanks for the PR!

@HuakunShen
Copy link
Author

+1 on this! I am also waiting to move from my custom implementation to fully adapting to this plugin. Thanks for the PR!

I was also using my custom implementation with cipher using rusqlite.
While I made this PR, it will be a lot of work to migrate from my implementation to this.
And I want to at least wait til this PR get merged to migrate.

BTW I also figured out how to use drizzle to work with this sql plugin and also rusqlite.
Working with sqlite in Tauri now feels like in Electron.

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.

[sql] SQLCipher Encryption
3 participants