Make a model connect to Postgres

master
Matt Huntington 8 years ago
parent de856cbe55
commit 0e586ac470

@ -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 }

Loading…
Cancel
Save