This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new db16bfe96 refactor(services/sqlite): split sqlite service into 
separate crate (#7014)
db16bfe96 is described below

commit db16bfe96aa463a9a6ebfdaec66daaad1185c51d
Author: bear&cat <[email protected]>
AuthorDate: Mon Dec 15 20:29:55 2025 +0800

    refactor(services/sqlite): split sqlite service into separate crate (#7014)
---
 core/Cargo.lock                                    | 76 ++++++----------------
 core/Cargo.toml                                    |  3 +-
 core/core/Cargo.toml                               |  6 --
 core/core/src/services/mod.rs                      |  5 --
 core/services/sqlite/Cargo.toml                    | 43 ++++++++++++
 .../sqlite => services/sqlite/src}/backend.rs      |  8 +--
 .../sqlite => services/sqlite/src}/config.rs       |  8 +--
 .../sqlite => services/sqlite/src}/core.rs         |  7 +-
 .../sqlite => services/sqlite/src}/deleter.rs      |  7 +-
 .../sqlite => services/sqlite/src}/docs.md         |  3 +-
 .../sqlite/mod.rs => services/sqlite/src/lib.rs}   |  2 +-
 .../sqlite => services/sqlite/src}/writer.rs       | 13 ++--
 core/src/lib.rs                                    |  2 +
 13 files changed, 92 insertions(+), 91 deletions(-)

diff --git a/core/Cargo.lock b/core/Cargo.lock
index c12b2ede2..fcc412432 100644
--- a/core/Cargo.lock
+++ b/core/Cargo.lock
@@ -65,12 +65,6 @@ dependencies = [
  "memchr",
 ]
 
-[[package]]
-name = "aliasable"
-version = "0.1.3"
-source = "registry+https://github.com/rust-lang/crates.io-index";
-checksum = "250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fd"
-
 [[package]]
 name = "allocator-api2"
 version = "0.2.21"
@@ -1728,7 +1722,7 @@ version = "4.5.49"
 source = "registry+https://github.com/rust-lang/crates.io-index";
 checksum = "2a0b5487afeab2deb2ff4e03a807ad1a03ac532ff5a2cee5d86884440c7f7671"
 dependencies = [
- "heck 0.5.0",
+ "heck",
  "proc-macro2",
  "quote",
  "syn 2.0.111",
@@ -2794,7 +2788,7 @@ version = "0.6.1"
 source = "registry+https://github.com/rust-lang/crates.io-index";
 checksum = "a1e6a265c649f3f5979b601d26f1d05ada116434c87741c9493cb56218f76cbc"
 dependencies = [
- "heck 0.5.0",
+ "heck",
  "proc-macro2",
  "quote",
  "syn 2.0.111",
@@ -3766,12 +3760,6 @@ dependencies = [
  "stable_deref_trait",
 ]
 
-[[package]]
-name = "heck"
-version = "0.4.1"
-source = "registry+https://github.com/rust-lang/crates.io-index";
-checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
-
 [[package]]
 name = "heck"
 version = "0.5.0"
@@ -5582,6 +5570,7 @@ dependencies = [
  "opendal-service-postgresql",
  "opendal-service-s3",
  "opendal-service-sled",
+ "opendal-service-sqlite",
  "opendal-service-tikv",
  "opendal-service-vercel-blob",
  "opentelemetry",
@@ -5663,7 +5652,6 @@ dependencies = [
  "monoio",
  "openssh",
  "openssh-sftp-client",
- "ouroboros",
  "percent-encoding",
  "persy",
  "pretty_assertions",
@@ -5681,7 +5669,6 @@ dependencies = [
  "sha1",
  "sha2",
  "size",
- "sqlx",
  "surrealdb",
  "tokio",
  "tracing-opentelemetry",
@@ -6179,6 +6166,18 @@ dependencies = [
  "sled",
 ]
 
+[[package]]
+name = "opendal-service-sqlite"
+version = "0.55.0"
+dependencies = [
+ "ctor",
+ "mea",
+ "opendal-core",
+ "serde",
+ "sqlx",
+ "tokio",
+]
+
 [[package]]
 name = "opendal-service-tikv"
 version = "0.55.0"
@@ -6437,30 +6436,6 @@ dependencies = [
  "windows-sys 0.61.2",
 ]
 
-[[package]]
-name = "ouroboros"
-version = "0.18.5"
-source = "registry+https://github.com/rust-lang/crates.io-index";
-checksum = "1e0f050db9c44b97a94723127e6be766ac5c340c48f2c4bb3ffa11713744be59"
-dependencies = [
- "aliasable",
- "ouroboros_macro",
- "static_assertions",
-]
-
-[[package]]
-name = "ouroboros_macro"
-version = "0.18.5"
-source = "registry+https://github.com/rust-lang/crates.io-index";
-checksum = "3c7028bdd3d43083f6d8d4d5187680d0d3560d54df4cc9d752005268b41e64d0"
-dependencies = [
- "heck 0.4.1",
- "proc-macro2",
- "proc-macro2-diagnostics",
- "quote",
- "syn 2.0.111",
-]
-
 [[package]]
 name = "outref"
 version = "0.5.2"
@@ -6970,19 +6945,6 @@ dependencies = [
  "unicode-ident",
 ]
 
-[[package]]
-name = "proc-macro2-diagnostics"
-version = "0.10.1"
-source = "registry+https://github.com/rust-lang/crates.io-index";
-checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn 2.0.111",
- "version_check",
- "yansi",
-]
-
 [[package]]
 name = "procfs"
 version = "0.17.0"
@@ -7095,7 +7057,7 @@ version = "0.14.1"
 source = "registry+https://github.com/rust-lang/crates.io-index";
 checksum = "ac6c3320f9abac597dcbc668774ef006702672474aad53c6d596b62e487b40b1"
 dependencies = [
- "heck 0.5.0",
+ "heck",
  "itertools 0.14.0",
  "log",
  "multimap",
@@ -8856,7 +8818,7 @@ checksum = 
"19a9c1841124ac5a61741f96e1d9e2ec77424bf323962dd894bdb93f37d5219b"
 dependencies = [
  "dotenvy",
  "either",
- "heck 0.5.0",
+ "heck",
  "hex",
  "once_cell",
  "proc-macro2",
@@ -9122,7 +9084,7 @@ version = "0.26.4"
 source = "registry+https://github.com/rust-lang/crates.io-index";
 checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be"
 dependencies = [
- "heck 0.5.0",
+ "heck",
  "proc-macro2",
  "quote",
  "rustversion",
@@ -9135,7 +9097,7 @@ version = "0.27.2"
 source = "registry+https://github.com/rust-lang/crates.io-index";
 checksum = "7695ce3845ea4b33927c055a39dc438a45b059f7c1b3d91d38d10355fb8cbca7"
 dependencies = [
- "heck 0.5.0",
+ "heck",
  "proc-macro2",
  "quote",
  "syn 2.0.111",
diff --git a/core/Cargo.toml b/core/Cargo.toml
index e8ec7fdb3..e28afa65c 100644
--- a/core/Cargo.toml
+++ b/core/Cargo.toml
@@ -153,7 +153,7 @@ services-s3 = ["dep:opendal-service-s3"]
 services-seafile = ["opendal-core/services-seafile"]
 services-sftp = ["opendal-core/services-sftp"]
 services-sled = ["dep:opendal-service-sled"]
-services-sqlite = ["opendal-core/services-sqlite"]
+services-sqlite = ["dep:opendal-service-sqlite"]
 services-surrealdb = ["opendal-core/services-surrealdb"]
 services-swift = ["opendal-core/services-swift"]
 services-tikv = ["dep:opendal-service-tikv"]
@@ -220,6 +220,7 @@ opendal-service-obs = { path = "services/obs", version = 
"0.55.0", optional = tr
 opendal-service-oss = { path = "services/oss", version = "0.55.0", optional = 
true, default-features = false }
 opendal-service-postgresql = { path = "services/postgresql", version = 
"0.55.0", optional = true, default-features = false }
 opendal-service-s3 = { path = "services/s3", version = "0.55.0", optional = 
true, default-features = false }
+opendal-service-sqlite = { path = "services/sqlite", version = "0.55.0", 
optional = true, default-features = false }
 opendal-service-sled = { path = "services/sled", version = "0.55.0", optional 
= true, default-features = false }
 opendal-service-tikv = { path = "services/tikv", version = "0.55.0", optional 
= true, default-features = false }
 opendal-service-vercel-blob = { path = "services/vercel-blob", version = 
"0.55.0", optional = true, default-features = false }
diff --git a/core/core/Cargo.toml b/core/core/Cargo.toml
index cc9a92df5..855ed1a41 100644
--- a/core/core/Cargo.toml
+++ b/core/core/Cargo.toml
@@ -116,7 +116,6 @@ services-redis-native-tls = ["services-redis", 
"redis?/tokio-native-tls-comp"]
 services-rocksdb = ["dep:rocksdb", "internal-tokio-rt"]
 services-seafile = []
 services-sftp = ["dep:openssh", "dep:openssh-sftp-client", "dep:fastpool"]
-services-sqlite = ["dep:sqlx", "sqlx?/sqlite", "dep:ouroboros"]
 services-surrealdb = ["dep:surrealdb"]
 services-swift = []
 services-upyun = ["dep:hmac", "dep:sha1"]
@@ -169,16 +168,11 @@ fastpool = { version = "1.0.2", optional = true }
 prost = { version = "0.13", optional = true }
 sha1 = { version = "0.10.6", optional = true }
 sha2 = { workspace = true, optional = true }
-sqlx = { version = "0.8.0", features = [
-  "runtime-tokio-rustls",
-], optional = true }
 
 # For http based services.
 reqsign = { workspace = true, default-features = false, optional = true }
 
 # for self-referencing structs
-ouroboros = { version = "0.18.4", optional = true }
-
 # for services-cacache
 cacache = { version = "13.0", default-features = false, features = [
   "tokio-runtime",
diff --git a/core/core/src/services/mod.rs b/core/core/src/services/mod.rs
index 68e2a7b86..2f211a4f5 100644
--- a/core/core/src/services/mod.rs
+++ b/core/core/src/services/mod.rs
@@ -179,11 +179,6 @@ mod sftp;
 #[cfg(feature = "services-sftp")]
 pub use sftp::*;
 
-#[cfg(feature = "services-sqlite")]
-mod sqlite;
-#[cfg(feature = "services-sqlite")]
-pub use self::sqlite::*;
-
 #[cfg(feature = "services-surrealdb")]
 mod surrealdb;
 #[cfg(feature = "services-surrealdb")]
diff --git a/core/services/sqlite/Cargo.toml b/core/services/sqlite/Cargo.toml
new file mode 100644
index 000000000..5afc1e0a1
--- /dev/null
+++ b/core/services/sqlite/Cargo.toml
@@ -0,0 +1,43 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+[package]
+description = "Apache OpenDAL SQLite service implementation"
+name = "opendal-service-sqlite"
+
+authors = { workspace = true }
+edition = { workspace = true }
+homepage = { workspace = true }
+license = { workspace = true }
+repository = { workspace = true }
+rust-version = { workspace = true }
+version = { workspace = true }
+
+[package.metadata.docs.rs]
+all-features = true
+
+[dependencies]
+opendal-core = { path = "../../core", version = "0.55.0", default-features = 
false }
+
+ctor = { workspace = true }
+mea = { version = "0.5.1" }
+serde = { workspace = true, features = ["derive"] }
+sqlx = { version = "0.8.0", features = ["runtime-tokio-rustls", "sqlite"] }
+
+[dev-dependencies]
+tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
+
diff --git a/core/core/src/services/sqlite/backend.rs 
b/core/services/sqlite/src/backend.rs
similarity index 98%
rename from core/core/src/services/sqlite/backend.rs
rename to core/services/sqlite/src/backend.rs
index 79d8ce923..5e1113596 100644
--- a/core/core/src/services/sqlite/backend.rs
+++ b/core/services/sqlite/src/backend.rs
@@ -26,9 +26,9 @@ use super::config::SqliteConfig;
 use super::core::SqliteCore;
 use super::deleter::SqliteDeleter;
 use super::writer::SqliteWriter;
-use crate::raw::oio;
-use crate::raw::*;
-use crate::*;
+use opendal_core::raw::oio;
+use opendal_core::raw::*;
+use opendal_core::*;
 
 #[doc = include_str!("docs.md")]
 #[derive(Debug, Default)]
@@ -242,7 +242,7 @@ impl Access for SqliteBackend {
                     .bind(format!("{}%", dir_path))
                     .fetch_one(self.core.get_client().await?)
                     .await
-                    
.map_err(crate::services::sqlite::backend::parse_sqlite_error)?;
+                    .map_err(parse_sqlite_error)?;
 
                     if count > 0 {
                         // Directory exists (has children)
diff --git a/core/core/src/services/sqlite/config.rs 
b/core/services/sqlite/src/config.rs
similarity index 95%
rename from core/core/src/services/sqlite/config.rs
rename to core/services/sqlite/src/config.rs
index 0bca09263..ffafb1837 100644
--- a/core/core/src/services/sqlite/config.rs
+++ b/core/services/sqlite/src/config.rs
@@ -67,10 +67,10 @@ impl Debug for SqliteConfig {
     }
 }
 
-impl crate::Configurator for SqliteConfig {
+impl opendal_core::Configurator for SqliteConfig {
     type Builder = SqliteBuilder;
 
-    fn from_uri(uri: &crate::types::OperatorUri) -> crate::Result<Self> {
+    fn from_uri(uri: &opendal_core::OperatorUri) -> opendal_core::Result<Self> 
{
         let mut map = uri.options().clone();
 
         if let Some(authority) = uri.authority() {
@@ -109,8 +109,8 @@ impl crate::Configurator for SqliteConfig {
 #[cfg(test)]
 mod tests {
     use super::*;
-    use crate::Configurator;
-    use crate::types::OperatorUri;
+    use opendal_core::Configurator;
+    use opendal_core::OperatorUri;
 
     #[test]
     fn from_uri_sets_connection_string_table_and_root() {
diff --git a/core/core/src/services/sqlite/core.rs 
b/core/services/sqlite/src/core.rs
similarity index 97%
rename from core/core/src/services/sqlite/core.rs
rename to core/services/sqlite/src/core.rs
index fa55643e9..56499db6c 100644
--- a/core/core/src/services/sqlite/core.rs
+++ b/core/services/sqlite/src/core.rs
@@ -15,13 +15,14 @@
 // specific language governing permissions and limitations
 // under the License.
 
+use std::fmt::Debug;
+
 use mea::once::OnceCell;
 use sqlx::SqlitePool;
 use sqlx::sqlite::SqliteConnectOptions;
-use std::fmt::Debug;
 
-use crate::services::sqlite::backend::parse_sqlite_error;
-use crate::*;
+use super::backend::parse_sqlite_error;
+use opendal_core::*;
 
 #[derive(Debug, Clone)]
 pub struct SqliteCore {
diff --git a/core/core/src/services/sqlite/deleter.rs 
b/core/services/sqlite/src/deleter.rs
similarity index 86%
rename from core/core/src/services/sqlite/deleter.rs
rename to core/services/sqlite/src/deleter.rs
index 7b3ee442c..018d7296c 100644
--- a/core/core/src/services/sqlite/deleter.rs
+++ b/core/services/sqlite/src/deleter.rs
@@ -15,8 +15,9 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use crate::raw::{OpDelete, build_abs_path, oio};
-use crate::services::sqlite::core::SqliteCore;
+use opendal_core::raw::{OpDelete, build_abs_path, oio};
+
+use super::core::SqliteCore;
 
 pub struct SqliteDeleter {
     pub core: std::sync::Arc<SqliteCore>,
@@ -30,7 +31,7 @@ impl SqliteDeleter {
 }
 
 impl oio::OneShotDelete for SqliteDeleter {
-    async fn delete_once(&self, path: String, _: OpDelete) -> 
crate::Result<()> {
+    async fn delete_once(&self, path: String, _: OpDelete) -> 
opendal_core::Result<()> {
         let p = build_abs_path(&self.root, &path);
         self.core.delete(&p).await?;
         Ok(())
diff --git a/core/core/src/services/sqlite/docs.md 
b/core/services/sqlite/src/docs.md
similarity index 96%
rename from core/core/src/services/sqlite/docs.md
rename to core/services/sqlite/src/docs.md
index 77d78b6fd..7848a2941 100644
--- a/core/core/src/services/sqlite/docs.md
+++ b/core/services/sqlite/src/docs.md
@@ -26,8 +26,8 @@ This service can be used to:
 
 ```rust,no_run
 use anyhow::Result;
-use opendal_core::services::Sqlite;
 use opendal_core::Operator;
+use opendal_service_sqlite::Sqlite;
 
 #[tokio::main]
 async fn main() -> Result<()> {
@@ -44,3 +44,4 @@ async fn main() -> Result<()> {
     Ok(())
 }
 ```
+
diff --git a/core/core/src/services/sqlite/mod.rs 
b/core/services/sqlite/src/lib.rs
similarity index 96%
rename from core/core/src/services/sqlite/mod.rs
rename to core/services/sqlite/src/lib.rs
index c6783d57f..4178520d3 100644
--- a/core/core/src/services/sqlite/mod.rs
+++ b/core/services/sqlite/src/lib.rs
@@ -18,7 +18,7 @@
 /// Default scheme for sqlite service.
 pub const SQLITE_SCHEME: &str = "sqlite";
 
-use crate::types::DEFAULT_OPERATOR_REGISTRY;
+use opendal_core::DEFAULT_OPERATOR_REGISTRY;
 
 mod backend;
 mod config;
diff --git a/core/core/src/services/sqlite/writer.rs 
b/core/services/sqlite/src/writer.rs
similarity index 83%
rename from core/core/src/services/sqlite/writer.rs
rename to core/services/sqlite/src/writer.rs
index bda34b255..1154e642f 100644
--- a/core/core/src/services/sqlite/writer.rs
+++ b/core/services/sqlite/src/writer.rs
@@ -15,9 +15,10 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use crate::raw::oio;
-use crate::services::sqlite::core::SqliteCore;
-use crate::{Buffer, EntryMode, Metadata};
+use opendal_core::raw::oio;
+use opendal_core::{Buffer, EntryMode, Metadata};
+
+use super::core::SqliteCore;
 
 pub struct SqliteWriter {
     core: std::sync::Arc<SqliteCore>,
@@ -36,12 +37,12 @@ impl SqliteWriter {
 }
 
 impl oio::Write for SqliteWriter {
-    async fn write(&mut self, bs: Buffer) -> crate::Result<()> {
+    async fn write(&mut self, bs: Buffer) -> opendal_core::Result<()> {
         self.buffer.push(bs);
         Ok(())
     }
 
-    async fn close(&mut self) -> crate::Result<Metadata> {
+    async fn close(&mut self) -> opendal_core::Result<Metadata> {
         let buf = self.buffer.clone().collect();
         let length = buf.len() as u64;
         self.core.set(&self.path, buf).await?;
@@ -50,7 +51,7 @@ impl oio::Write for SqliteWriter {
         Ok(meta)
     }
 
-    async fn abort(&mut self) -> crate::Result<()> {
+    async fn abort(&mut self) -> opendal_core::Result<()> {
         self.buffer.clear();
         Ok(())
     }
diff --git a/core/src/lib.rs b/core/src/lib.rs
index 1ab172741..100f746b1 100644
--- a/core/src/lib.rs
+++ b/core/src/lib.rs
@@ -65,6 +65,8 @@ pub mod services {
     pub use opendal_service_s3::*;
     #[cfg(feature = "services-sled")]
     pub use opendal_service_sled::*;
+    #[cfg(feature = "services-sqlite")]
+    pub use opendal_service_sqlite::*;
     #[cfg(feature = "services-tikv")]
     pub use opendal_service_tikv::*;
     #[cfg(feature = "services-vercel-blob")]

Reply via email to