Giter Club home page Giter Club logo

tauri-plugin-sqlite-drizzle's Introduction

Tauri Plugin SQLite

license

This plugin provides a "classical" Tauri Plugin interface to SQLite database through sqlite.

Installation

Rust

src-tauri/Cargo.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

fn main() {
    tauri::Builder::default()
        .plugin(tauri_plugin_sqlite::init())
        .build()
        .run();
}

JavaScript/TypeScript

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<Array<{ count: number }>>('SELECT COUNT(*) as count FROM users')

/** select with param */
const rows = await db.select<Array<{ name: string }>>('SELECT name FROM users WHERE age > ?', [20])

/** select with params, you can use ? or $1 .. $n */
const rows = await db.select<Array<any>>('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

tauri-plugin-sqlite-drizzle's People

Contributors

jstbyte avatar lzdyes avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.