Skip to content

Commit 1ba746d

Browse files
refactor: Split service d1 out of core (#7027)
* refactor: Split service d1 out of core Signed-off-by: Jintao Zhang <zhangjintao9020@gmail.com> * chore: format d1 service Cargo.toml with taplo --------- Signed-off-by: Jintao Zhang <zhangjintao9020@gmail.com>
1 parent 731ada8 commit 1ba746d

File tree

15 files changed

+98
-39
lines changed

15 files changed

+98
-39
lines changed

core/Cargo.lock

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ services-cacache = ["opendal-core/services-cacache"]
111111
services-cloudflare-kv = ["dep:opendal-service-cloudflare-kv"]
112112
services-compfs = ["opendal-core/services-compfs"]
113113
services-cos = ["dep:opendal-service-cos"]
114-
services-d1 = ["opendal-core/services-d1"]
114+
services-d1 = ["dep:opendal-service-d1"]
115115
services-dashmap = ["dep:opendal-service-dashmap"]
116116
services-dbfs = ["opendal-core/services-dbfs"]
117117
services-dropbox = ["opendal-core/services-dropbox"]
@@ -211,6 +211,7 @@ opendal-service-azfile = { path = "services/azfile", version = "0.55.0", optiona
211211
opendal-service-b2 = { path = "services/b2", version = "0.55.0", optional = true, default-features = false }
212212
opendal-service-cloudflare-kv = { path = "services/cloudflare-kv", version = "0.55.0", optional = true, default-features = false }
213213
opendal-service-cos = { path = "services/cos", version = "0.55.0", optional = true, default-features = false }
214+
opendal-service-d1 = { path = "services/d1", version = "0.55.0", optional = true, default-features = false }
214215
opendal-service-dashmap = { path = "services/dashmap", version = "0.55.0", optional = true, default-features = false }
215216
opendal-service-fs = { path = "services/fs", version = "0.55.0", optional = true, default-features = false }
216217
opendal-service-ftp = { path = "services/ftp", version = "0.55.0", optional = true, default-features = false }

core/core/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ layers-dtrace = ["dep:probe"]
5959

6060
services-cacache = ["dep:cacache"]
6161
services-compfs = ["dep:compio"]
62-
services-d1 = []
6362
services-dbfs = []
6463
services-dropbox = []
6564
services-etcd = ["dep:etcd-client", "dep:fastpool"]

core/core/src/services/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ mod compfs;
2929
#[cfg(feature = "services-compfs")]
3030
pub use compfs::*;
3131

32-
#[cfg(feature = "services-d1")]
33-
mod d1;
34-
#[cfg(feature = "services-d1")]
35-
pub use self::d1::*;
36-
3732
#[cfg(feature = "services-dbfs")]
3833
mod dbfs;
3934
#[cfg(feature = "services-dbfs")]

core/services/d1/Cargo.toml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
[package]
19+
description = "Apache OpenDAL D1 service implementation"
20+
name = "opendal-service-d1"
21+
22+
authors = { workspace = true }
23+
edition = { workspace = true }
24+
homepage = { workspace = true }
25+
license = { workspace = true }
26+
repository = { workspace = true }
27+
rust-version = { workspace = true }
28+
version = { workspace = true }
29+
30+
[package.metadata.docs.rs]
31+
all-features = true
32+
33+
[dependencies]
34+
opendal-core = { path = "../../core", version = "0.55.0", default-features = false }
35+
36+
bytes = { workspace = true }
37+
ctor = { workspace = true }
38+
http = { workspace = true }
39+
log = { workspace = true }
40+
serde = { workspace = true, features = ["derive"] }
41+
serde_json = { workspace = true }
42+
43+
[dev-dependencies]
44+
pretty_assertions = "1"
45+
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ use super::config::D1Config;
2323
use super::core::*;
2424
use super::deleter::D1Deleter;
2525
use super::writer::D1Writer;
26-
use crate::raw::*;
27-
use crate::*;
26+
use opendal_core::raw::*;
27+
use opendal_core::*;
2828

2929
#[doc = include_str!("docs.md")]
3030
#[derive(Default)]
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,30 @@ impl Debug for D1Config {
5656
}
5757
}
5858

59-
impl crate::Configurator for D1Config {
59+
impl opendal_core::Configurator for D1Config {
6060
type Builder = D1Builder;
6161

62-
fn from_uri(uri: &crate::types::OperatorUri) -> crate::Result<Self> {
62+
fn from_uri(uri: &opendal_core::OperatorUri) -> opendal_core::Result<Self> {
6363
let account_id = uri.name().ok_or_else(|| {
64-
crate::Error::new(
65-
crate::ErrorKind::ConfigInvalid,
64+
opendal_core::Error::new(
65+
opendal_core::ErrorKind::ConfigInvalid,
6666
"uri host must contain account id",
6767
)
6868
.with_context("service", D1_SCHEME)
6969
})?;
7070

7171
let database_and_root = uri.root().ok_or_else(|| {
72-
crate::Error::new(
73-
crate::ErrorKind::ConfigInvalid,
72+
opendal_core::Error::new(
73+
opendal_core::ErrorKind::ConfigInvalid,
7474
"uri path must contain database id",
7575
)
7676
.with_context("service", D1_SCHEME)
7777
})?;
7878

7979
let mut segments = database_and_root.splitn(2, '/');
8080
let database_id = segments.next().filter(|s| !s.is_empty()).ok_or_else(|| {
81-
crate::Error::new(
82-
crate::ErrorKind::ConfigInvalid,
81+
opendal_core::Error::new(
82+
opendal_core::ErrorKind::ConfigInvalid,
8383
"database id is required in uri path",
8484
)
8585
.with_context("service", D1_SCHEME)
@@ -106,8 +106,8 @@ impl crate::Configurator for D1Config {
106106
#[cfg(test)]
107107
mod tests {
108108
use super::*;
109-
use crate::Configurator;
110-
use crate::types::OperatorUri;
109+
use opendal_core::Configurator;
110+
use opendal_core::OperatorUri;
111111

112112
#[test]
113113
fn from_uri_sets_account_database_and_root() {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ use serde_json::Value;
2424

2525
use super::error::parse_error;
2626
use super::model::*;
27-
use crate::raw::*;
28-
use crate::*;
27+
use opendal_core::raw::*;
28+
use opendal_core::*;
2929

3030
#[derive(Clone)]
3131
pub struct D1Core {
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
use std::sync::Arc;
1919

2020
use super::core::*;
21-
use crate::raw::oio;
22-
use crate::raw::*;
23-
use crate::*;
21+
use opendal_core::raw::oio;
22+
use opendal_core::raw::*;
23+
use opendal_core::*;
2424

2525
pub struct D1Deleter {
2626
core: Arc<D1Core>,
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@ This service can be used to:
2727
### Via Builder
2828

2929
```rust,no_run
30-
use anyhow::Result;
31-
use opendal_core::services::D1;
30+
use opendal_service_d1::D1;
3231
use opendal_core::Operator;
3332
3433
#[tokio::main]
35-
async fn main() -> Result<()> {
34+
async fn main() -> Result<(), Box<dyn std::error::Error>> {
3635
let mut builder = D1::default()
3736
.token("token")
3837
.account_id("account_id")

0 commit comments

Comments
 (0)