Class: PgPartitions::SQL::Function

Inherits:
Struct
  • Object
show all
Defined in:
lib/pg_partitions/sql.rb

Direct Known Subclasses

DeleteFunction, InsertFunction

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bodyObject

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



40
41
42
# File 'lib/pg_partitions/sql.rb', line 40

def body
  @body
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



40
41
42
# File 'lib/pg_partitions/sql.rb', line 40

def name
  @name
end

#tableObject

Returns the value of attribute table

Returns:

  • (Object)

    the current value of table



40
41
42
# File 'lib/pg_partitions/sql.rb', line 40

def table
  @table
end

Instance Method Details

#to_sqlObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/pg_partitions/sql.rb', line 41

def to_sql
  <<~SQL
    CREATE OR REPLACE FUNCTION #{name}()
    RETURNS TRIGGER AS $$
    DECLARE
      result #{table}%rowtype;
    BEGIN
    #{body.indent(2)}
      RETURN result;
    END;
    $$
    LANGUAGE plpgsql;
  SQL
end