lib/enrichment_db.rb in enrichment_db-0.1.5 vs lib/enrichment_db.rb in enrichment_db-0.1.6

- old
+ new

@@ -1,7 +1,8 @@ require 'enrichment_db/error' require 'enrichment_db/version' +require 'enrichment_db/helper' module EnrichmentDb module_function class DatumModel @@ -22,10 +23,45 @@ end end end end + def self.by_id(table_name, id) + schema_name = self::DATABASE_NAME + uid_name = self::UID_NAME + puts "Finding object from #{table_name} with #{uid_name} = '#{id}'." + query = "SELECT * FROM #{schema_name}.#{table_name} where #{uid_name} = $1" + values = [id] + + result = EnrichmentDb.request(schema_name, query, values).collect do |record| + record + end + + format_result(result) + end + + def self.all(table_name, schema_name = nil) + schema_name = schema_name || self::DATABASE_NAME + puts "Finding all objects from #{table_name}" + query = "SELECT * FROM #{schema_name}.#{table_name}" + + result = EnrichmentDb.request(schema_name, query).collect do |record| + record + end + + format_result(result) + end + + def self.format_result(result) + if result.size > 0 + puts "Found #{result.size} object/s" + result + else + puts "Nothing found" + end + end + # Initializes a new Base object # # @param attrs [Hash] # @return [DatumModel] def initialize(attrs={}) @@ -33,8 +69,9 @@ end end end require 'enrichment_db/geo' +require 'enrichment_db/language' require 'enrichment_db/census' require 'datum' require 'db' \ No newline at end of file