Skip to content

Commit

Permalink
docs: update README
Browse files Browse the repository at this point in the history
  • Loading branch information
lzdyes committed May 8, 2022
1 parent 08500aa commit 56f4f8a
Showing 1 changed file with 13 additions and 30 deletions.
43 changes: 13 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Array<{ count: number }>>(
"SELECT COUNT(*) as count FROM users"
);
const rows = await db.select<Array<{ count: number }>>('SELECT COUNT(*) as count FROM users')

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

const rows = await db.select<Array<any>>(
"SELECT * FROM users LIMIT ?1 OFFSET ?2",
[10, 0]
);
const rows = await db.select<Array<{ name: string }>>('SELECT name FROM users WHERE age > ?', [20])

const rows = await db.select<Array<any>>('SELECT * FROM users LIMIT ?1 OFFSET ?2', [10, 0])
```

## License
Expand Down

0 comments on commit 56f4f8a

Please sign in to comment.