Skip to content

Instantly share code, notes, and snippets.

@theunraveler
Created June 8, 2015 22:36
Show Gist options
  • Select an option

  • Save theunraveler/366ba9c173003d106fdc to your computer and use it in GitHub Desktop.

Select an option

Save theunraveler/366ba9c173003d106fdc to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'pg'
end
conn = PG.connect( dbname: 'paranoia_null_unique' )
conn.exec('
CREATE TABLE IF NOT EXISTS testing (
token varchar(32) NOT NULL,
deleted_at timestamp,
UNIQUE(token, deleted_at)
)
')
conn.exec('DELETE FROM testing')
5.times { conn.exec("INSERT INTO testing (token) VALUES ('should_be_unique')") }
conn.exec('SELECT COUNT(*) FROM testing') do |result|
print "#{result.values.first.first} records!\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment