Skip to main content

ProductOSServiceHandler

Struct ProductOSServiceHandler 

Source
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 name
  • identifier_name: Primary key column name (e.g., “id”)
  • controller: Reference to the ProductOS controller
  • store: Database connection and query interface
  • default_limit: Default pagination limit
  • default_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

Source

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 manages
  • identifier_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
);
Source

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 records
  • POST {path} - Create a new record
  • GET {path}/:id - Get a single record
  • PUT {path}/:id - Update a record (not implemented)
  • PATCH {path}/:id - Patch a record
  • DELETE {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;
Source

pub fn get_store(&self) -> Arc<ProductOSRelationalStore>

Returns a reference to the relational store

Provides access to the underlying database connection for executing queries.

Source

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.

Source

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.

Source

pub fn get_path(&self) -> String

Returns the service path

This is the URL path where the service is mounted (e.g., “/api/users”).

Source

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.

Source

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

Source§

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,

Source§

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,

Source§

fn identifier(&self) -> String

Source§

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,

Source§

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,

Source§

fn init_feature<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), ()>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Source§

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§

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> CastSlice<'_, T> for T

Source§

fn cast_slice(selves: &[T]) -> &[T]

Source§

impl<T> CastSliceMut<'_, T> for T

Source§

fn cast_slice_mut(selves: &mut [T]) -> &mut [T]

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

Source§

type Output = T

Should always be Self
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