Skip to content

Commit

Permalink
feat: add experimental db0 driver (#476)
Browse files Browse the repository at this point in the history
Co-authored-by: Pooya Parsa <[email protected]>
  • Loading branch information
zsilbi and pi0 authored Dec 10, 2024
1 parent 08c833f commit 836f0f9
Show file tree
Hide file tree
Showing 7 changed files with 757 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/2.drivers/0.index.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ icon: icon-park-outline:hard-disk
::
::card
---
icon: ph:database
to: /drivers/database
title: SQL Database
color: gray
---
Store data in SQL database.
::
::card
---
icon: gg:vercel
to: /drivers/vercel
title: Vercel KV
Expand Down
58 changes: 58 additions & 0 deletions docs/2.drivers/database.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
icon: ph:database
---

# SQL Database

> Store data in any SQL database.
## Usage

This driver stores KV data in any SQL database using [db0](https://db0.unjs.io).

::warning
Database driver is experimental, please report any issues [here](https://github.com/unjs/unstorage/issues/400).
::

To use, you will need to install `db0` in your project:

:pm-install{name="db0"}

Select and configure the appropriate connector for your database.

::important{to="https://db0.unjs.io/connectors"}
Learn more about configuring connectors in the `db0` documentation.
::

You can then configure the driver like this:

```js
import { createDatabase } from "db0";
import { createStorage } from "unstorage";
import dbDriver from "unstorage/drivers/db0";
import sqlite from "db0/connectors/better-sqlite3";

// Learn more: https://db0.unjs.io
const database = createDatabase(
sqlite({
/* db0 connector options */
})
);

const storage = createStorage({
driver: dbDriver({
database,
table: "custom_table_name", // Default is "unstorage"
}),
});
```

::tip
The database table is automatically created, no additional setup is required! <br>
Before first operation, driver ensures a table with columns of `id`, `value`, `blob`, `created_at` and `updated_at` exist.
::

**Options:**

- **`database`** (required): A `db0` database instance.
- `table`: The name of the table to use. It defaults to `unstorage`.
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
"@azure/storage-blob": "^12.26.0",
"@capacitor/preferences": "^6.0.3",
"@cloudflare/workers-types": "^4.20241205.0",
"@electric-sql/pglite": "^0.2.15",
"@libsql/client": "^0.14.0",
"@netlify/blobs": "^8.1.0",
"@planetscale/database": "^1.19.0",
"@types/ioredis-mock": "^8.2.5",
Expand All @@ -72,7 +74,9 @@
"@vercel/kv": "^3.0.0",
"@vitest/coverage-v8": "^2.1.8",
"azurite": "^3.33.0",
"better-sqlite3": "^11.7.0",
"changelogen": "^0.5.7",
"db0": "^0.2.1",
"eslint": "^9.16.0",
"eslint-config-unjs": "^0.4.2",
"fake-indexeddb": "^6.0.0",
Expand Down Expand Up @@ -105,6 +109,7 @@
"@planetscale/database": "^1.19.0",
"@upstash/redis": "^1.34.3",
"@vercel/kv": "^1.0.1",
"db0": ">=0.1",
"idb-keyval": "^6.2.1",
"ioredis": "^5.4.1"
},
Expand Down Expand Up @@ -142,6 +147,9 @@
"@vercel/kv": {
"optional": true
},
"db0": {
"optional": true
},
"idb-keyval": {
"optional": true
},
Expand Down
Loading

0 comments on commit 836f0f9

Please sign in to comment.