flexirecord 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/flexirecord-oldpg.rb.patch +75 -0
- data/lib/flexirecord-demo.rb +10 -1
- data/lib/flexirecord.rb +1 -1
- metadata +3 -2
| @@ -0,0 +1,75 @@ | |
| 1 | 
            +
            --- flexirecord.rb	2007-02-07 18:54:13.000000000 +0000
         | 
| 2 | 
            +
            +++ flexirecord-oldpg.rb	2007-02-08 12:05:49.000000000 +0000
         | 
| 3 | 
            +
            @@ -568,7 +568,7 @@
         | 
| 4 | 
            +
                     primary_columns = []
         | 
| 5 | 
            +
                     db_query('SELECT ' <<
         | 
| 6 | 
            +
                         '"pg_attribute"."attname", ' <<
         | 
| 7 | 
            +
            -            '"pg_constraint"."conkey" @> ARRAY["pg_attribute"."attnum"] AS "primary" ' <<
         | 
| 8 | 
            +
            +            '("pg_constraint"."conkey"[1] = "pg_attribute"."attnum" OR "pg_constraint"."conkey"[2] = "pg_attribute"."attnum" OR "pg_constraint"."conkey"[3] = "pg_attribute"."attnum" OR "pg_constraint"."conkey"[4] = "pg_attribute"."attnum" OR "pg_constraint"."conkey"[5] = "pg_attribute"."attnum" OR "pg_constraint"."conkey"[6] = "pg_attribute"."attnum" OR "pg_constraint"."conkey"[7] = "pg_attribute"."attnum" OR "pg_constraint"."conkey"[8] = "pg_attribute"."attnum") AS "primary" ' <<
         | 
| 9 | 
            +
                         'FROM "pg_attribute" ' <<
         | 
| 10 | 
            +
                         'JOIN "pg_class" ON "pg_attribute"."attrelid" = "pg_class"."oid" ' <<
         | 
| 11 | 
            +
                         'JOIN "pg_namespace" ON "pg_class"."relnamespace" = "pg_namespace"."oid" ' <<
         | 
| 12 | 
            +
            @@ -752,7 +752,7 @@
         | 
| 13 | 
            +
                     )
         | 
| 14 | 
            +
                   end
         | 
| 15 | 
            +
             
         | 
| 16 | 
            +
            -      # Adds a ManyToOneReference to the class (by simply creating it). The first argument is the destination class, followed by arguments being passed to Reference.new.
         | 
| 17 | 
            +
            +      # Adds a ManyToManyReference to the class (by simply creating it). The first argument is the destination class, followed by arguments being passed to Reference.new.
         | 
| 18 | 
            +
                   def add_many_to_one_reference(destination_class, *arguments)
         | 
| 19 | 
            +
                     return FlexiRecord::ManyToOneReference.new(
         | 
| 20 | 
            +
                       self, destination_class, *arguments
         | 
| 21 | 
            +
            @@ -985,16 +985,14 @@
         | 
| 22 | 
            +
                   def save
         | 
| 23 | 
            +
                     synchronize do
         | 
| 24 | 
            +
                       used_columns = self.used_columns
         | 
| 25 | 
            +
            -          primary_key = nil
         | 
| 26 | 
            +
                       if @saved
         | 
| 27 | 
            +
                         if self.class.primary_columns.empty?
         | 
| 28 | 
            +
                           raise "Can not re-save a record of a table without a primary key."
         | 
| 29 | 
            +
                         end
         | 
| 30 | 
            +
            -            primary_key = self.class.db_query1(
         | 
| 31 | 
            +
            +            self.class.db_execute(
         | 
| 32 | 
            +
                           'UPDATE ' << self.class.table <<
         | 
| 33 | 
            +
                           ' SET ' << (used_columns.collect { |column| '"' << column << '" = $' }.join(', ')) <<
         | 
| 34 | 
            +
            -              ' WHERE ' << (self.class.primary_columns.collect { |column| '"' << column << '" = $' }.join(' AND ')) <<
         | 
| 35 | 
            +
            -              ' RETURNING ' << (self.class.primary_columns.collect { |column| '"' << column << '"' }.join(', ')),
         | 
| 36 | 
            +
            +              ' WHERE ' << (self.class.primary_columns.collect { |column| '"' << column << '" = $' }.join(' AND ')),
         | 
| 37 | 
            +
                           *(
         | 
| 38 | 
            +
                             used_columns.collect { |column| read(column) } +
         | 
| 39 | 
            +
                             self.class.primary_columns.collect { |column| @old_primary_key[column] }
         | 
| 40 | 
            +
            @@ -1002,18 +1000,12 @@
         | 
| 41 | 
            +
                         )
         | 
| 42 | 
            +
                       else
         | 
| 43 | 
            +
                         if used_columns.empty?
         | 
| 44 | 
            +
            -              primary_key = self.class.db_query1('INSERT INTO ' << self.class.table << ' DEFAULT VALUES' <<
         | 
| 45 | 
            +
            -              (self.class.primary_columns.empty? ? '' : (
         | 
| 46 | 
            +
            -                ' RETURNING ' << (self.class.primary_columns.collect { |column| '"' << column << '"' }.join(', '))
         | 
| 47 | 
            +
            -              )))
         | 
| 48 | 
            +
            +              self.class.db_execute('INSERT INTO ' << self.class.table << ' DEFAULT VALUES')
         | 
| 49 | 
            +
                         else
         | 
| 50 | 
            +
            -              primary_key = self.class.db_query1(
         | 
| 51 | 
            +
            +              self.class.db_execute(
         | 
| 52 | 
            +
                             'INSERT INTO ' << self.class.table <<
         | 
| 53 | 
            +
                             ' (' << (used_columns.collect { |column| '"' << column << '"' }.join(', ')) << ')' <<
         | 
| 54 | 
            +
            -                ' VALUES (' << (used_columns.collect { |column| '$' }.join(', ')) << ')' <<
         | 
| 55 | 
            +
            -                (self.class.primary_columns.empty? ? '' : (
         | 
| 56 | 
            +
            -                  ' RETURNING ' << (self.class.primary_columns.collect { |column| '"' << column << '"' }.join(', '))
         | 
| 57 | 
            +
            -                )),
         | 
| 58 | 
            +
            +                ' VALUES (' << (used_columns.collect { |column| '$' }.join(', ')) << ')',
         | 
| 59 | 
            +
                             *(
         | 
| 60 | 
            +
                               used_columns.collect { |column| read(column) }
         | 
| 61 | 
            +
                             )
         | 
| 62 | 
            +
            @@ -1021,10 +1013,9 @@
         | 
| 63 | 
            +
                         end
         | 
| 64 | 
            +
                         @saved = true
         | 
| 65 | 
            +
                       end
         | 
| 66 | 
            +
            -          unless primary_key.nil?
         | 
| 67 | 
            +
            -            self.class.primary_columns.each do |column|
         | 
| 68 | 
            +
            -              self.set(column, primary_key.read(column))
         | 
| 69 | 
            +
            -            end
         | 
| 70 | 
            +
            +          if self.class.primary_columns == ['id'] and self.id.nil?
         | 
| 71 | 
            +
            +            primary_key = self.class.db_query1('SELECT lastval() AS "id"')
         | 
| 72 | 
            +
            +            self.id = primary_key.id
         | 
| 73 | 
            +
                       end
         | 
| 74 | 
            +
                       copy_primary_key
         | 
| 75 | 
            +
                       return self
         | 
    
        data/lib/flexirecord-demo.rb
    CHANGED
    
    | @@ -117,7 +117,8 @@ module FlexiRecordDemo | |
| 117 117 | 
             
                  MediumEntry.new(:medium => medium_b, :position => :last, :movie => koyaanisqatsi).save
         | 
| 118 118 | 
             
                  MediumEntry.new(:medium => medium_b, :position => :last, :movie => american_beauty).save
         | 
| 119 119 | 
             
                end
         | 
| 120 | 
            -
                Rating.new(:person => anja, :movie =>  | 
| 120 | 
            +
                Rating.new(:person => anja, :movie => american_beauty, :rating => Rational(7, 10)).save
         | 
| 121 | 
            +
                Rating.new(:person => anja, :movie => koyaanisqatsi, :rating => Rational(9,10)).save
         | 
| 121 122 | 
             
                Rating.new(:person => phillip, :movie => koyaanisqatsi, :rating => Rational(6,10)).save
         | 
| 122 123 | 
             
                Rating.new(:person => phillip, :movie => koyaanisqatsi, :rating => Rational(8,10)).save
         | 
| 123 124 | 
             
                Rating.new(:person => wilson, :movie => naruto, :comment => 'Rasengan!').save
         | 
| @@ -138,6 +139,14 @@ module FlexiRecordDemo | |
| 138 139 | 
             
                  puts "  - Rating: #{rating.rating ? rating.rating.to_s : 'none'}"
         | 
| 139 140 | 
             
                  puts "  - Comment: #{rating.comment || 'none'}"
         | 
| 140 141 | 
             
                end
         | 
| 142 | 
            +
                anjas = Person.select('WHERE "name" = $', 'Anja')
         | 
| 143 | 
            +
                if anjas.length == 1
         | 
| 144 | 
            +
                  anja = anjas.first
         | 
| 145 | 
            +
                  anjas_favourite = anja.rated_movies('WHERE "rel"."rating" NOTNULL ORDER BY "rel"."rating" DESC LIMIT 1').first
         | 
| 146 | 
            +
                  puts "The movie, which Anja likes most is: #{anjas_favourite ? anjas_favourite.name : 'N/A'}."
         | 
| 147 | 
            +
                else
         | 
| 148 | 
            +
                  puts "There is more than one person named Anja."
         | 
| 149 | 
            +
                end
         | 
| 141 150 | 
             
                nil
         | 
| 142 151 | 
             
              end
         | 
| 143 152 | 
             
              module_function :demo
         | 
    
        data/lib/flexirecord.rb
    CHANGED
    
    | @@ -752,7 +752,7 @@ module FlexiRecord | |
| 752 752 | 
             
                    )
         | 
| 753 753 | 
             
                  end
         | 
| 754 754 |  | 
| 755 | 
            -
                  # Adds a  | 
| 755 | 
            +
                  # Adds a ManyToOneReference to the class (by simply creating it). The first argument is the destination class, followed by arguments being passed to Reference.new.
         | 
| 756 756 | 
             
                  def add_many_to_one_reference(destination_class, *arguments)
         | 
| 757 757 | 
             
                    return FlexiRecord::ManyToOneReference.new(
         | 
| 758 758 | 
             
                      self, destination_class, *arguments
         | 
    
        metadata
    CHANGED
    
    | @@ -3,8 +3,8 @@ rubygems_version: 0.9.0 | |
| 3 3 | 
             
            specification_version: 1
         | 
| 4 4 | 
             
            name: flexirecord
         | 
| 5 5 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 6 | 
            -
              version: 0.0. | 
| 7 | 
            -
            date: 2007-02- | 
| 6 | 
            +
              version: 0.0.3
         | 
| 7 | 
            +
            date: 2007-02-08 00:00:00 +00:00
         | 
| 8 8 | 
             
            summary: Object-Oriented Database Access Library
         | 
| 9 9 | 
             
            require_paths: 
         | 
| 10 10 | 
             
            - lib/
         | 
| @@ -34,6 +34,7 @@ files: | |
| 34 34 | 
             
            - lib/flexirecord.rb
         | 
| 35 35 | 
             
            - lib/flexirecord-demo.rb
         | 
| 36 36 | 
             
            - ./flexirecord-demo.sql
         | 
| 37 | 
            +
            - flexirecord-oldpg.rb.patch
         | 
| 37 38 | 
             
            test_files: []
         | 
| 38 39 |  | 
| 39 40 | 
             
            rdoc_options: 
         |