Created
November 10, 2021 11:15
-
-
Save whatnext/825e0cd9aa814d384cc1786c8b625d5e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# module RedWrap: | |
use Red; | |
unit class RedWrap; | |
method set( Str $label ){ | |
my $table = $label; | |
$table = $.prefix ~ '::' ~ $label if $.prefix; | |
require ::($table); | |
$.table = $table; | |
return self; | |
} | |
method create( %p = %() ){ return self!do( 'create', %p ); } | |
method delete( %p = %() ){ return self!do( 'delete', %p ); } | |
method !do( $op, %p = %() ){ | |
require ::($.table); | |
my $resp; | |
$resp = ::($.table).HOW."$op"( ::($.table), |%p ); | |
return $resp; | |
} | |
method search( %p = %() ){ | |
require ::($.table); | |
my $rs = ::($.table).^all.grep({ self.match( $_, %p ) }); | |
return $rs; | |
} | |
method find( %p = %() ){ | |
my $rs = self.search( %p ); | |
return $rs[0]; | |
} | |
method find_or_create( %p = () ) { | |
my $param_r = $.find( %p ); | |
return $param_r; | |
} | |
# in a module the following method is called many times: | |
method write_output { | |
my $param_r = $.redwrap.set('Table1').find_or_create({ | |
sheet_id => %.index_ws<sheet_id>, | |
name => $param | |
}); | |
my $eqn_r = $.ess.redwrap.set('Table2').create({ | |
param_id => $param_r.id, | |
num_comps => @comps.elems | |
}); | |
for @comps -> $comp { | |
my $comp_r = $.ess.redwrap('Table1').find_or_create({ | |
sheet_id => %.index_ws<sheet_id>, | |
name => $comp | |
}); | |
$.ess.red.set('Table3').create({ | |
eqn_id => $eqn_r.id, | |
param_id => $comp_r.id | |
}); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment