feat: codegen script to geenrate type aliases in adapters
This commit is contained in:
parent
5f5903e31b
commit
c296451401
1 changed files with 59 additions and 0 deletions
59
utils/adapter_type_gen.sh
Executable file
59
utils/adapter_type_gen.sh
Executable file
|
@ -0,0 +1,59 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
help() {
|
||||||
|
echo "Usage: adapter_type_gen.sh
|
||||||
|
<domain name with first letter in caps>
|
||||||
|
<aggregate struct name>"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
run() {
|
||||||
|
echo "
|
||||||
|
|
||||||
|
pub type $1$2CqrsExec = Arc<PostgresCqrs<$2>>;
|
||||||
|
pub type $1$2CqrsView = Arc<dyn ViewRepository<$2View, $2>>;
|
||||||
|
pub type Web$1$2CqrsView = Data<$1$2CqrsView>;
|
||||||
|
|
||||||
|
// struct
|
||||||
|
|
||||||
|
${2,,}: $1$2CqrsExec,
|
||||||
|
|
||||||
|
// trait impl
|
||||||
|
|
||||||
|
self.${2,,}.execute(aggregate_id, command.clone()).await?;
|
||||||
|
|
||||||
|
|
||||||
|
// $2_view.rs DB stuff
|
||||||
|
|
||||||
|
use crate::${1,,}::adapters::types::{$1$2CqrsExec, $1$2CqrsView};
|
||||||
|
use crate::${1,,}::application::services::$1ServicesObj;
|
||||||
|
|
||||||
|
pub fn init_cqrs(
|
||||||
|
db: $1DBPostgresAdapter,
|
||||||
|
services: $1ServicesObj,
|
||||||
|
) -> ($1$2CqrsExec, $1$2CqrsView) {
|
||||||
|
let queries: Vec<Box<dyn Query<$2>>> = vec![Box::new(db.clone())];
|
||||||
|
|
||||||
|
let pool = db.pool.clone();
|
||||||
|
|
||||||
|
(
|
||||||
|
std::sync::Arc::new(postgres_es::postgres_cqrs(pool.clone(), queries, services)),
|
||||||
|
std::sync::Arc::new(db.clone()),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if [ -z $1 ]
|
||||||
|
then
|
||||||
|
help
|
||||||
|
elif [ -z $2 ]
|
||||||
|
then
|
||||||
|
help
|
||||||
|
else
|
||||||
|
run $1 $2 $3 $4 | wl-copy
|
||||||
|
run $1 $2 $3 $4
|
||||||
|
fi
|
Loading…
Reference in a new issue