Skip to content

Instantly share code, notes, and snippets.

@dLobatog
Created May 14, 2019 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dLobatog/63e0d6d4904511993c826ca66bfbf7a4 to your computer and use it in GitHub Desktop.
Save dLobatog/63e0d6d4904511993c826ca66bfbf7a4 to your computer and use it in GitHub Desktop.
[11] pry(main)> a = Host.new(id: SecureRandom.uuid, name: 'securerandom')
=> #<Host:0x0000564fdb674748
id: "7d9cc9e2-e962-48ff-a914-b9ad258d54f0",
name: "securerandom",
created_at: nil,
updated_at: nil,
account_id: nil>
[12] pry(main)> a.valid?
Host Exists (1.2ms) SELECT 1 AS one FROM "hosts" WHERE "hosts"."name" = $1 AND "hosts"."account_id" IS NULL LIMIT $2 [["name", "securerandom"], ["LIMIT", 1]]
=> true
[13] pry(main)> a.save
(0.7ms) BEGIN
Host Exists (2.4ms) SELECT 1 AS one FROM "hosts" WHERE "hosts"."name" = $1 AND "hosts"."account_id" IS NULL LIMIT $2 [["name", "securerandom"], ["LIMIT", 1]]
Host Create (3.6ms) INSERT INTO "hosts" ("id", "name", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["id", "7d9cc9e2-e962-48ff-a914-b9ad258d54f0"], ["name", "securerandom"], ["created_at", "2019-05-14 11:14:15.399753"], ["updated_at", "2019-05-14 11:14:15.399753"]]
(2.5ms) COMMIT
=> true
[14] pry(main)> a.id
=> "7d9cc9e2-e962-48ff-a914-b9ad258d54f0"
[15] pry(main)> b = Host.new(id: 'test', name: 'test')
=> #<Host:0x0000564fdbb857f0 id: nil, name: "test", created_at: nil, updated_at: nil, account_id: nil>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment