-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
101 additions
and
3 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,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)を参照してください。 |
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,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.