Skip to main content

D1

D1 services support.

Capabilities

This service can be used to:

  • stat
  • read
  • write
  • create_dir
  • delete
  • copy
  • rename
  • list
  • scan
  • presign
  • blocking

Configuration

  • root: Set the working directory of OpenDAL
  • token: Set the token of cloudflare api
  • 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

Via Builder

use anyhow::Result;
use opendal::services::D1;
use opendal::Operator;

#[tokio::main]
async fn main() -> Result<()> {
let mut builder = D1::default();
builder
.token("token")
.account_id("account_id")
.database_id("database_id")
.table("table")
.key_field("key_field")
.value_field("value_field");

let op = Operator::new(builder)?.finish();
Ok(())
}

Via Config

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(())
}