Skip to main content

AdminDatabase

Struct AdminDatabase 

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

Admin database interface

Provides CRUD operations for admin panel, leveraging reinhardt-orm.

§Examples

use reinhardt_admin::core::AdminDatabase;
use reinhardt_db::orm::{DatabaseConnection, DatabaseBackend, Model};
use std::sync::Arc;
use serde::{Serialize, Deserialize};

let conn = DatabaseConnection::connect("postgres://localhost/test").await?;
let db = AdminDatabase::new(conn);

// List items with filters
let items = db.list::<User>("users", vec![], 0, 50).await?;

// Placeholder User type for example
#[derive(Clone, Debug, Serialize, Deserialize)]
struct User {
    id: Option<i64>,
    name: String,
}

reinhardt_test::impl_test_model!(User, i64, "users");

Implementations§

Source§

impl AdminDatabase

Source

pub fn new(connection: DatabaseConnection) -> Self

Create a new admin database interface

This method accepts a DatabaseConnection directly without requiring Arc wrapping. The Arc wrapping is handled internally for you.

Source

pub fn from_arc(connection: Arc<DatabaseConnection>) -> Self

Create a new admin database interface from an Arc-wrapped connection

This is provided for cases where you already have an Arc<DatabaseConnection>. In most cases, you should use new() instead.

Source

pub fn connection(&self) -> &DatabaseConnection

Get a reference to the underlying database connection

Source

pub fn connection_arc(&self) -> Arc<DatabaseConnection>

Get a cloned Arc of the connection (for cases where you need ownership)

In most cases, you should use connection() instead to get a reference.

Source

pub async fn list<M: Model>( &self, table_name: &str, filters: Vec<Filter>, offset: u64, limit: u64, ) -> AdminResult<Vec<HashMap<String, Value>>>

List items with filters, ordering, and pagination

§Examples
use reinhardt_admin::core::AdminDatabase;
use reinhardt_db::orm::{DatabaseConnection, DatabaseBackend, Model, Filter, FilterOperator, FilterValue};
use std::sync::Arc;
use serde::{Serialize, Deserialize};

let conn = DatabaseConnection::connect("postgres://localhost/test").await?;
let db = AdminDatabase::new(conn);

let filters = vec![
    Filter::new("is_active".to_string(), FilterOperator::Eq, FilterValue::Boolean(true))
];

let items = db.list::<User>("users", filters, 0, 50).await?;

#[derive(Clone, Debug, Serialize, Deserialize)]
struct User {
    id: Option<i64>,
    name: String,
}

reinhardt_test::impl_test_model!(User, i64, "users");
Source

pub async fn list_with_condition<M: Model>( &self, table_name: &str, filter_condition: Option<&FilterCondition>, additional_filters: Vec<Filter>, sort_by: Option<&str>, offset: u64, limit: u64, ) -> AdminResult<Vec<HashMap<String, Value>>>

List items with composite filter conditions (supports AND/OR logic)

This method supports complex filter conditions using FilterCondition, which allows building nested AND/OR queries.

§Arguments
  • table_name - The name of the table to query
  • filter_condition - Optional composite filter condition (AND/OR logic)
  • additional_filters - Additional simple filters to AND with the condition
  • sort_by - Optional sort field (prefix with “-” for descending, e.g., “created_at” or “-created_at”)
  • offset - Number of items to skip for pagination
  • limit - Maximum number of items to return
Source

pub async fn count_with_condition<M: Model>( &self, table_name: &str, filter_condition: Option<&FilterCondition>, additional_filters: Vec<Filter>, ) -> AdminResult<u64>

Count items with composite filter conditions (supports AND/OR logic)

§Arguments
  • table_name - The name of the table to query
  • filter_condition - Optional composite filter condition (AND/OR logic)
  • additional_filters - Additional simple filters to AND with the condition
Source

pub async fn get<M: Model>( &self, table_name: &str, pk_field: &str, id: &str, ) -> AdminResult<Option<HashMap<String, Value>>>

Get a single item by ID

§Examples
use reinhardt_admin::core::AdminDatabase;
use reinhardt_db::orm::{DatabaseConnection, DatabaseBackend, Model};
use std::sync::Arc;
use serde::{Serialize, Deserialize};

let conn = DatabaseConnection::connect("postgres://localhost/test").await?;
let db = AdminDatabase::new(conn);

let item = db.get::<User>("users", "id", "1").await?;

#[derive(Clone, Debug, Serialize, Deserialize)]
struct User {
    id: Option<i64>,
    name: String,
}

reinhardt_test::impl_test_model!(User, i64, "users");
Source

pub async fn create<M: Model>( &self, table_name: &str, data: HashMap<String, Value>, ) -> AdminResult<u64>

Create a new item

§Examples
use reinhardt_admin::core::AdminDatabase;
use reinhardt_db::orm::{DatabaseConnection, DatabaseBackend, Model};
use std::sync::Arc;
use std::collections::HashMap;
use serde::{Serialize, Deserialize};

let conn = DatabaseConnection::connect("postgres://localhost/test").await?;
let db = AdminDatabase::new(conn);

let mut data = HashMap::new();
data.insert("name".to_string(), serde_json::json!("Alice"));
data.insert("email".to_string(), serde_json::json!("alice@example.com"));

db.create::<User>("users", data).await?;

#[derive(Clone, Debug, Serialize, Deserialize)]
struct User {
    id: Option<i64>,
    name: String,
}

reinhardt_test::impl_test_model!(User, i64, "users");
Source

pub async fn update<M: Model>( &self, table_name: &str, pk_field: &str, id: &str, data: HashMap<String, Value>, ) -> AdminResult<u64>

Update an existing item

§Examples
use reinhardt_admin::core::AdminDatabase;
use reinhardt_db::orm::{DatabaseConnection, DatabaseBackend, Model};
use std::sync::Arc;
use std::collections::HashMap;
use serde::{Serialize, Deserialize};

let conn = DatabaseConnection::connect("postgres://localhost/test").await?;
let db = AdminDatabase::new(conn);

let mut data = HashMap::new();
data.insert("name".to_string(), serde_json::json!("Alice Updated"));

db.update::<User>("users", "id", "1", data).await?;

#[derive(Clone, Debug, Serialize, Deserialize)]
struct User {
    id: Option<i64>,
    name: String,
}

reinhardt_test::impl_test_model!(User, i64, "users");
Source

pub async fn delete<M: Model>( &self, table_name: &str, pk_field: &str, id: &str, ) -> AdminResult<u64>

Delete an item by ID

§Examples
use reinhardt_admin::core::AdminDatabase;
use reinhardt_db::orm::{DatabaseConnection, DatabaseBackend, Model};
use std::sync::Arc;
use serde::{Serialize, Deserialize};

let conn = DatabaseConnection::connect("postgres://localhost/test").await?;
let db = AdminDatabase::new(conn);

db.delete::<User>("users", "id", "1").await?;

#[derive(Clone, Debug, Serialize, Deserialize)]
struct User {
    id: Option<i64>,
    name: String,
}

reinhardt_test::impl_test_model!(User, i64, "users");
Source

pub async fn bulk_delete<M: Model>( &self, table_name: &str, pk_field: &str, ids: Vec<String>, ) -> AdminResult<u64>

Delete multiple items by IDs (bulk delete)

§Examples
use reinhardt_admin::core::AdminDatabase;
use reinhardt_db::orm::{DatabaseConnection, DatabaseBackend, Model};
use std::sync::Arc;
use serde::{Serialize, Deserialize};

let conn = DatabaseConnection::connect("postgres://localhost/test").await?;
let db = AdminDatabase::new(conn);

let ids = vec!["1".to_string(), "2".to_string(), "3".to_string()];
db.bulk_delete::<User>("users", "id", ids).await?;

#[derive(Clone, Debug, Serialize, Deserialize)]
struct User {
    id: Option<i64>,
    name: String,
}

reinhardt_test::impl_test_model!(User, i64, "users");
Source

pub async fn bulk_delete_by_table( &self, table_name: &str, pk_field: &str, ids: Vec<String>, ) -> AdminResult<u64>

Delete multiple items by IDs without requiring Model type parameter

This method provides a type-safe way to perform bulk deletions without requiring a Model type parameter. It’s particularly useful for admin actions where the model type may not be known at compile time.

§Examples
use reinhardt_admin::core::AdminDatabase;
use reinhardt_db::orm::DatabaseConnection;

let conn = DatabaseConnection::connect("postgres://localhost/test").await?;
let db = AdminDatabase::new(conn);

let ids = vec!["1".to_string(), "2".to_string(), "3".to_string()];
db.bulk_delete_by_table("users", "id", ids).await?;
Source

pub async fn count<M: Model>( &self, table_name: &str, filters: Vec<Filter>, ) -> AdminResult<u64>

Count total items with optional filters

§Examples
use reinhardt_admin::core::AdminDatabase;
use reinhardt_db::orm::{DatabaseConnection, DatabaseBackend, Model, Filter, FilterOperator, FilterValue};
use std::sync::Arc;
use serde::{Serialize, Deserialize};

let conn = DatabaseConnection::connect("postgres://localhost/test").await?;
let db = AdminDatabase::new(conn);

let filters = vec![
    Filter::new("is_active".to_string(), FilterOperator::Eq, FilterValue::Boolean(true))
];

let count = db.count::<User>("users", filters).await?;

#[derive(Clone, Debug, Serialize, Deserialize)]
struct User {
    id: Option<i64>,
    name: String,
}

reinhardt_test::impl_test_model!(User, i64, "users");

Trait Implementations§

Source§

impl Clone for AdminDatabase

Source§

fn clone(&self) -> AdminDatabase

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Injectable for AdminDatabase

Injectable trait implementation for AdminDatabase

This allows AdminDatabase to be injected via the DI container. The implementation resolves Arc<AdminDatabase> from the container and clones the inner value.

Source§

fn inject<'life0, 'async_trait>( ctx: &'life0 InjectionContext, ) -> Pin<Box<dyn Future<Output = DiResult<Self>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn inject_uncached<'life0, 'async_trait>( ctx: &'life0 InjectionContext, ) -> Pin<Box<dyn Future<Output = Result<Self, DiError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Inject without using cache (for cache = false support). Read more

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> Chain<T> for T

Source§

fn len(&self) -> usize

The number of items that this chain link consists of.
Source§

fn append_to(self, v: &mut Vec<T>)

Append the elements in this link to the chain.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Container<T> for T
where T: Clone,

Source§

type Iter = Once<T>

An iterator over the items within this container, by value.
Source§

fn get_iter(&self) -> <T as Container<T>>::Iter

Iterate over the elements of the container (using internal iteration because GATs are unstable).
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> OrderedContainer<T> for T
where T: Clone,