Skip to content

Commit

Permalink
docs:
Browse files Browse the repository at this point in the history
  • Loading branch information
taisan11 committed Oct 22, 2024
1 parent be626f7 commit 3c034e9
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 3 deletions.
13 changes: 10 additions & 3 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,23 @@ export default defineConfig({
],

sidebar: [
{ text: 'メインページ', link: '/docs/' },
{
text: 'concepts',
text: 'コンセプト',
items: [
{ text: 'Main Concepts', link: '/docs/' },
{ text: 'Driverについて', link: '/docs/concepts/Driver' }
]
},
{
text:"Deploy",
items:[
{text:"Deno",link:"/docs/deploy/deno"}
{text:"Deno",link:"/docs/deploy/deno"},
{text:"Driver",
items:[
// {text:"Deno KV",link:"/docs/deploy/driver/deno_kv"}
{text:"drizzle_driver",link:"/docs/deploy/drizzle_driver"}
]
}
]
}
],
Expand Down
37 changes: 37 additions & 0 deletions docs/docs/concepts/Driver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Driver
Driverとは複数の保存方法を提供するための物です。Driverはランタイム間との差異をなくすための目的で作られました。
Driverはconfigファイルに入れてください。
公式のDriverは以下の通りです。
::: info
公式Driverは/src/module/storageの下にあります。
:::
## unstorage_driver
unstorage_driverはunstorageを使用して、データを保存するためのDriverです。
unstorageはランタイムに依存しない複数のunstorage_driverを利用して様々なところで動かせるKey - Valueストレージです。
下記のように設定します。
```ts system.config.ts
import { unstorage_driver } from "../src/module/storage/unstrage-base";
import fs from "unstorage/drivers/fs"

const config:Config = {
preference:{
site:{
name:'Och',
use:'bun',
websocket:true,
API:true,
driver:unstorage_driver(fs({base:"./data"})),
},
}
}

export default config
```
### UnStorage DenoKV driver
Ochが提供しているDenoKVでunstorageを利用するためのdriverです。
Ochのdriverと区別するためunstorageがついています。
設定方法は[こちら](/docs/deploy/deno.md)を参照してください。
## Drizzle Driver(SQlite)
Drizzle DriverはDrizzle ORMを利用してデータを保存するためのDriverです。
SQliteでの使用に対応しています。
設定方法、使い方は[こちら](/docs/deploy/drizzle_driver.md)を参照してください。
54 changes: 54 additions & 0 deletions docs/docs/deploy/drizzle_driver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Drizzle Driverを利用する。
## Drizzle Driverとは
Drizzle Driverを使用するとDBを利用して保存したりできます。
## Step①.drizzle.config.tsの編集。
初期状態だとsqlite.dbファイルが作成されます。
D1で使用したり、Trusoで使用する場合は頑張って編集してください。
## Step②.DBを生成。
```bash
bun run ./script/dbgen.ts
```
を実行すると
```bash
bun x drizzle-kit generate
```
されて、初期データが生成されます。
初期データがいらない場合は`./script/dbgen.ts`を見ながら頑張ってください。
## Step③.configをいじる。
`data/system.config.ts`をいじります。ない場合は作ってください。
では中身です。
```ts system.config.ts
import { Config } from "../src/module/config";
import {drizzle} from "drizzle-orm/bun-sqlite"
import { Database } from "bun:sqlite";
import { drizzle_db_driver } from "../src/module/storage/drizzle";

const sqlite = new Database("sqlite.db");

const config:Config = {
caps:{
admin:{
name:'Admin',
pw:'Admin',
fullname:'Administrator',
description:'Administrator',
}
},
preference:{
site:{
name:'Och',
use:'bun',
websocket:true,
API:true,
// これが重要。
driver:drizzle_db_driver(drizzle(new Database("sqlite.db"))),
plugins:[]
},
}
}

export default config
```
詳しく解説すると`drizzle_db_driver()`という関数の中にdrizzle ormから`drizzle()`を渡してあげます。
`drizzle()`によって、BunやD1で使えます。例ではBunを使ってます。
詳しくは[公式ドキュメント](https://orm.drizzle.team/docs/connect-overview)を見てください。
File renamed without changes.

0 comments on commit 3c034e9

Please sign in to comment.