Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lzdyes/tauri-plugin-sqlite
A Tauri plugin for interface to SQLite
https://github.com/lzdyes/tauri-plugin-sqlite
database rust sqlite tauri tauri-plugin typescript
Last synced: 4 days ago
JSON representation
A Tauri plugin for interface to SQLite
- Host: GitHub
- URL: https://github.com/lzdyes/tauri-plugin-sqlite
- Owner: lzdyes
- License: mit
- Created: 2022-05-07T13:38:02.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-07-11T02:31:47.000Z (over 2 years ago)
- Last Synced: 2024-04-27T14:31:33.612Z (7 months ago)
- Topics: database, rust, sqlite, tauri, tauri-plugin, typescript
- Language: Rust
- Homepage:
- Size: 26.4 KB
- Stars: 91
- Watchers: 4
- Forks: 12
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Tauri Plugin SQLite
[![license](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
This plugin provides a "classical" Tauri Plugin interface to SQLite database through [sqlite](https://github.com/stainless-steel/sqlite).
## Installation
### Rust
`src-tauri/Cargo.toml`
```toml
[dependencies.tauri-plugin-sqlite]
git = "https://github.com/lzdyes/tauri-plugin-sqlite"
tag = "v0.1.1"
```### Webview
```
npm install github:lzdyes/tauri-plugin-sqlite#v0.1.1
# or
yarn add github:lzdyes/tauri-plugin-sqlite#v0.1.1
```## Usage
### Rust
`src-tauri/src/main.rs`
```rust
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_sqlite::init())
.build()
.run();
}
```### JavaScript/TypeScript
```ts
import SQLite from 'tauri-plugin-sqlite-api'/** The path will be 'src-tauri/test.db', you can customize the path */
const db = await SQLite.open('./test.db')/** execute SQL */
await db.execute(`
CREATE TABLE users (name TEXT, age INTEGER);
INSERT INTO users VALUES ('Alice', 42);
INSERT INTO users VALUES ('Bob', 69);
`)/** execute SQL with params */
await db.execute('INSERT INTO users VALUES (?1, ?2)', ['Jack', 18])/** batch execution SQL with params */
await db.execute('INSERT INTO users VALUES (?1, ?2)', [
['Allen', 20],
['Barry', 16],
['Cara', 28],
])/** select count */
const rows = await db.select>('SELECT COUNT(*) as count FROM users')/** select with param */
const rows = await db.select>('SELECT name FROM users WHERE age > ?', [20])/** select with params, you can use ? or $1 .. $n */
const rows = await db.select>('SELECT * FROM users LIMIT $1 OFFSET $2', [10, 0])/** close sqlite database */
const isClosed = await db.close()
```## Contribute
Contributions are welcome! please open issues and pull request :)
## License
[MIT](LICENSE)