You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
16 lines
375 B
16 lines
375 B
class Person
|
|
# connect to postgres
|
|
DB = PG.connect(host: "localhost", port: 5432, dbname: 'contacts')
|
|
|
|
def initialize(opts = {})
|
|
@id = opts["id"].to_i
|
|
@name = opts["name"]
|
|
@age = opts["age"]
|
|
end
|
|
|
|
def self.all
|
|
results = DB.exec("SELECT * FROM people;")
|
|
return results.map { |result| Person.new(result) }
|
|
end
|
|
end
|