-
Notifications
You must be signed in to change notification settings - Fork 4
PostgresSQL Usage
-
docker-compose exec web rails console
-
ex. User.all command in rails console will display all of the rows for the User table
irb(main):001:0> User.all
output below:
User Load (1.3ms) SELECT "users".* FROM "users" LIMIT
=> #<ActiveRecord::Relation #<User id: 1, email: "[email protected]", created_at: "2019-01-20 09:34:41", updated_at: "2018-01-20 09:34:41", username: "Joe@RLC", first_name: "Bob", last_name: "Domain", profile_photo: nil, interests: nil, is_admin: false>, #<User id: 2, email: "[email protected]", created_at: "2018-04-27 09:34:41", updated_at: "2018-04-27 09:34:41", username: "Bob@RLC", first_name: "Bob", last_name: "Domain", profile_photo: nil, interests: nil, is_admin: false>
-
irb(main):004:0> User.new
output below:
=> #<User id: nil, email: "", created_at: nil, updated_at: nil, username: nil, first_name: nil, last_name: nil, profile_photo: nil, interests: nil, is_admin: false>
-
irb(main):006:0> User.count
output below:
(0.6ms) SELECT COUNT(*) FROM "users"
=> 2
-
irb(main):006:0> User.find(2)
output below:
User Load(0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1
=> #<User id: 2, email: "[email protected]", created_at: "2019-01-20 09:34:41", updated_at: "2018-01-20 09:34:41", username: "Joe@RLC", first_name: "Bob", last_name: "Domain", profile_photo: nil, interests: nil, is_admin: false>