Skip to content

Commit

Permalink
feat: add libsql support (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hebilicious authored Jul 21, 2023
1 parent 24d4365 commit 77b6093
Show file tree
Hide file tree
Showing 6 changed files with 282 additions and 12 deletions.
55 changes: 47 additions & 8 deletions docs/content/100.connectors/libsql.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,58 @@ navigation.title: LibSQL

# LibSQL Connector

Connect to [LibSQL](https://libsql.org/) database.

::alert{type="primary"}
🚀 This connector will be comming soon! Follow up via [unjs/db0#14](https://github.com/unjs/db0/issues/14).
::
Connect to a [LibSQL](https://libsql.org/) database.

```js
import { createDB, sql } from "db0";
import vercelPostgres from "db0/connectors/libsql";
import libSql from "db0/connectors/libsql";

const db = createDB(
libsql({
/* options */
libSql({
url: `file:local.db`,
})
);
```

## Options

### `url`

Type: `string`

The database URL. The client supports `libsql:`, `http:`/`https:`, `ws:`/`wss:` and `file:` URL. For more information, please refer to the project README: [link](https://github.com/libsql/libsql-client-ts#supported-urls)

---

### `authToken`

Type: `string` (optional)

Authentication token for the database.

---

### `tls`

Type: `boolean` (optional)

Enables or disables TLS for `libsql:` URLs. By default, `libsql:` URLs use TLS. You can set this option to `false` to disable TLS.

---

### `intMode`

Type: `IntMode` (optional)

How to convert SQLite integers to JavaScript values:

- `"number"` (default): returns SQLite integers as JavaScript `number`-s (double precision floats). `number` cannot precisely represent integers larger than 2^53-1 in absolute value, so attempting to read larger integers will throw a `RangeError`.
- `"bigint"`: returns SQLite integers as JavaScript `bigint`-s (arbitrary precision integers). Bigints can precisely represent all SQLite integers.
- `"string"`: returns SQLite integers as strings.

## References

- [LibSQL Website](https://libsql.org/)
- [LibSQL GitHub Repository](https://github.com/libsql/libsql)
- [LibSQL Client API Reference](https://libsql.org/libsql-client-ts/index.html)
- [LibSQL Client GitHub Repository](https://github.com/libsql/libsql-client-ts)
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"db0": "pnpm jiti src/cli"
},
"devDependencies": {
"@libsql/client": "^0.2.2",
"@types/better-sqlite3": "^7.6.4",
"@types/pg": "^8.10.2",
"@vitest/coverage-v8": "^0.33.0",
Expand All @@ -57,10 +58,14 @@
"vitest": "^0.33.0"
},
"peerDependencies": {
"@libsql/client": "^0.2.2",
"better-sqlite3": "^8.4.0",
"drizzle-orm": "^0.27.2"
},
"peerDependenciesMeta": {
"@libsql/client": {
"optional": true
},
"better-sqlite3": {
"optional": true
},
Expand Down
150 changes: 146 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 77b6093

Please sign in to comment.