2 map $_->new(%$_, name => '_'.$_->name), @cols;
5 sub body_cols ($source) {
6 grep $_->name ne 'id', $source->all_cols;
9 my @pk_col = ($table->col('id'));
11 my @sources = grep defined, $table, $super_view;
13 my @body_cols = map body_cols($_), @sources;
15 CREATE VIEW $view_name =>
17 (map $_->qualify, @pk_col),
20 $super_view ? ($table->join($super_view)->using(@pk_col)) : $table
23 my ($now, $next) = grep defined, $super_view, $table;
25 CREATE FUNCTION "${view_name}_insert" =>
27 => RETURNS VOID => AS {
28 INSERT INTO { $now } (body_cols $now)
29 => VALUES (argify body_cols $now);
31 INSERT INTO { $next } ($next->all_cols)
33 $root_table->col('id')->sequence->currval,
34 argify body_cols $next
39 my $pk_eq = AND( map (expr { $_ == argify $_ }), @pk_col);
41 CREATE FUNCTION "${view_name}_update" =>
42 (argify @pk_col, @body_cols)
43 => RETURNS VOID => AS {
44 foreach my $s (@sources) {
45 UPDATE { $s } SET { map ($_ => argify $_), body_cols $s }
50 CREATE FUNCTION "${view_name}_delete" =>
52 => RETURNS VOID => AS {
53 foreach my $s (@sources) {
54 DELETE FROM { $s } WHERE { $pk_eq };