pub struct DatabaseManager { /* private fields */ }
Expand description
Database manager for handling database operations and queries
Implementations§
Source§impl DatabaseManager
impl DatabaseManager
Sourcepub async fn list(&self) -> Result<Vec<Database>>
pub async fn list(&self) -> Result<Vec<Database>>
List all databases
§Examples
use zero_trust_sdk::{ZeroTrustClient, Config};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::new("https://api.zerotrust.com")?
.with_token("your-jwt-token");
let client = ZeroTrustClient::new(config).await?;
let databases = client.databases().list().await?;
for db in databases {
println!("Database: {} ({} tables)", db.name, db.tables.len());
}
Ok(())
}
Sourcepub async fn create<S: AsRef<str>>(&self, name: S) -> Result<Database>
pub async fn create<S: AsRef<str>>(&self, name: S) -> Result<Database>
Create a new database
§Arguments
name
- Database name
§Examples
use zero_trust_sdk::{ZeroTrustClient, Config};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::new("https://api.zerotrust.com")?
.with_token("your-jwt-token");
let client = ZeroTrustClient::new(config).await?;
let database = client.databases().create("my-app-db").await?;
println!("Created database: {}", database.name);
Ok(())
}
Sourcepub async fn get<S: AsRef<str>>(&self, name: S) -> Result<Database>
pub async fn get<S: AsRef<str>>(&self, name: S) -> Result<Database>
Get database information
§Arguments
name
- Database name
§Examples
use zero_trust_sdk::{ZeroTrustClient, Config};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::new("https://api.zerotrust.com")?
.with_token("your-jwt-token");
let client = ZeroTrustClient::new(config).await?;
let database = client.databases().get("my-app-db").await?;
println!("Database {} has {} tables", database.name, database.tables.len());
Ok(())
}
Sourcepub async fn delete<S: AsRef<str>>(&self, name: S) -> Result<()>
pub async fn delete<S: AsRef<str>>(&self, name: S) -> Result<()>
Delete a database
§Arguments
name
- Database name
§Examples
use zero_trust_sdk::{ZeroTrustClient, Config};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::new("https://api.zerotrust.com")?
.with_token("your-jwt-token");
let client = ZeroTrustClient::new(config).await?;
client.databases().delete("old-database").await?;
println!("Database deleted successfully");
Ok(())
}
Sourcepub fn query<S: AsRef<str>>(&self, database: S) -> QueryBuilder
pub fn query<S: AsRef<str>>(&self, database: S) -> QueryBuilder
Get a query builder for the specified database
§Arguments
database
- Database name
§Examples
use zero_trust_sdk::{ZeroTrustClient, Config};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::new("https://api.zerotrust.com")?
.with_token("your-jwt-token");
let client = ZeroTrustClient::new(config).await?;
let result = client.databases()
.query("my-app-db")
.execute("SELECT * FROM users LIMIT 10")
.await?;
println!("Found {} rows", result.meta.row_count);
Ok(())
}
Sourcepub async fn list_tables<S: AsRef<str>>(
&self,
database: S,
) -> Result<Vec<Table>>
pub async fn list_tables<S: AsRef<str>>( &self, database: S, ) -> Result<Vec<Table>>
List tables in a database
§Arguments
database
- Database name
§Examples
use zero_trust_sdk::{ZeroTrustClient, Config};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::new("https://api.zerotrust.com")?
.with_token("your-jwt-token");
let client = ZeroTrustClient::new(config).await?;
let tables = client.databases().list_tables("my-app-db").await?;
for table in tables {
println!("Table: {} ({} columns)", table.name, table.columns.len());
}
Ok(())
}
Sourcepub async fn get_table<S1, S2>(&self, database: S1, table: S2) -> Result<Table>
pub async fn get_table<S1, S2>(&self, database: S1, table: S2) -> Result<Table>
Get table information
§Arguments
database
- Database nametable
- Table name
§Examples
use zero_trust_sdk::{ZeroTrustClient, Config};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::new("https://api.zerotrust.com")?
.with_token("your-jwt-token");
let client = ZeroTrustClient::new(config).await?;
let table = client.databases().get_table("my-app-db", "users").await?;
println!("Table {} has {} rows", table.name, table.row_count.unwrap_or(0));
Ok(())
}
Trait Implementations§
Source§impl Clone for DatabaseManager
impl Clone for DatabaseManager
Source§fn clone(&self) -> DatabaseManager
fn clone(&self) -> DatabaseManager
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for DatabaseManager
impl !RefUnwindSafe for DatabaseManager
impl Send for DatabaseManager
impl Sync for DatabaseManager
impl Unpin for DatabaseManager
impl !UnwindSafe for DatabaseManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more