From 56f4f8af73da4f965c4f50b1628c260e55b17f78 Mon Sep 17 00:00:00 2001 From: lzdyes Date: Sun, 8 May 2022 18:00:27 +0800 Subject: [PATCH] docs: update README --- README.md | 43 +++++++++++++------------------------------ 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index fd630b6..42076a7 100644 --- a/README.md +++ b/README.md @@ -19,21 +19,12 @@ tag = "v0.1.0" ### Web -`Install from a tagged release` - ``` npm install github:lzdyes/tauri-plugin-sqlite#v0.1.0 # or yarn add github:lzdyes/tauri-plugin-sqlite#v0.1.0 ``` -`package.json` - -```json - "dependencies": { - "tauri-plugin-sqlite": "lzdyes/tauri-plugin-sqlite#v0.1.0", -``` - ## Usage ### Rust @@ -52,43 +43,35 @@ fn main() { ### JavaScript/TypeScript ```ts -import SQLite from "tauri-plugin-sqlite-api"; +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"); +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]); +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], -]); +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" -); +const rows = await db.select>('SELECT COUNT(*) as count FROM users') /** select with params */ -const rows = await db.select>( - "SELECT name FROM users WHERE age > ?", - [20] -); - -const rows = await db.select>( - "SELECT * FROM users LIMIT ?1 OFFSET ?2", - [10, 0] -); +const rows = await db.select>('SELECT name FROM users WHERE age > ?', [20]) + +const rows = await db.select>('SELECT * FROM users LIMIT ?1 OFFSET ?2', [10, 0]) ``` ## License