-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add experimental
db0
driver (#476)
Co-authored-by: Pooya Parsa <[email protected]>
- Loading branch information
Showing
7 changed files
with
757 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.