Skip to content

Commit

Permalink
docs: Add docs on website for d1 services (#3295)
Browse files Browse the repository at this point in the history
* docs: Add docs on website for d1 services

Signed-off-by: Manjusaka <[email protected]>

* Update docs

Signed-off-by: Manjusaka <[email protected]>

---------

Signed-off-by: Manjusaka <[email protected]>
  • Loading branch information
Zheaoli authored Oct 16, 2023
1 parent 1bb601b commit e46550b
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 16 deletions.
21 changes: 5 additions & 16 deletions core/src/services/d1/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ This service can be used to:

- `root`: Set the working directory of `OpenDAL`
- `token`: Set the token of cloudflare api
- `account_identifier`: Set the account identifier of d1
- `database_identifier`: Set the database identifier of d1
- `endpoint`: Set the endpoint of d1 service
- `table`: Set the table name of the d1 service to read/write
- `key_field`: Set the key field of d1
- `value_field`: Set the value field of d1
- `account_id`: Set the account id of cloudflare api
- `database_id`: Set the database id of cloudflare api
- `table`: Set the table of D1 Database
- `key_field`: Set the key field of D1 Database
- `value_field`: Set the value field of D1 Database

## Example

Expand All @@ -46,16 +45,6 @@ async fn main() -> Result<()> {
.value_field("value_field");

let op = Operator::new(builder)?.finish();
let source_path = "ALFKI";
// set value to d1 "opendal test value" as Vec<u8>
let value = "opendal test value".as_bytes();
// write value to d1, the key is source_path
op.write(source_path, value).await?;
// read value from d1, the key is source_path
let v = op.read(source_path).await?;
assert_eq!(v, value);
// delete value from d1, the key is source_path
op.delete(source_path).await?;
Ok(())
}
```
78 changes: 78 additions & 0 deletions website/docs/services/d1.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
title: D1
---

[D1](https://developers.cloudflare.com/d1/) services support.

import Docs from '../../../core/src/services/d1/docs.md'

<Docs components={props.components} />

### Via Config

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<Tabs>
<TabItem value="rust" label="Rust" default>

```rust
use anyhow::Result;
use opendal::Operator;
use opendal::Scheme;
use std::collections::HashMap;

#[tokio::main]
async fn main() -> Result<()> {
let mut map = HashMap::new();
map.insert("token".to_string(), "token".to_string());
map.insert("account_id".to_string(), "account_id".to_string());
map.insert("database_id".to_string(), "database_id".to_string());
map.insert("table".to_string(), "table".to_string());
map.insert("key_field".to_string(), "key_field".to_string());
map.insert("value_field".to_string(), "value_field".to_string());

let op: Operator = Operator::via_map(Scheme::D1, map)?;
Ok(())
}
```

</TabItem>
<TabItem value="node.js" label="Node.js">

```javascript
import { Operator } from "opendal";

async function main() {
const config = {
token: "token",
account_id: "account_id",
database_id: "database_id",
table: "table",
key_field: "key_field",
value_field: "value_field"
};
const op = new Operator("d1", config);
}
```

</TabItem>
<TabItem value="python" label="Python">

```python
import opendal

config = {
"token": "token",
"account_id": "account_id",
"database_id": "database_id",
"table": "table",
"key_field": "key_field",
"value_field": "value_field"
}

op = opendal.Operator("d1", **config)
```

</TabItem>
</Tabs>

0 comments on commit e46550b

Please sign in to comment.