-
Notifications
You must be signed in to change notification settings - Fork 513
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: feathercyc <[email protected]>
- Loading branch information
Showing
8 changed files
with
275 additions
and
0 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
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,122 @@ | ||
// 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. | ||
|
||
use std::fmt::Debug; | ||
|
||
use crate::raw::adapters::kv; | ||
use crate::raw::*; | ||
use crate::services::NebulaGraphConfig; | ||
use crate::*; | ||
|
||
impl Configurator for NebulaGraphConfig { | ||
type Builder = NebulaGraphBuilder; | ||
fn into_builder(self) -> Self::Builder { | ||
NebulaGraphBuilder { config: self } | ||
} | ||
} | ||
|
||
#[doc = include_str!("docs.md")] | ||
#[derive(Default)] | ||
pub struct NebulaGraphBuilder { | ||
config: NebulaGraphConfig, | ||
} | ||
|
||
impl Debug for NebulaGraphBuilder { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
let mut d = f.debug_struct("MysqlBuilder"); | ||
|
||
d.field("config", &self.config).finish() | ||
} | ||
} | ||
|
||
impl NebulaGraphBuilder { | ||
/// Set the host addr of nebulagraph's graphd server | ||
pub fn host(&mut self, host: &str) -> &mut Self { | ||
if !host.is_empty() { | ||
self.config.host = Some(host.to_string()); | ||
} | ||
self | ||
} | ||
|
||
/// Set the host port of nebulagraph's graphd server | ||
pub fn port(&mut self, port: u16) -> &mut Self { | ||
self.config.port = Some(port); | ||
self | ||
} | ||
|
||
/// Set the username of nebulagraph's graphd server | ||
pub fn username(&mut self, username: &str) -> &mut Self { | ||
if !username.is_empty() { | ||
self.config.username = Some(username.to_string()); | ||
} | ||
self | ||
} | ||
|
||
/// Set the password of nebulagraph's graphd server | ||
pub fn password(&mut self, password: &str) -> &mut Self { | ||
if !password.is_empty() { | ||
self.config.password = Some(password.to_string()); | ||
} | ||
self | ||
} | ||
|
||
/// Set the space name of nebulagraph's graphd server | ||
pub fn space(&mut self, space: &str) -> &mut Self { | ||
if !space.is_empty() { | ||
self.config.space = Some(space.to_string()); | ||
} | ||
self | ||
} | ||
|
||
/// Set the tag name of nebulagraph's graphd server | ||
pub fn tag(&mut self, tag: &str) -> &mut Self { | ||
if !tag.is_empty() { | ||
self.config.tag = Some(tag.to_string()); | ||
} | ||
self | ||
} | ||
|
||
/// Set the key field name of the NebulaGraph service to read/write. | ||
/// | ||
/// Default to `key` if not specified. | ||
pub fn key_field(&mut self, key_field: &str) -> &mut Self { | ||
if !key_field.is_empty() { | ||
self.config.key_field = Some(key_field.to_string()); | ||
} | ||
self | ||
} | ||
|
||
/// Set the value field name of the NebulaGraph service to read/write. | ||
/// | ||
/// Default to `value` if not specified. | ||
pub fn value_field(&mut self, value_field: &str) -> &mut Self { | ||
if !value_field.is_empty() { | ||
self.config.value_field = Some(value_field.to_string()); | ||
} | ||
self | ||
} | ||
|
||
/// set the working directory, all operations will be performed under it. | ||
/// | ||
/// default: "/" | ||
pub fn root(&mut self, root: &str) -> &mut Self { | ||
if !root.is_empty() { | ||
self.config.root = Some(root.to_string()); | ||
} | ||
self | ||
} | ||
} |
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,64 @@ | ||
// 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. | ||
|
||
use std::fmt::Debug; | ||
|
||
use serde::Deserialize; | ||
use serde::Serialize; | ||
|
||
/// Config for Mysql services support. | ||
#[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)] | ||
#[serde(default)] | ||
#[non_exhaustive] | ||
pub struct NebulaGraphConfig { | ||
/// The host addr of nebulagraph's graphd server | ||
pub host: Option<String>, | ||
/// The host port of nebulagraph's graphd server | ||
pub port: Option<u16>, | ||
/// The username of nebulagraph's graphd server | ||
pub username: Option<String>, | ||
/// The password of nebulagraph's graphd server | ||
pub password: Option<String>, | ||
|
||
/// The space name of nebulagraph's graphd server | ||
pub space: Option<String>, | ||
/// The tag name of nebulagraph's graphd server | ||
pub tag: Option<String>, | ||
/// The key field name of the NebulaGraph service to read/write. | ||
pub key_field: Option<String>, | ||
/// The value field name of the NebulaGraph service to read/write. | ||
pub value_field: Option<String>, | ||
/// The root for NebulaGraph | ||
pub root: Option<String>, | ||
} | ||
|
||
impl Debug for NebulaGraphConfig { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
let mut d = f.debug_struct("NebulaGraphConfig"); | ||
|
||
d.field("host", &self.host) | ||
.field("port", &self.port) | ||
.field("username", &self.username) | ||
.field("password", &self.password) | ||
.field("space", &self.space) | ||
.field("tag", &self.tag) | ||
.field("key_field", &self.key_field) | ||
.field("value_field", &self.value_field) | ||
.field("root", &self.root) | ||
.finish() | ||
} | ||
} |
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,53 @@ | ||
## Capabilities | ||
|
||
This service can be used to: | ||
|
||
- [x] stat | ||
- [x] read | ||
- [x] write | ||
- [x] create_dir | ||
- [x] delete | ||
- [ ] copy | ||
- [ ] rename | ||
- [x] list | ||
- [ ] ~~presign~~ | ||
- [ ] blocking | ||
|
||
## Configuration | ||
|
||
- `root`: Set the working directory of `OpenDAL` | ||
- `host`: Set the host address of NebulaGraph's graphd server | ||
- `port`: Set the port of NebulaGraph's graphd server | ||
- `username`: Set the username of NebulaGraph's graphd server | ||
- `password`: Set the password of NebulaGraph's graphd server | ||
- `space`: Set the passspaceword of NebulaGraph | ||
- `tag`: Set the tag of NebulaGraph | ||
- `key_field`: Set the key_field of NebulaGraph | ||
- `value_field`: Set the value_field of NebulaGraph | ||
|
||
## Example | ||
|
||
### Via Builder | ||
|
||
```rust,no_run | ||
use anyhow::Result; | ||
use opendal::services::NebulaGraph; | ||
use opendal::Operator; | ||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
let mut builder = NebulaGraph::default(); | ||
builder.root("/"); | ||
builder.host("127.0.0.1"); | ||
builder.port(9669); | ||
builder.space("your_space"); | ||
builder.tag("your_tag"); | ||
// key field type in the table should be compatible with Rust's &str like text | ||
builder.key_field("key"); | ||
// value field type in the table should be compatible with Rust's Vec<u8> like bytea | ||
builder.value_field("value"); | ||
let op = Operator::new(builder)?.finish(); | ||
Ok(()) | ||
} | ||
``` |
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,24 @@ | ||
// 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. | ||
|
||
#[cfg(feature = "services-nebula-graph")] | ||
mod backend; | ||
#[cfg(feature = "services-nebula-graph")] | ||
pub use backend::NebulaGraphBuilder as NebulaGraph; | ||
|
||
mod config; | ||
pub use config::NebulaGraphConfig; |
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