--
-- Created by SQL::Translator::Producer::PostgreSQL
--- Created on Sat Apr 17 08:25:41 2010
+-- Created on Tue Jun 1 18:40:12 2010
--
--
-- Table: just_a_table
CREATE INDEX "_foo_idx_a" on "_foo" ("a");
--
--- View: "foo"
+-- View: "bar"
--
-DROP VIEW "foo";
-CREATE VIEW "foo" ( "id", "a" ) AS
- SELECT _foo.id, a FROM _foo;
+DROP VIEW "bar";
+CREATE VIEW "bar" ( "id", "a", "words", "b" ) AS
+ SELECT _bar.id, b, words, a FROM _bar _bar JOIN mixin mixin ON mixin.id = _bar.id JOIN foo foo ON foo.id = _bar.id;
-CREATE OR REPLACE FUNCTION foo_insert
- (_a INTEGER)
+CREATE OR REPLACE FUNCTION bar_insert
+ (_b INTEGER, _words TEXT, _a INTEGER)
RETURNS VOID AS $function$
BEGIN
- INSERT INTO _foo ( a) VALUES ( _a );
+ INSERT INTO foo ( a) VALUES ( _a );
+ INSERT INTO _bar ( b, id) VALUES ( _b, currval('_foo_id_seq') );
+ INSERT INTO mixin ( id, words) VALUES ( currval('_foo_id_seq'), _words );
END;
$function$ LANGUAGE plpgsql;
-CREATE OR REPLACE FUNCTION foo_update
- (_id INTEGER, _a INTEGER)
+CREATE OR REPLACE FUNCTION bar_update
+ (_id INTEGER, _b INTEGER, _words TEXT, _a INTEGER)
RETURNS VOID AS $function$
BEGIN
- UPDATE _foo SET a = _a WHERE ( id = _id );
+ UPDATE _bar SET b = _b WHERE ( id = _id );
+ UPDATE mixin SET words = _words WHERE ( id = _id );
+ UPDATE foo SET a = _a WHERE ( id = _id );
END;
$function$ LANGUAGE plpgsql;
-CREATE OR REPLACE FUNCTION foo_delete
+CREATE OR REPLACE FUNCTION bar_delete
(_id INTEGER)
RETURNS VOID AS $function$
BEGIN
- DELETE FROM _foo WHERE ( id = _id );
+ DELETE FROM _bar WHERE ( id = _id );
+ DELETE FROM mixin WHERE ( id = _id );
+ DELETE FROM foo WHERE ( id = _id );
END;
$function$ LANGUAGE plpgsql;
-CREATE RULE _foo_insert_rule AS
- ON INSERT TO foo
+CREATE RULE _bar_insert_rule AS
+ ON INSERT TO bar
DO INSTEAD (
- SELECT foo_insert(NEW.a)
+ SELECT bar_insert(NEW.b, NEW.words, NEW.a)
);
-CREATE RULE _foo_update_rule AS
- ON UPDATE TO foo
+CREATE RULE _bar_update_rule AS
+ ON UPDATE TO bar
DO INSTEAD (
- SELECT foo_update(OLD.id, NEW.a)
+ SELECT bar_update(OLD.id, NEW.b, NEW.words, NEW.a)
);
-CREATE RULE _foo_delete_rule AS
- ON DELETE TO foo
+CREATE RULE _bar_delete_rule AS
+ ON DELETE TO bar
DO INSTEAD (
- SELECT foo_delete(OLD.id)
+ SELECT bar_delete(OLD.id)
);
;
--
--- View: "bar"
+-- View: "foo"
--
-DROP VIEW "bar";
-CREATE VIEW "bar" ( "id", "a", "words", "b" ) AS
- SELECT _bar.id, b, words, a FROM _bar _bar JOIN mixin mixin ON mixin.id = _bar.id JOIN foo foo ON foo.id = _bar.id;
+DROP VIEW "foo";
+CREATE VIEW "foo" ( "id", "a" ) AS
+ SELECT _foo.id, a FROM _foo;
-CREATE OR REPLACE FUNCTION bar_insert
- (_b INTEGER, _words TEXT, _a INTEGER)
+CREATE OR REPLACE FUNCTION foo_insert
+ (_a INTEGER)
RETURNS VOID AS $function$
BEGIN
- INSERT INTO foo ( a) VALUES ( _a );
- INSERT INTO _bar ( b, id) VALUES ( _b, currval('_foo_id_seq') );
- INSERT INTO mixin ( id, words) VALUES ( currval('_foo_id_seq'), _words );
+ INSERT INTO _foo ( a) VALUES ( _a );
END;
$function$ LANGUAGE plpgsql;
-CREATE OR REPLACE FUNCTION bar_update
- (_id INTEGER, _b INTEGER, _words TEXT, _a INTEGER)
+CREATE OR REPLACE FUNCTION foo_update
+ (_id INTEGER, _a INTEGER)
RETURNS VOID AS $function$
BEGIN
- UPDATE _bar SET b = _b WHERE ( id = _id );
- UPDATE mixin SET words = _words WHERE ( id = _id );
- UPDATE foo SET a = _a WHERE ( id = _id );
+ UPDATE _foo SET a = _a WHERE ( id = _id );
END;
$function$ LANGUAGE plpgsql;
-CREATE OR REPLACE FUNCTION bar_delete
+CREATE OR REPLACE FUNCTION foo_delete
(_id INTEGER)
RETURNS VOID AS $function$
BEGIN
- DELETE FROM _bar WHERE ( id = _id );
- DELETE FROM mixin WHERE ( id = _id );
- DELETE FROM foo WHERE ( id = _id );
+ DELETE FROM _foo WHERE ( id = _id );
END;
$function$ LANGUAGE plpgsql;
-CREATE RULE _bar_insert_rule AS
- ON INSERT TO bar
+CREATE RULE _foo_insert_rule AS
+ ON INSERT TO foo
DO INSTEAD (
- SELECT bar_insert(NEW.b, NEW.words, NEW.a)
+ SELECT foo_insert(NEW.a)
);
-CREATE RULE _bar_update_rule AS
- ON UPDATE TO bar
+CREATE RULE _foo_update_rule AS
+ ON UPDATE TO foo
DO INSTEAD (
- SELECT bar_update(OLD.id, NEW.b, NEW.words, NEW.a)
+ SELECT foo_update(OLD.id, NEW.a)
);
-CREATE RULE _bar_delete_rule AS
- ON DELETE TO bar
+CREATE RULE _foo_delete_rule AS
+ ON DELETE TO foo
DO INSTEAD (
- SELECT bar_delete(OLD.id)
+ SELECT foo_delete(OLD.id)
);
;