diff --git a/app/models/person.rb b/app/models/person.rb index 38bc5e2..a167c17 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -1,6 +1,13 @@ class Person - def self.all # a static function that's called on the class itself, not an instance - [ ## ruby functions return the last line of code, so no need for an explicit 'return' statement + # connect to postgres + DB = PG.connect(host: "localhost", port: 5432, dbname: 'contacts') + + def self.all + results = DB.exec("SELECT * FROM people;") + results.each do |result| + puts result + end + [ { name: 'Joey', age:12 }, { name: 'Sarah', age:52 }, { name: 'Cthulhu', age: 8000 }