pub struct ProductOSServiceHandler { /* private fields */ }Expand description
Product OS Service Handler
A FeathersJS-compatible service handler that manages CRUD operations for a specific database table. Each handler instance is bound to a single table and provides RESTful endpoints following the FeathersJS service pattern.
§Fields
name: Service identifier (e.g., “users”)path: URL path for the service (e.g., “/api/users”)table_name: Database table nameidentifier_name: Primary key column name (e.g., “id”)controller: Reference to the ProductOS controllerstore: Database connection and query interfacedefault_limit: Default pagination limitdefault_offset: Default pagination offset
§Thread Safety
This struct is thread-safe and can be safely shared across threads using Arc.
The internal ProductOSRelationalStore uses connection pooling for concurrent access.
§Example
let service = ProductOSServiceHandler::new(
"products".to_string(),
"/api/products".to_string(),
"products".to_string(),
"product_id".to_string(),
controller
);Implementations§
Source§impl ProductOSServiceHandler
impl ProductOSServiceHandler
Sourcepub fn new(
name: String,
path: String,
table_name: String,
identifier_name: String,
controller: Arc<Mutex<ProductOSController>>,
) -> Self
pub fn new( name: String, path: String, table_name: String, identifier_name: String, controller: Arc<Mutex<ProductOSController>>, ) -> Self
Creates a new service handler instance
This method initializes a service handler bound to a specific database table. It extracts configuration from the controller including default pagination settings and database connection information.
§Arguments
name- The service identifier (e.g., “users”, “products”)path- The URL path where this service will be mounted (e.g., “/api/users”)table_name- The name of the database table this service managesidentifier_name- The primary key column name (e.g., “id”, “user_id”)controller- Shared reference to the ProductOS controller
§Returns
A new ProductOSServiceHandler instance configured with the specified parameters.
§Example
let service = ProductOSServiceHandler::new(
"users".to_string(),
"/api/users".to_string(),
"users".to_string(),
"id".to_string(),
controller
);Sourcepub async fn load_service(self, router: &mut ProductOSRouter)
pub async fn load_service(self, router: &mut ProductOSRouter)
Registers this service with a router
This method registers the service with the ProductOS controller and adds all necessary routes to the provided router. It sets up both collection routes (for find/create) and individual resource routes (for get/update/patch/remove).
§Arguments
router- Mutable reference to the ProductOS router where routes will be registered
§Routes Created
GET {path}- Find multiple recordsPOST {path}- Create a new recordGET {path}/:id- Get a single recordPUT {path}/:id- Update a record (not implemented)PATCH {path}/:id- Patch a recordDELETE {path}/:id- Remove a record
§Example
let service = ProductOSServiceHandler::new(
"users".to_string(),
"/api/users".to_string(),
"users".to_string(),
"id".to_string(),
controller
);
let mut router = ProductOSRouter::new();
service.load_service(&mut router).await;Sourcepub fn get_store(&self) -> Arc<ProductOSRelationalStore>
pub fn get_store(&self) -> Arc<ProductOSRelationalStore>
Returns a reference to the relational store
Provides access to the underlying database connection for executing queries.
Sourcepub fn get_table_name(&self) -> String
pub fn get_table_name(&self) -> String
Returns the database table name
This is the name of the table in the database that this service manages.
Sourcepub fn get_identifier_name(&self) -> String
pub fn get_identifier_name(&self) -> String
Returns the identifier column name
This is the name of the primary key column used for identifying records.
Sourcepub fn get_path(&self) -> String
pub fn get_path(&self) -> String
Returns the service path
This is the URL path where the service is mounted (e.g., “/api/users”).
Sourcepub fn get_default_limit(&self) -> Option<u32>
pub fn get_default_limit(&self) -> Option<u32>
Returns the default query limit
This limit is used when no explicit $limit is provided in queries.
Sourcepub fn get_default_offset(&self) -> Option<u32>
pub fn get_default_offset(&self) -> Option<u32>
Returns the default query offset
This offset is used when no explicit $skip is provided in queries.
Trait Implementations§
Source§impl Feature for ProductOSServiceHandler
impl Feature for ProductOSServiceHandler
fn register<'life0, 'life1, 'async_trait>(
&'life0 self,
feature: Arc<dyn Feature>,
base_path: String,
router: &'life1 mut ProductOSRouter,
) -> Pin<Box<dyn Future<Output = RegistryFeature> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn register_mut<'life0, 'life1, 'async_trait>(
&'life0 self,
_feature: Arc<Mutex<dyn Feature>>,
_base_path: String,
_router: &'life1 mut ProductOSRouter,
) -> Pin<Box<dyn Future<Output = RegistryFeature> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn identifier(&self) -> String
fn request<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_action: &'life1 What,
_input: &'life2 Option<Value>,
_semver: &'life3 str,
) -> Pin<Box<dyn Future<Output = Response<Body>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn request_mut<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 mut self,
action: &'life1 What,
input: &'life2 Option<Value>,
semver: &'life3 str,
) -> Pin<Box<dyn Future<Output = Response<Body>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn init_feature<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), ()>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn init_feature_mut<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<(), ()>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Auto Trait Implementations§
impl Freeze for ProductOSServiceHandler
impl !RefUnwindSafe for ProductOSServiceHandler
impl Send for ProductOSServiceHandler
impl Sync for ProductOSServiceHandler
impl Unpin for ProductOSServiceHandler
impl !UnwindSafe for ProductOSServiceHandler
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
Source§impl<T> CastSliceMut<'_, T> for T
impl<T> CastSliceMut<'_, T> for T
fn cast_slice_mut(selves: &mut [T]) -> &mut [T]
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>
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>
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