#![no_std]
extern crate no_std_compat as std;
extern crate alloc;
use core::fmt::Formatter;
use std::prelude::v1::*;
use std::fmt::Display;
cfg_if::cfg_if! {
if #[cfg(feature = "key_value_store")] {
mod key_value_store;
#[cfg(feature = "redis_key_value_store")]
mod redis_key_value_store;
#[cfg(feature = "memory_key_value_store")]
mod memory_key_value_store;
#[cfg(feature = "file_key_value_store")]
mod file_key_value_store;
mod sink_key_value_store;
use product_os_configuration::KeyValueKind;
use std::collections::BTreeMap;
use crate::key_value_store::ProductOSKeyValueStoreEngine;
use crate::sink_key_value_store::ProductOSSinkKeyValueStore;
#[cfg(feature = "redis_key_value_store")]
use crate::redis_key_value_store::ProductOSRedisKeyValueStore;
#[cfg(feature = "memory_key_value_store")]
use crate::memory_key_value_store::ProductOSMemoryKeyValueStore;
#[cfg(feature = "file_key_value_store")]
use crate::file_key_value_store::ProductOSFileKeyValueStore;
}
}
cfg_if::cfg_if! {
if #[cfg(feature = "queue_store")] {
mod queue_store;
#[cfg(feature = "redis_queue_store")]
mod redis_queue_store;
#[cfg(feature = "memory_queue_store")]
mod memory_queue_store;
#[cfg(feature = "file_queue_store")]
mod file_queue_store;
mod sink_queue_store;
use product_os_configuration::QueueKind;
use crate::queue_store::ProductOSQueueStoreEngine;
use crate::sink_queue_store::ProductOSSinkQueueStore;
#[cfg(feature = "redis_queue_store")]
use crate::redis_queue_store::ProductOSRedisQueueStore;
#[cfg(feature = "memory_queue_store")]
use crate::memory_queue_store::ProductOSMemoryQueueStore;
#[cfg(feature = "file_queue_store")]
use crate::file_queue_store::ProductOSFileQueueStore;
}
}
cfg_if::cfg_if! {
if #[cfg(feature = "relational_store")] {
mod relational_store;
#[cfg(feature = "postgres_relational_store")]
mod postgres_relational_store;
#[cfg(feature = "sqlite_relational_store")]
mod sqlite_relational_store;
mod memory_relational_store;
mod sink_relational_store;
mod sql_query_processing;
pub use relational_store::{
ProductOSRelationalObject, ProductOSRelationalStoreEngine,Query, Fields, Field, Operation, Table,
SortOrder, DistinctType, Expression, Join, Fetch, InstructionType, Value, Target, Action, Instruction,
Constraint, ConstraintFunction, ConstraintAction, DataType, Sharding,
RelationalRow, RelationalColumn, RelationalError, RelationalResult, RelationalTransaction
};
use product_os_configuration::RelationalKind;
use crate::sql_query_processing::{query_to_string, instruction_to_string, process_instruction_to_string, process_query_to_string};
#[cfg(feature = "postgres_relational_store")]
use postgres_relational_store::ProductOSPostgresRelationalStore;
#[cfg(feature = "sqlite_relational_store")]
use sqlite_relational_store::ProductOSSqliteRelationalStore;
use sink_relational_store::ProductOSSinkRelationalStore;
#[cfg(feature = "sql_relational_store")]
pub use sqlx::{
Row as ProductOSRow, FromRow, types,
Column as ProductOSColumn,
Error as SqlError,
error::UnexpectedNullError as SqlNullError
};
#[cfg(feature = "postgres_relational_store")]
pub use sqlx::{
Postgres, postgres::{ PgQueryResult, PgRow },
};
#[cfg(feature = "sqlite_relational_store")]
pub use sqlx::{
Sqlite, sqlite::{ SqliteQueryResult, SqliteRow },
};
}
}
#[cfg(feature = "document_store")]
mod document_store;
#[cfg(feature = "event_store")]
mod event_store;
#[derive(Debug)]
pub enum ProductOSStoreError {
ConnectionError(String),
QueryError(String),
WriteError(String),
ReadError(String),
DeleteError(String)
}
impl Display for ProductOSStoreError {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
let value = format!("{:?}", self);
write!(f, "{:?}", value)
}
}
#[cfg(feature = "relational_store")]
pub enum ProductOSKeyValueStorageType {
Redis,
Memory,
File,
Sink
}
#[cfg(feature = "key_value_store")]
pub enum ProductOSKeyValueStorage {
#[cfg(feature = "redis_key_value_store")]
Redis(ProductOSRedisKeyValueStore),
#[cfg(feature = "memory_key_value_store")]
Memory(ProductOSMemoryKeyValueStore),
#[cfg(feature = "file_key_value_store")]
File(ProductOSFileKeyValueStore),
Sink(ProductOSSinkKeyValueStore)
}
#[cfg(feature = "key_value_store")]
pub struct ProductOSKeyValueStore {
store: ProductOSKeyValueStorage
}
#[cfg(feature = "key_value_store")]
impl ProductOSKeyValueStore {
pub fn new(config: &product_os_configuration::KeyValueStore) -> Self {
match config.kind {
#[cfg(feature = "redis_key_value_store")]
KeyValueKind::Redis => Self {
store: ProductOSKeyValueStorage::Redis(ProductOSRedisKeyValueStore::new(config))
},
KeyValueKind::Sink => Self {
store: ProductOSKeyValueStorage::Sink(ProductOSSinkKeyValueStore::new(config))
},
#[cfg(feature = "memory_key_value_store")]
KeyValueKind::Memory => Self {
store: ProductOSKeyValueStorage::Memory(ProductOSMemoryKeyValueStore::new(config))
},
#[cfg(feature = "file_key_value_store")]
KeyValueKind::File => Self {
store: ProductOSKeyValueStorage::File(ProductOSFileKeyValueStore::new(config))
},
_ => panic!("Key value store kind not currently supported")
}
}
pub fn connect(&mut self) -> Result<(), ProductOSStoreError> {
match &mut self.store {
#[cfg(feature = "redis_key_value_store")]
ProductOSKeyValueStorage::Redis(store) => store.connect(),
ProductOSKeyValueStorage::Sink(store) => store.connect(),
#[cfg(feature = "memory_key_value_store")]
ProductOSKeyValueStorage::Memory(store) => store.connect(),
#[cfg(feature = "file_key_value_store")]
ProductOSKeyValueStorage::File(store) => store.connect(),
_ => panic!("Key value store kind not currently supported")
}
}
pub fn disconnect(&mut self) -> Result<(), ProductOSStoreError> {
match &mut self.store {
#[cfg(feature = "redis_key_value_store")]
ProductOSKeyValueStorage::Redis(store) => store.disconnect(),
ProductOSKeyValueStorage::Sink(store) => store.disconnect(),
#[cfg(feature = "memory_key_value_store")]
ProductOSKeyValueStorage::Memory(store) => store.disconnect(),
#[cfg(feature = "file_key_value_store")]
ProductOSKeyValueStorage::File(store) => store.disconnect(),
_ => panic!("Key value store kind not currently supported")
}
}
pub fn set_group(&mut self, group: &str) {
match &mut self.store {
#[cfg(feature = "redis_key_value_store")]
ProductOSKeyValueStorage::Redis(store) => store.set_group(group),
ProductOSKeyValueStorage::Sink(store) => store.set_group(group),
#[cfg(feature = "memory_key_value_store")]
ProductOSKeyValueStorage::Memory(store) => store.set_group(group),
#[cfg(feature = "file_key_value_store")]
ProductOSKeyValueStorage::File(store) => store.set_group(group),
_ => panic!("Key value store kind not currently supported")
}
}
pub fn set_group_type(&mut self, group_type: &str) {
match &mut self.store {
#[cfg(feature = "redis_key_value_store")]
ProductOSKeyValueStorage::Redis(store) => store.set_group_type(group_type),
ProductOSKeyValueStorage::Sink(store) => store.set_group_type(group_type),
#[cfg(feature = "memory_key_value_store")]
ProductOSKeyValueStorage::Memory(store) => store.set_group_type(group_type),
#[cfg(feature = "file_key_value_store")]
ProductOSKeyValueStorage::File(store) => store.set_group_type(group_type),
_ => panic!("Key value store kind not currently supported")
}
}
pub fn group_get(&self, key: &str) -> Result<String, ProductOSStoreError> {
match &self.store {
#[cfg(feature = "redis_key_value_store")]
ProductOSKeyValueStorage::Redis(store) => store.group_get(key),
ProductOSKeyValueStorage::Sink(store) => store.group_get(key),
#[cfg(feature = "memory_key_value_store")]
ProductOSKeyValueStorage::Memory(store) => store.group_get(key),
#[cfg(feature = "file_key_value_store")]
ProductOSKeyValueStorage::File(store) => store.group_get(key),
_ => panic!("Key value store kind not currently supported")
}
}
pub fn group_set(&self, key: &str, value: &str) -> Result<(), ProductOSStoreError> {
match &self.store {
#[cfg(feature = "redis_key_value_store")]
ProductOSKeyValueStorage::Redis(store) => store.group_set(key, value),
ProductOSKeyValueStorage::Sink(store) => store.group_set(key, value),
#[cfg(feature = "memory_key_value_store")]
ProductOSKeyValueStorage::Memory(store) => store.group_set(key, value),
#[cfg(feature = "file_key_value_store")]
ProductOSKeyValueStorage::File(store) => store.group_set(key, value),
_ => panic!("Key value store kind not currently supported")
}
}
pub fn group_remove(&self, key: &str) -> Result<(), ProductOSStoreError> {
match &self.store {
#[cfg(feature = "redis_key_value_store")]
ProductOSKeyValueStorage::Redis(store) => store.group_remove(key),
ProductOSKeyValueStorage::Sink(store) => store.group_remove(key),
#[cfg(feature = "memory_key_value_store")]
ProductOSKeyValueStorage::Memory(store) => store.group_remove(key),
#[cfg(feature = "file_key_value_store")]
ProductOSKeyValueStorage::File(store) => store.group_remove(key),
_ => panic!("Key value store kind not currently supported")
}
}
pub fn group_find(&self, query: Option<&str>) -> Result<BTreeMap<String, String>, ProductOSStoreError> {
match &self.store {
#[cfg(feature = "redis_key_value_store")]
ProductOSKeyValueStorage::Redis(store) => store.group_find(query),
ProductOSKeyValueStorage::Sink(store) => store.group_find(query),
#[cfg(feature = "memory_key_value_store")]
ProductOSKeyValueStorage::Memory(store) => store.group_find(query),
#[cfg(feature = "file_key_value_store")]
ProductOSKeyValueStorage::File(store) => store.group_find(query),
_ => panic!("Key value store kind not currently supported")
}
}
pub fn group_specific_get(&self, key: &str, group: &str) -> Result<String, ProductOSStoreError> {
match &self.store {
#[cfg(feature = "redis_key_value_store")]
ProductOSKeyValueStorage::Redis(store) => store.group_specific_get(key, group),
ProductOSKeyValueStorage::Sink(store) => store.group_specific_get(key, group),
#[cfg(feature = "memory_key_value_store")]
ProductOSKeyValueStorage::Memory(store) => store.group_specific_get(key, group),
#[cfg(feature = "file_key_value_store")]
ProductOSKeyValueStorage::File(store) => store.group_specific_get(key, group),
_ => panic!("Key value store kind not currently supported")
}
}
pub fn group_specific_set(&self, key: &str, value: &str, group: &str) -> Result<(), ProductOSStoreError> {
match &self.store {
#[cfg(feature = "redis_key_value_store")]
ProductOSKeyValueStorage::Redis(store) => store.group_specific_set(key, value, group),
ProductOSKeyValueStorage::Sink(store) => store.group_specific_set(key, value, group),
#[cfg(feature = "memory_key_value_store")]
ProductOSKeyValueStorage::Memory(store) => store.group_specific_set(key, value, group),
#[cfg(feature = "file_key_value_store")]
ProductOSKeyValueStorage::File(store) => store.group_specific_set(key, value, group),
_ => panic!("Key value store kind not currently supported")
}
}
pub fn group_specific_remove(&self, key: &str, group: &str) -> Result<(), ProductOSStoreError> {
match &self.store {
#[cfg(feature = "redis_key_value_store")]
ProductOSKeyValueStorage::Redis(store) => store.group_specific_remove(key, group),
ProductOSKeyValueStorage::Sink(store) => store.group_specific_remove(key, group),
#[cfg(feature = "memory_key_value_store")]
ProductOSKeyValueStorage::Memory(store) => store.group_specific_remove(key, group),
#[cfg(feature = "file_key_value_store")]
ProductOSKeyValueStorage::File(store) => store.group_specific_remove(key, group),
_ => panic!("Key value store kind not currently supported")
}
}
pub fn group_specific_find(&self, query: Option<&str>, group: &str) -> Result<BTreeMap<String, String>, ProductOSStoreError> {
match &self.store {
#[cfg(feature = "redis_key_value_store")]
ProductOSKeyValueStorage::Redis(store) => store.group_specific_find(query, group),
ProductOSKeyValueStorage::Sink(store) => store.group_specific_find(query, group),
#[cfg(feature = "memory_key_value_store")]
ProductOSKeyValueStorage::Memory(store) => store.group_specific_find(query, group),
#[cfg(feature = "file_key_value_store")]
ProductOSKeyValueStorage::File(store) => store.group_specific_find(query, group),
_ => panic!("Key value store kind not currently supported")
}
}
}
#[cfg(feature = "queue_store")]
pub enum ProductOSQueueStorageType {
Redis,
Memory,
File,
Sink
}
#[cfg(feature = "queue_store")]
pub enum ProductOSQueueStorage {
#[cfg(feature = "redis_queue_store")]
Redis(ProductOSRedisQueueStore),
Sink(ProductOSSinkQueueStore),
#[cfg(feature = "memory_queue_store")]
Memory(ProductOSMemoryQueueStore),
#[cfg(feature = "file_queue_store")]
File(ProductOSFileQueueStore)
}
#[cfg(feature = "queue_store")]
pub struct ProductOSQueueStore {
store: ProductOSQueueStorage
}
#[cfg(feature = "queue_store")]
impl ProductOSQueueStore {
pub fn new(config: &product_os_configuration::QueueStore) -> Self {
match config.kind {
#[cfg(feature = "redis_queue_store")]
QueueKind::Redis => Self {
store: ProductOSQueueStorage::Redis(ProductOSRedisQueueStore::new(config))
},
QueueKind::Sink => Self {
store: ProductOSQueueStorage::Sink(ProductOSSinkQueueStore::new(config))
},
#[cfg(feature = "memory_queue_store")]
QueueKind::Memory => Self {
store: ProductOSQueueStorage::Memory(ProductOSMemoryQueueStore::new(config))
},
#[cfg(feature = "file_queue_store")]
QueueKind::File => Self {
store: ProductOSQueueStorage::File(ProductOSFileQueueStore::new(config))
},
_ => panic!("Queue kind module not loaded: {:?}", config.kind)
}
}
pub fn connect(&mut self) -> Result<(), ProductOSStoreError> {
match &mut self.store {
#[cfg(feature = "redis_queue_store")]
ProductOSQueueStorage::Redis(store) => store.connect(),
ProductOSQueueStorage::Sink(store) => store.connect(),
#[cfg(feature = "memory_queue_store")]
ProductOSQueueStorage::Memory(store) => store.connect(),
#[cfg(feature = "file_queue_store")]
ProductOSQueueStorage::File(store) => store.connect()
}
}
pub fn disconnect(&mut self) -> Result<(), ProductOSStoreError> {
match &mut self.store {
#[cfg(feature = "redis_queue_store")]
ProductOSQueueStorage::Redis(store) => store.disconnect(),
ProductOSQueueStorage::Sink(store) => store.disconnect(),
#[cfg(feature = "memory_queue_store")]
ProductOSQueueStorage::Memory(store) => store.disconnect(),
#[cfg(feature = "file_queue_store")]
ProductOSQueueStorage::File(store) => store.disconnect()
}
}
pub fn set_queue(&mut self, queue: &str) {
match &mut self.store {
#[cfg(feature = "redis_queue_store")]
ProductOSQueueStorage::Redis(store) => store.set_queue(queue),
ProductOSQueueStorage::Sink(store) => store.set_queue(queue),
#[cfg(feature = "memory_queue_store")]
ProductOSQueueStorage::Memory(store) => store.set_queue(queue),
#[cfg(feature = "file_queue_store")]
ProductOSQueueStorage::File(store) => store.set_queue(queue)
}
}
pub fn set_queue_type(&mut self, queue_type: &str) {
match &mut self.store {
#[cfg(feature = "redis_queue_store")]
ProductOSQueueStorage::Redis(store) => store.set_queue_type(queue_type),
ProductOSQueueStorage::Sink(store) => store.set_queue_type(queue_type),
#[cfg(feature = "memory_queue_store")]
ProductOSQueueStorage::Memory(store) => store.set_queue_type(queue_type),
#[cfg(feature = "file_queue_store")]
ProductOSQueueStorage::File(store) => store.set_queue_type(queue_type)
}
}
pub fn queue_push(&self, value: &str) -> Result<(), ProductOSStoreError> {
match &self.store {
#[cfg(feature = "redis_queue_store")]
ProductOSQueueStorage::Redis(store) => store.queue_push(value),
ProductOSQueueStorage::Sink(store) => store.queue_push(value),
#[cfg(feature = "memory_queue_store")]
ProductOSQueueStorage::Memory(store) => store.queue_push(value),
#[cfg(feature = "file_queue_store")]
ProductOSQueueStorage::File(store) => store.queue_push(value)
}
}
pub fn queue_insert(&self, position: u64, value: &str) -> Result<(), ProductOSStoreError> {
match &self.store {
#[cfg(feature = "redis_queue_store")]
ProductOSQueueStorage::Redis(store) => store.queue_insert(position, value),
ProductOSQueueStorage::Sink(store) => store.queue_insert(position, value),
#[cfg(feature = "memory_queue_store")]
ProductOSQueueStorage::Memory(store) => store.queue_insert(position, value),
#[cfg(feature = "file_queue_store")]
ProductOSQueueStorage::File(store) => store.queue_insert(position, value)
}
}
pub fn queue_remove(&self) -> Result<String, ProductOSStoreError> {
match &self.store {
#[cfg(feature = "redis_queue_store")]
ProductOSQueueStorage::Redis(store) => store.queue_remove(),
ProductOSQueueStorage::Sink(store) => store.queue_remove(),
#[cfg(feature = "memory_queue_store")]
ProductOSQueueStorage::Memory(store) => store.queue_remove(),
#[cfg(feature = "file_queue_store")]
ProductOSQueueStorage::File(store) => store.queue_remove()
}
}
pub fn queue_pop(&self) -> Result<String, ProductOSStoreError> {
match &self.store {
#[cfg(feature = "redis_queue_store")]
ProductOSQueueStorage::Redis(store) => store.queue_pop(),
ProductOSQueueStorage::Sink(store) => store.queue_pop(),
#[cfg(feature = "memory_queue_store")]
ProductOSQueueStorage::Memory(store) => store.queue_pop(),
#[cfg(feature = "file_queue_store")]
ProductOSQueueStorage::File(store) => store.queue_pop()
}
}
pub fn queue_specific_push(&self, value: &str, queue: &str) -> Result<(), ProductOSStoreError> {
match &self.store {
#[cfg(feature = "redis_queue_store")]
ProductOSQueueStorage::Redis(store) => store.queue_specific_push(value, queue),
ProductOSQueueStorage::Sink(store) => store.queue_specific_push(value, queue),
#[cfg(feature = "memory_queue_store")]
ProductOSQueueStorage::Memory(store) => store.queue_specific_push(value, queue),
#[cfg(feature = "file_queue_store")]
ProductOSQueueStorage::File(store) => store.queue_specific_push(value, queue)
}
}
pub fn queue_specific_insert(&self, position: u64, value: &str, queue: &str) -> Result<(), ProductOSStoreError> {
match &self.store {
#[cfg(feature = "redis_queue_store")]
ProductOSQueueStorage::Redis(store) => store.queue_specific_insert(position, value, queue),
ProductOSQueueStorage::Sink(store) => store.queue_specific_insert(position, value, queue),
#[cfg(feature = "memory_queue_store")]
ProductOSQueueStorage::Memory(store) => store.queue_specific_insert(position, value, queue),
#[cfg(feature = "file_queue_store")]
ProductOSQueueStorage::File(store) => store.queue_specific_insert(position, value, queue)
}
}
pub fn queue_specific_remove(&self, queue: &str) -> Result<String, ProductOSStoreError> {
match &self.store {
#[cfg(feature = "redis_queue_store")]
ProductOSQueueStorage::Redis(store) => store.queue_specific_remove(queue),
ProductOSQueueStorage::Sink(store) => store.queue_specific_remove(queue),
#[cfg(feature = "memory_queue_store")]
ProductOSQueueStorage::Memory(store) => store.queue_specific_remove(queue),
#[cfg(feature = "file_queue_store")]
ProductOSQueueStorage::File(store) => store.queue_specific_remove(queue)
}
}
pub fn queue_specific_pop(&self, queue: &str) -> Result<String, ProductOSStoreError> {
match &self.store {
#[cfg(feature = "redis_queue_store")]
ProductOSQueueStorage::Redis(store) => store.queue_specific_pop(queue),
ProductOSQueueStorage::Sink(store) => store.queue_specific_pop(queue),
#[cfg(feature = "memory_queue_store")]
ProductOSQueueStorage::Memory(store) => store.queue_specific_pop(queue),
#[cfg(feature = "file_queue_store")]
ProductOSQueueStorage::File(store) => store.queue_specific_pop(queue)
}
}
}
#[cfg(feature = "relational_store")]
pub enum ProductOSRelationalStorageType {
Postgres,
Sqlite,
Sink
}
#[cfg(feature = "relational_store")]
pub enum ProductOSRelationalStorage {
#[cfg(feature = "postgres_relational_store")]
Postgres(ProductOSPostgresRelationalStore<Postgres>),
#[cfg(feature = "sqlite_relational_store")]
Sqlite(ProductOSSqliteRelationalStore<Sqlite>),
Sink(ProductOSSinkRelationalStore)
}
#[cfg(feature = "relational_store")]
pub struct ProductOSRelationalStore {
store: ProductOSRelationalStorage
}
#[cfg(feature = "relational_store")]
impl ProductOSRelationalStore {
pub fn new(config: &product_os_configuration::RelationalStore) -> Self {
match config.kind {
#[cfg(feature = "postgres_relational_store")]
RelationalKind::Postgres => Self {
store: ProductOSRelationalStorage::Postgres(ProductOSPostgresRelationalStore::new(config))
},
#[cfg(feature = "sqlite_relational_store")]
RelationalKind::Sqlite => Self {
store: ProductOSRelationalStorage::Sqlite(ProductOSSqliteRelationalStore::new(config))
},
RelationalKind::Sink => Self {
store: ProductOSRelationalStorage::Sink(ProductOSSinkRelationalStore::new(config))
},
_ => panic!("Relational store kind not currently supported")
}
}
pub async fn connect(&mut self) -> Result<(), ProductOSStoreError> {
match &mut self.store {
#[cfg(feature = "postgres_relational_store")]
ProductOSRelationalStorage::Postgres(store) => store.connect().await,
#[cfg(feature = "sqlite_relational_store")]
ProductOSRelationalStorage::Sqlite(store) => store.connect().await,
ProductOSRelationalStorage::Sink(store) => store.connect().await,
_ => panic!("Relational store kind not currently supported")
}
}
pub fn connect_sync(&mut self) -> Result<(), ProductOSStoreError> {
match &mut self.store {
#[cfg(feature = "postgres_relational_store")]
ProductOSRelationalStorage::Postgres(store) => store.connect_sync(),
#[cfg(feature = "sqlite_relational_store")]
ProductOSRelationalStorage::Sqlite(store) => store.connect_sync(),
ProductOSRelationalStorage::Sink(store) => store.connect_sync(),
_ => panic!("Relational store kind not currently supported")
}
}
pub async fn disconnect(&mut self) -> Result<(), ProductOSStoreError> {
match &mut self.store {
#[cfg(feature = "postgres_relational_store")]
ProductOSRelationalStorage::Postgres(store) => store.disconnect().await,
#[cfg(feature = "sqlite_relational_store")]
ProductOSRelationalStorage::Sqlite(store) => store.disconnect().await,
ProductOSRelationalStorage::Sink(store) => store.disconnect().await,
_ => panic!("Relational store kind not currently supported")
}
}
pub async fn get_one_raw(&self, query: &str) -> Result<Option<RelationalRow>, ProductOSStoreError> {
match &self.store {
#[cfg(feature = "postgres_relational_store")]
ProductOSRelationalStorage::Postgres(store) => store.get_one_raw(query).await,
#[cfg(feature = "sqlite_relational_store")]
ProductOSRelationalStorage::Sqlite(store) => store.get_one_raw(query).await,
ProductOSRelationalStorage::Sink(store) => store.get_one_raw(query).await,
_ => panic!("Relational store kind not currently supported")
}
}
pub async fn get_all_raw(&self, query: &str) -> Result<Vec<RelationalRow>, ProductOSStoreError> {
match &self.store {
#[cfg(feature = "postgres_relational_store")]
ProductOSRelationalStorage::Postgres(store) => store.get_all_raw(query).await,
#[cfg(feature = "sqlite_relational_store")]
ProductOSRelationalStorage::Sqlite(store) => store.get_all_raw(query).await,
ProductOSRelationalStorage::Sink(store) => store.get_all_raw(query).await,
_ => panic!("Relational store kind not currently supported")
}
}
pub async fn get_raw(&self, query: &str) -> Result<Vec<RelationalRow>, ProductOSStoreError> {
match &self.store {
#[cfg(feature = "postgres_relational_store")]
ProductOSRelationalStorage::Postgres(store) => store.get_raw(query).await,
#[cfg(feature = "sqlite_relational_store")]
ProductOSRelationalStorage::Sqlite(store) => store.get_raw(query).await,
ProductOSRelationalStorage::Sink(store) => store.get_raw(query).await,
_ => panic!("Relational store kind not currently supported")
}
}
pub async fn execute_raw(&self, instruction: &str) -> Result<RelationalResult, ProductOSStoreError> {
match &self.store {
#[cfg(feature = "postgres_relational_store")]
ProductOSRelationalStorage::Postgres(store) => store.execute_raw(instruction).await,
#[cfg(feature = "sqlite_relational_store")]
ProductOSRelationalStorage::Sqlite(store) => store.execute_raw(instruction).await,
ProductOSRelationalStorage::Sink(store) => store.execute_raw(instruction).await,
_ => panic!("Relational store kind not currently supported")
}
}
pub async fn transaction_raw(&self, instructions: Vec<String>) -> Result<Vec<RelationalResult>, ProductOSStoreError> {
match &self.store {
#[cfg(feature = "postgres_relational_store")]
ProductOSRelationalStorage::Postgres(store) => store.transaction_raw(instructions).await,
#[cfg(feature = "sqlite_relational_store")]
ProductOSRelationalStorage::Sqlite(store) => store.transaction_raw(instructions).await,
ProductOSRelationalStorage::Sink(store) => store.transaction_raw(instructions).await,
_ => panic!("Relational store kind not currently supported")
}
}
pub async fn transaction(&self, instructions: Vec<Instruction>) -> Result<Vec<RelationalResult>, ProductOSStoreError> {
match &self.store {
#[cfg(feature = "postgres_relational_store")]
ProductOSRelationalStorage::Postgres(store) => store.transaction(instructions).await,
#[cfg(feature = "sqlite_relational_store")]
ProductOSRelationalStorage::Sqlite(store) => store.transaction(instructions).await,
ProductOSRelationalStorage::Sink(store) => store.transaction(instructions).await,
_ => panic!("Relational store kind not currently supported")
}
}
#[cfg(any(feature = "postgres_relational_store", feature = "sqlite_relational_store"))]
pub async fn transaction_manual_raw(&self, txn: &mut RelationalTransaction<'_>, instructions: Vec<String>) -> Result<Vec<RelationalResult>, ProductOSStoreError> {
match &self.store {
#[cfg(feature = "postgres_relational_store")]
ProductOSRelationalStorage::Postgres(store) => store.transaction_manual_raw(txn, instructions).await,
#[cfg(feature = "sqlite_relational_store")]
ProductOSRelationalStorage::Sqlite(store) => store.transaction_manual_raw(txn, instructions).await,
ProductOSRelationalStorage::Sink(store) => store.transaction_manual_raw(txn, instructions).await,
_ => panic!("Relational store kind not currently supported")
}
}
#[cfg(not(any(feature = "postgres_relational_store", feature = "sqlite_relational_store")))]
pub async fn transaction_manual_raw(&self, txn: &mut RelationalTransaction, instructions: Vec<String>) -> Result<Vec<RelationalResult>, ProductOSStoreError> {
match &self.store {
ProductOSRelationalStorage::Sink(store) => store.transaction_manual_raw(txn, instructions).await,
_ => panic!("Relational store kind not currently supported")
}
}
#[cfg(any(feature = "postgres_relational_store", feature = "sqlite_relational_store"))]
pub async fn transaction_manual(&self, txn: &mut RelationalTransaction<'_>, instructions: Vec<Instruction>) -> Result<Vec<RelationalResult>, ProductOSStoreError> {
match &self.store {
#[cfg(feature = "postgres_relational_store")]
ProductOSRelationalStorage::Postgres(store) => store.transaction_manual(txn, instructions).await,
#[cfg(feature = "sqlite_relational_store")]
ProductOSRelationalStorage::Sqlite(store) => store.transaction_manual(txn, instructions).await,
ProductOSRelationalStorage::Sink(store) => store.transaction_manual(txn, instructions).await,
_ => panic!("Relational store kind not currently supported")
}
}
#[cfg(not(any(feature = "postgres_relational_store", feature = "sqlite_relational_store")))]
pub async fn transaction_manual(&self, txn: &mut RelationalTransaction, instructions: Vec<Instruction>) -> Result<Vec<RelationalResult>, ProductOSStoreError> {
match &self.store {
ProductOSRelationalStorage::Sink(store) => store.transaction_manual(txn, instructions).await,
_ => panic!("Relational store kind not currently supported")
}
}
pub async fn get_one<IRO>(&self, query: Query) -> Result<Option<IRO>, ProductOSStoreError>
where
IRO: ProductOSRelationalObject + Default
{
match &self.store {
#[cfg(feature = "postgres_relational_store")]
ProductOSRelationalStorage::Postgres(store) => store.get_one(query).await,
#[cfg(feature = "sqlite_relational_store")]
ProductOSRelationalStorage::Sqlite(store) => store.get_one(query).await,
ProductOSRelationalStorage::Sink(store) => store.get_one(query).await,
_ => panic!("Relational store kind not currently supported")
}
}
pub async fn get_one_specific(&self, query: Query) -> Result<Option<RelationalRow>, ProductOSStoreError> {
match &self.store {
#[cfg(feature = "postgres_relational_store")]
ProductOSRelationalStorage::Postgres(store) => store.get_one_specific(query).await,
#[cfg(feature = "sqlite_relational_store")]
ProductOSRelationalStorage::Sqlite(store) => store.get_one_specific(query).await,
ProductOSRelationalStorage::Sink(store) => store.get_one_specific(query).await,
_ => panic!("Relational store kind not currently supported")
}
}
pub async fn get_all<IRO>(&self, query: Query) -> Result<Vec<IRO>, ProductOSStoreError>
where
IRO: ProductOSRelationalObject + Default
{
match &self.store {
#[cfg(feature = "postgres_relational_store")]
ProductOSRelationalStorage::Postgres(store) => store.get_all(query).await,
#[cfg(feature = "sqlite_relational_store")]
ProductOSRelationalStorage::Sqlite(store) => store.get_all(query).await,
ProductOSRelationalStorage::Sink(store) => store.get_all(query).await,
_ => panic!("Relational store kind not currently supported")
}
}
pub async fn get_all_specific(&self, query: Query) -> Result<Vec<RelationalRow>, ProductOSStoreError> {
match &self.store {
#[cfg(feature = "postgres_relational_store")]
ProductOSRelationalStorage::Postgres(store) => store.get_all_specific(query).await,
#[cfg(feature = "sqlite_relational_store")]
ProductOSRelationalStorage::Sqlite(store) => store.get_all_specific(query).await,
ProductOSRelationalStorage::Sink(store) => store.get_all_specific(query).await,
_ => panic!("Relational store kind not currently supported")
}
}
pub async fn count(&self, query: Query, identifier_name: String) -> Result<i64, ProductOSStoreError> {
match &self.store {
#[cfg(feature = "postgres_relational_store")]
ProductOSRelationalStorage::Postgres(store) => store.count(query, identifier_name).await,
#[cfg(feature = "sqlite_relational_store")]
ProductOSRelationalStorage::Sqlite(store) => store.count(query, identifier_name).await,
ProductOSRelationalStorage::Sink(store) => store.count(query, identifier_name).await,
_ => panic!("Relational store kind not currently supported")
}
}
pub async fn execute(&self, instruction: Instruction) -> Result<RelationalResult, ProductOSStoreError> {
match &self.store {
#[cfg(feature = "postgres_relational_store")]
ProductOSRelationalStorage::Postgres(store) => store.execute(instruction).await,
#[cfg(feature = "sqlite_relational_store")]
ProductOSRelationalStorage::Sqlite(store) => store.execute(instruction).await,
ProductOSRelationalStorage::Sink(store) => store.execute(instruction).await,
_ => panic!("Relational store kind not currently supported")
}
}
pub async fn create(&self, instruction: Instruction) -> Result<RelationalResult, ProductOSStoreError> {
match &self.store {
#[cfg(feature = "postgres_relational_store")]
ProductOSRelationalStorage::Postgres(store) => store.create(instruction).await,
#[cfg(feature = "sqlite_relational_store")]
ProductOSRelationalStorage::Sqlite(store) => store.create(instruction).await,
ProductOSRelationalStorage::Sink(store) => store.create(instruction).await,
_ => panic!("Relational store kind not currently supported")
}
}
pub async fn alter(&self, instruction: Instruction) -> Result<RelationalResult, ProductOSStoreError> {
match &self.store {
#[cfg(feature = "postgres_relational_store")]
ProductOSRelationalStorage::Postgres(store) => store.alter(instruction).await,
#[cfg(feature = "sqlite_relational_store")]
ProductOSRelationalStorage::Sqlite(store) => store.alter(instruction).await,
ProductOSRelationalStorage::Sink(store) => store.alter(instruction).await,
_ => panic!("Relational store kind not currently supported")
}
}
pub async fn drop(&self, instruction: Instruction) -> Result<RelationalResult, ProductOSStoreError> {
match &self.store {
#[cfg(feature = "postgres_relational_store")]
ProductOSRelationalStorage::Postgres(store) => store.drop(instruction).await,
#[cfg(feature = "sqlite_relational_store")]
ProductOSRelationalStorage::Sqlite(store) => store.drop(instruction).await,
ProductOSRelationalStorage::Sink(store) => store.drop(instruction).await,
_ => panic!("Relational store kind not currently supported")
}
}
pub async fn insert(&self, instruction: Instruction) -> Result<RelationalResult, ProductOSStoreError> {
match &self.store {
#[cfg(feature = "postgres_relational_store")]
ProductOSRelationalStorage::Postgres(store) => store.insert(instruction).await,
#[cfg(feature = "sqlite_relational_store")]
ProductOSRelationalStorage::Sqlite(store) => store.insert(instruction).await,
ProductOSRelationalStorage::Sink(store) => store.insert(instruction).await,
_ => panic!("Relational store kind not currently supported")
}
}
pub async fn update(&self, instruction: Instruction) -> Result<RelationalResult, ProductOSStoreError> {
match &self.store {
#[cfg(feature = "postgres_relational_store")]
ProductOSRelationalStorage::Postgres(store) => store.update(instruction).await,
#[cfg(feature = "sqlite_relational_store")]
ProductOSRelationalStorage::Sqlite(store) => store.update(instruction).await,
ProductOSRelationalStorage::Sink(store) => store.update(instruction).await,
_ => panic!("Relational store kind not currently supported")
}
}
pub async fn upsert(&self, instruction: Instruction) -> Result<RelationalResult, ProductOSStoreError> {
match &self.store {
#[cfg(feature = "postgres_relational_store")]
ProductOSRelationalStorage::Postgres(store) => store.upsert(instruction).await,
#[cfg(feature = "sqlite_relational_store")]
ProductOSRelationalStorage::Sqlite(store) => store.upsert(instruction).await,
ProductOSRelationalStorage::Sink(store) => store.upsert(instruction).await,
_ => panic!("Relational store kind not currently supported")
}
}
pub async fn delete(&self, instruction: Instruction) -> Result<RelationalResult, ProductOSStoreError> {
match &self.store {
#[cfg(feature = "postgres_relational_store")]
ProductOSRelationalStorage::Postgres(store) => store.delete(instruction).await,
#[cfg(feature = "sqlite_relational_store")]
ProductOSRelationalStorage::Sqlite(store) => store.delete(instruction).await,
ProductOSRelationalStorage::Sink(store) => store.delete(instruction).await,
_ => panic!("Relational store kind not currently supported")
}
}
pub async fn index(&self, table: Option<String>) -> Result<RelationalResult, ProductOSStoreError> {
match &self.store {
#[cfg(feature = "postgres_relational_store")]
ProductOSRelationalStorage::Postgres(store) => store.index(table).await,
#[cfg(feature = "sqlite_relational_store")]
ProductOSRelationalStorage::Sqlite(store) => store.index(table).await,
ProductOSRelationalStorage::Sink(store) => store.index(table).await,
_ => panic!("Relational store kind not currently supported")
}
}
pub async fn total(&self, table: String) -> Result<i64, ProductOSStoreError> {
match &self.store {
#[cfg(feature = "postgres_relational_store")]
ProductOSRelationalStorage::Postgres(store) => store.total(table).await,
#[cfg(feature = "sqlite_relational_store")]
ProductOSRelationalStorage::Sqlite(store) => store.total(table).await,
ProductOSRelationalStorage::Sink(store) => store.total(table).await,
_ => panic!("Relational store kind not currently supported")
}
}
pub fn get_query(query: Query, relational_type: ProductOSRelationalStorageType) -> Result<String, ProductOSStoreError> {
process_query_to_string(query, &relational_type)
}
pub fn get_instruction(instruction: Instruction, relational_type: ProductOSRelationalStorageType) -> Result<String, ProductOSStoreError> {
process_instruction_to_string(instruction, &relational_type)
}
}