Galaxy

Struct Galaxy 

Source
pub struct Galaxy { /* private fields */ }
Expand description

A Galaxy is the storage engine for one TuGraph instance. It manages a set of User/Role/GraphDBs.

A galaxy can be opened in async mode, in which case ALL write transactions will be treated as async, whether they declare async or not. This can come in handy if we are performing a lot of writing, but can cause data loss for online processing.

Implementations§

Source§

impl Galaxy

Source

pub fn open<P: AsRef<Path>>( dir: P, username: &str, password: &str, ) -> Result<Galaxy>

Open Galaxy at dir with username and password

If more options are need to open, use OpenOptions instead.

§Errors

TODO(eadrenking@outlook.com)

§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
    .create(true)
    .open("/tmp/rust_tugraph/doc/galaxy_open", "admin", "73@TuGraph")?;
Source

pub fn set_current_user(&self, user: &str, password: &str) -> Result<()>

Switch current user with password.

§Errors

TODO(eadrenking@outlook.com)

§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
    .create(true)
    .open("/tmp/rust_tugraph/doc/set_current_user", "admin", "73@TuGraph")?;
galaxy.set_current_user("test_user1", "test_password1");
Source

pub fn set_user_without_auth(&self, user: &str) -> Result<()>

Switch current user without authorization.

Note: It is you user’s responsibility to make sure the current user have right permissions to switch.

§Errors

TODO(eadrenking@outlook.com)

§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
    .create(true)
    .open("/tmp/rust_tugraph/doc/set_user_without_auth", "admin", "73@TuGraph")?;
galaxy.set_user_without_auth("test_user1");
Source

pub fn create_graph( &self, name: &str, desc: &str, max_size: usize, ) -> Result<bool>

Create graph with name, description and max size in bytes of graph stored in filesystem.

§Errors

TODO(eadrenking@outlook.com)

§Examples
use tugraph::{db::{OpenOptions, MINIMUM_GRAPH_MAX_SIZE}, Error};
let galaxy = OpenOptions::new()
    .create(true)
    .open("/tmp/rust_tugraph/doc/create_graph", "admin", "73@TuGraph")?;
let _ = galaxy.create_graph(
    "test_create_graph",
    "graph created in test_create_graph",
    MINIMUM_GRAPH_MAX_SIZE,
)?;
Source

pub fn delete_graph(&self, graph: &str) -> Result<bool>

Create graph with name, description and max size in bytes of graph stored in filesystem.

§Errors

TODO(eadrenking@outlook.com)

§Examples
use tugraph::{db::{OpenOptions, MINIMUM_GRAPH_MAX_SIZE}, Error};
let galaxy = OpenOptions::new()
    .create(true)
    .open("/tmp/rust_tugraph/doc/delete_graph", "admin", "73@TuGraph")?;
let _ = galaxy.create_graph(
    "test_create_graph",
    "graph created in test_create_graph",
    MINIMUM_GRAPH_MAX_SIZE,
)?;
Source

pub fn mod_graph(&self) -> ModGraphOptions<'_>

Modify graph info.

§Errors

TODO(eadrenking@outlook.com)

§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
    .create(true)
    .open("/tmp/rust_tugraph/doc/mod_graph", "admin", "73@TuGraph")?;
let modified = galaxy
    .mod_graph()
    .mod_desc("The new description of default graph".to_string())
    .apply("default")?;
Source

pub fn list_graphs(&self) -> Result<Vec<ListGraph>>

List graphs.

§Errors

TODO(eadrenking@outlook.com)

§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
    .create(true)
    .open("/tmp/rust_tugraph/doc/list_graphs", "admin", "73@TuGraph")?;
let graphs = galaxy.list_graphs()?;
Source

pub fn create_user( &self, username: &str, password: &str, desc: &str, ) -> Result<bool>

Create a user.

§Errors

TODO(eadrenking@outlook.com)

§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
    .create(true)
    .open("/tmp/rust_tugraph/doc/create_user", "admin", "73@TuGraph")?;
let created = galaxy.create_user("test_user1", "test_password1", "user one")?;
Source

pub fn delete_user(&self, username: &str) -> Result<bool>

Delete a user.

§Errors

TODO(eadrenking@outlook.com)

§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
    .create(true)
    .open("/tmp/rust_tugraph/doc/delete_user", "admin", "73@TuGraph")?;
galaxy.create_user("test_user1", "test_password1", "user one")?;
let deleted = galaxy.delete_user("test_user1")?;
assert!(deleted);
Source

pub fn set_password( &self, username: &str, old_password: &str, new_password: &str, ) -> Result<bool>

Set the password of the specified user.

§Errors

TODO(eadrenking@outlook.com)

§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
    .create(true)
    .open("/tmp/rust_tugraph/doc/set_password", "admin", "73@TuGraph")?;
galaxy.set_password("test_user1", "test_password1", "new_password1")?;
Source

pub fn set_user_desc(&self, username: &str, desc: &str) -> Result<bool>

Set user description.

§Errors

TODO(eadrenking@outlook.com)

§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
    .create(true)
    .open("/tmp/rust_tugraph/doc/set_user_desc", "admin", "73@TuGraph")?;
galaxy.set_user_desc("test_user1", "new_description")?;
Source

pub fn set_user_roles<'a, R>(&self, username: &str, roles: R) -> Result<bool>
where R: IntoIterator<Item = &'a str>,

Set the roles of the specified user. If you need to add or delete a role, you will need to use GetUserInfo to get the roles first.

Note: Only admin can set user roles.

§Errors

TODO(eadrenking@outlook.com)

§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
    .create(true)
    .open("/tmp/rust_tugraph/doc/set_user_roles", "admin", "73@TuGraph")?;
galaxy.create_user("test_user1", "test_password1", "test user one")?;
galaxy.create_role("operator", "A good operator")?;
galaxy.create_role("crud_boy", "Create, retrieve, update and delete data all day")?;
galaxy.set_user_roles("test_user1", ["operator", "crud_boy"])?;
Source

pub fn set_user_graph_access( &self, username: &str, graph: &str, access: AccessLevel, ) -> Result<bool>

Sets user access rights on a graph.

§Errors

TODO(eadrenking@outlook.com)

§Examples
use tugraph::{db::OpenOptions, types::AccessLevel, Error};
let galaxy = OpenOptions::new()
    .create(true)
    .open("/tmp/rust_tugraph/doc/set_user_graph_access", "admin", "73@TuGraph")?;
galaxy
    .set_user_graph_access("test_user1", "default", AccessLevel::Full)?;
Source

pub fn disable_user(&self, username: &str) -> Result<bool>

Disable a user. A disabled user is not able to login or perform any operation. A user cannot disable itself.

§Errors

TODO(eadrenking@outlook.com)

§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
    .create(true)
    .open("/tmp/rust_tugraph/doc/disable_user", "admin", "73@TuGraph")?;
galaxy.create_user("test_user1", "test_password1", "user one")?;
galaxy.disable_user("test_user1")?;
Source

pub fn enable_user(&self, username: &str) -> Result<bool>

Enable a user.

§Errors

TODO(eadrenking@outlook.com)

§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
    .create(true)
    .open("/tmp/rust_tugraph/doc/enable_user", "admin", "73@TuGraph")?;
galaxy.create_user("test_user1", "test_password1", "user one")?;
galaxy.disable_user("test_user1")?;
galaxy.enable_user("test_user1")?;
Source

pub fn list_users(&self) -> Result<Vec<ListUser>>

List all users

§Errors

TODO(eadrenking@outlook.com)

§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
    .create(true)
    .open("/tmp/rust_tugraph/doc/list_users", "admin", "73@TuGraph")?;
galaxy
    .create_user("test_user1", "test_password1", "user one")?;
galaxy
    .create_user("test_user2", "test_password2", "user two")?;
let users = galaxy.list_users()?;
Source

pub fn get_user_info(&self, username: &str) -> Result<UserInfo>

Get user information

§Errors

TODO(eadrenking@outlook.com)

§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
    .create(true)
    .open("/tmp/rust_tugraph/doc/get_user_info", "admin", "73@TuGraph")?;
galaxy
    .create_user("test_user1", "test_password1", "user one")?;
let info = galaxy.get_user_info("test_user1")?;
Source

pub fn create_role(&self, role: &str, desc: &str) -> Result<bool>

Create a role. A role has different access levels to different graphs. Every user must be assigned some role to get access to graphs.

§Errors

TODO(eadrenking@outlook.com)

§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
    .create(true)
    .open("/tmp/rust_tugraph/doc/create_role", "admin", "73@TuGraph")?;
galaxy.create_role("operator", "a operator role")?;
Source

pub fn delete_role(&self, role: &str) -> Result<bool>

Deletes the role.

§Errors

TODO(eadrenking@outlook.com)

§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
    .create(true)
    .open("/tmp/rust_tugraph/doc/delete_role", "admin", "73@TuGraph")?;
galaxy.create_role("operator", "a operator role")?;
galaxy.delete_role("operator")?;
Source

pub fn disable_role(&self, role: &str) -> Result<bool>

Disable a role.

A disabled role still has the data, but is not effective. i.e., users will not have access rights to graphs that are obtained by having this role.

§Errors

TODO(eadrenking@outlook.com)

§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
    .create(true)
    .open("/tmp/rust_tugraph/doc/disable_role", "admin", "73@TuGraph")?;
galaxy.create_role("operator", "a operator role")?;
galaxy.disable_role("operator")?;
Source

pub fn enable_role(&self, role: &str) -> Result<bool>

Enable the role.

§Errors

TODO(eadrenking@outlook.com)

§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy =  OpenOptions::new()
    .create(true)
    .open("/tmp/rust_tugraph/doc/enable_role", "admin", "73@TuGraph")?;
galaxy.create_role("operator", "a operator role")?;
galaxy.disable_role("operator")?;
galaxy.enable_role("operator")?;
Source

pub fn set_role_desc(&self, role: &str, desc: &str) -> Result<bool>

Set the description of the specified role

§Errors

TODO(eadrenking@outlook.com)

§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
    .create(true)
    .open("/tmp/rust_tugraph/doc/set_role_desc", "admin", "73@TuGraph")?;
galaxy.create_role("operator", "a operator role")?;
galaxy.set_role_desc("operator", "a good operator")?;
Source

pub fn set_role_access_rights<'a, T>( &self, role: &str, graph_access: T, ) -> Result<bool>
where T: IntoIterator<Item = &'a GraphAccess>,

Set access of the role to graphs.

If you need to add or remove access to part of the graphs, you need to get full graph_access map by using GetRoleInfo first.

§Errors

TODO(eadrenking@outlook.com)

§Examples
use tugraph::{
    db::{OpenOptions, GraphAccess},
    types::AccessLevel,
    Error,
};
let galaxy = OpenOptions::new()
    .create(true)
    .open("/tmp/rust_tugraph/doc/set_role_access_rights", "admin", "73@TuGraph")?;
galaxy.create_role("operator", "a operator role")?;
galaxy.set_role_access_rights(
    "operator",
    &[GraphAccess {
        name: "default".to_string(),
        access_level: AccessLevel::Full,
    }],
)?;
Source

pub fn set_role_access_rights_incremental<'a, T>( &self, role: &str, graph_access: T, ) -> Result<bool>
where T: IntoIterator<Item = &'a GraphAccess>,

Incrementally modify the access right of the specified role.

For example, for a role that has access right {graph1:READ, graph2:WRITE}, calling this function with graph_access={graph2:READ, graph3:FULL} will set the access right of this role to {graph1:READ, graph2:READ, graph3:FULL}

§Errors

TODO(eadrenking@outlook.com)

§Examples
use tugraph::{
    db::{OpenOptions, GraphAccess, MINIMUM_GRAPH_MAX_SIZE},
    types::AccessLevel,
    Error,
};
let galaxy = OpenOptions::new()
    .create(true)
    .open("/tmp/rust_tugraph/doc/set_role_access_rights_incremental", "admin", "73@TuGraph")?;
galaxy
    .create_graph("test_graph1", "test graph one", MINIMUM_GRAPH_MAX_SIZE)?;
galaxy.create_role("operator", "a operator role")?;
galaxy.set_role_access_rights_incremental(
    "operator",
    &[GraphAccess {
        name: "default".to_string(),
        access_level: AccessLevel::Write,
    }],
)?;
galaxy.set_role_access_rights_incremental(
    "operator",
    &[GraphAccess {
        name: "test_graph1".to_string(),
        access_level: AccessLevel::Read,
    }],
)?;
Source

pub fn get_role_info(&self, role: &str) -> Result<RoleInfo>

Gets role information.

§Errors

TODO(eadrenking@outlook.com)

§Examples
use tugraph::{db::{OpenOptions, GraphAccess}, Error};
let galaxy = OpenOptions::new()
    .create(true)
    .open("/tmp/rust_tugraph/doc/get_role_info", "admin", "73@TuGraph")?;
galaxy.create_role("operator", "a operator role")?;
let info = galaxy.get_role_info("operator")?;
Source

pub fn list_roles(&self) -> Result<Vec<ListRole>>

List all the roles.

§Errors

TODO(eadrenking@outlook.com)

§Examples
use tugraph::{db::{OpenOptions, GraphAccess}, Error};
let galaxy = OpenOptions::new()
    .create(true)
    .open("/tmp/rust_tugraph/doc/list_roles", "admin", "73@TuGraph")?;
galaxy.create_role("operator", "a operator role")?;
let roles: Vec<_> = galaxy.list_roles()?;
Source

pub fn get_access_level( &self, username: &str, graph: &str, ) -> Result<AccessLevel>

Get the access level that the specified user have to the graph

§Errors

TODO(eadrenking@outlook.com)

§Examples
use tugraph::{db::{OpenOptions, GraphAccess}, Error};
let galaxy = OpenOptions::new()
    .create(true)
    .open("/tmp/rust_tugraph/doc/get_access_level", "admin", "73@TuGraph")?;
galaxy.get_access_level("admin", "default")?;
Source

pub fn open_graph(&self, graph: &str, read_only: bool) -> Result<Graph<'_>>

Open a graph.

§Errors

TODO(eadrenking@outlook.com)

§Examples
use tugraph::{db::OpenOptions, Error};
let galaxy = OpenOptions::new()
    .create(true)
    .open("/tmp/rust_tugraph/doc/open_graph", "admin", "73@TuGraph")?;
let graph = galaxy.open_graph("default", false)?;

Trait Implementations§

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.