|
1 | | -# tauri-plugin-sqlite |
| 1 | +# Tauri SQLite Plugin |
| 2 | + |
| 3 | +[![CI][ci-badge]][ci-url] |
| 4 | + |
| 5 | +A Tauri plugin for SQLite database access with connection management. This plugin |
| 6 | +depends on [SQLx](https://github.com/launchbadge/sqlx) and enforces pragmatic policies |
| 7 | +for connection management. |
| 8 | + |
| 9 | +[ci-badge]: https://github.com/silvermine/tauri-plugin-sqlite/actions/workflows/ci.yml/badge.svg |
| 10 | +[ci-url]: https://github.com/silvermine/tauri-plugin-sqlite/actions/workflows/ci.yml |
| 11 | + |
| 12 | +## Project Structure |
| 13 | + |
| 14 | +This project is organized as a Cargo workspace with the following structure: |
| 15 | + |
| 16 | +```text |
| 17 | +tauri-plugin-sqlite/ |
| 18 | +├── crates/ |
| 19 | +│ └── sqlx-sqlite-conn-mgr/ # SQLx SQLite connection pool manager |
| 20 | +│ ├── src/ |
| 21 | +│ │ └── lib.rs |
| 22 | +│ └── Cargo.toml |
| 23 | +├── src/ # Tauri plugin implementation |
| 24 | +│ ├── commands.rs # Plugin commands |
| 25 | +│ ├── error.rs # Error types |
| 26 | +│ ├── lib.rs # Main plugin code |
| 27 | +│ └── models.rs # Data models |
| 28 | +├── guest-js/ # JavaScript/TypeScript bindings |
| 29 | +│ ├── index.ts |
| 30 | +│ └── tsconfig.json |
| 31 | +├── permissions/ # Permission definitions (mostly generated) |
| 32 | +├── dist-js/ # Compiled JS (generated) |
| 33 | +├── Cargo.toml # Workspace configuration |
| 34 | +├── package.json # NPM package configuration |
| 35 | +└── build.rs # Build script |
| 36 | +``` |
| 37 | + |
| 38 | +## Crates |
| 39 | + |
| 40 | +### sqlx-sqlite-conn-mgr |
| 41 | + |
| 42 | +A pure Rust module with no dependencies on Tauri or its plugin architecture. It |
| 43 | +provides connection management for SQLite databases using SQLx. It's designed to be |
| 44 | +published as a standalone crate in the future with minimal changes. |
| 45 | + |
| 46 | +See [`crates/sqlx-sqlite-conn-mgr/README.md`](crates/sqlx-sqlite-conn-mgr/README.md) |
| 47 | +for more details. |
| 48 | + |
| 49 | +### Tauri Plugin |
| 50 | + |
| 51 | +The main plugin provides a Tauri integration layer that exposes SQLite functionality |
| 52 | +to Tauri applications. It uses the `sqlx-sqlite-conn-mgr` module internally. |
| 53 | + |
| 54 | +## Getting Started |
| 55 | + |
| 56 | +### Installation |
| 57 | + |
| 58 | +1. Install NPM dependencies: |
| 59 | + |
| 60 | + ```bash |
| 61 | + npm install |
| 62 | + ``` |
| 63 | + |
| 64 | +2. Build the TypeScript bindings: |
| 65 | + |
| 66 | + ```bash |
| 67 | + npm run build |
| 68 | + ``` |
| 69 | + |
| 70 | +3. Build the Rust plugin: |
| 71 | + |
| 72 | + ```bash |
| 73 | + cargo build |
| 74 | + ``` |
| 75 | + |
| 76 | +### Tests |
| 77 | + |
| 78 | +Run Rust tests: |
| 79 | + |
| 80 | +```bash |
| 81 | +cargo test |
| 82 | +``` |
| 83 | + |
| 84 | +### Linting and standards checks |
| 85 | + |
| 86 | +```bash |
| 87 | +npm run standards |
| 88 | +``` |
| 89 | + |
| 90 | +## Usage |
| 91 | + |
| 92 | +### In a Tauri Application |
| 93 | + |
| 94 | +Add the plugin to your Tauri application's `Cargo.toml`: |
| 95 | + |
| 96 | +```toml |
| 97 | +[dependencies] |
| 98 | +tauri-plugin-sqlite = { path = "../path/to/tauri-plugin-sqlite" } |
| 99 | +``` |
| 100 | + |
| 101 | +Initialize the plugin in your Tauri app: |
| 102 | + |
| 103 | +```rust |
| 104 | +fn main() { |
| 105 | + tauri::Builder::default() |
| 106 | + .plugin(tauri_plugin_sqlite::init()) |
| 107 | + .run(tauri::generate_context!()) |
| 108 | + .expect("error while running tauri application"); |
| 109 | +} |
| 110 | +``` |
| 111 | + |
| 112 | +### JavaScript/TypeScript API |
| 113 | + |
| 114 | +Install the JavaScript package in your frontend: |
| 115 | + |
| 116 | +```bash |
| 117 | +npm install @silvermine/tauri-plugin-sqlite |
| 118 | +``` |
| 119 | + |
| 120 | +Use the plugin from JavaScript: |
| 121 | + |
| 122 | +```typescript |
| 123 | +// TODO: Add real examples once we have decided on the plugin API |
| 124 | +import { hello } from '@silvermine/tauri-plugin-sqlite'; |
| 125 | + |
| 126 | +// Call the hello command |
| 127 | +const greeting = await hello('World'); |
| 128 | +console.log(greeting); // "Hello, World! This is the SQLite plugin." |
| 129 | +``` |
| 130 | + |
| 131 | +## Development Standards |
| 132 | + |
| 133 | +This project follows the |
| 134 | +[Silvermine standardization](https://github.com/silvermine/standardization) |
| 135 | +guidelines. Key standards include: |
| 136 | + |
| 137 | + * **EditorConfig**: Consistent editor settings across the team |
| 138 | + * **Markdownlint**: Markdown linting for documentation |
| 139 | + * **Commitlint**: Conventional commit message format |
| 140 | + * **Code Style**: 3-space indentation, LF line endings |
| 141 | + |
| 142 | +### Running Standards Checks |
| 143 | + |
| 144 | +```bash |
| 145 | +npm run standards |
| 146 | +``` |
| 147 | + |
| 148 | +## License |
| 149 | + |
| 150 | +MIT |
| 151 | + |
| 152 | +## Contributing |
| 153 | + |
| 154 | +Contributions are welcome! Please follow the established coding standards and commit |
| 155 | +message conventions. |
0 commit comments