Skip to content

Instantly share code, notes, and snippets.

@schmurfy
Created August 29, 2013 14:04
Show Gist options
  • Save schmurfy/6378497 to your computer and use it in GitHub Desktop.
Save schmurfy/6378497 to your computer and use it in GitHub Desktop.
in memory DB
require 'active_record'
require 'sqlite3'
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => ':memory:'
)
ActiveRecord::Base.connection.instance_eval do
create_table :firstnames, :id => false do |t|
t.string :firstname
t.integer :age
end
add_index :firstnames, :firstname
end
class Firstnames < ActiveRecord::Base
end
Firstnames.create(firstname: 'john', age: 13)
Firstnames.create(firstname: 'julie', age: 20)
Firstnames.create(firstname: 'bob', age: 15)
p Firstnames.where("age > 5").order('age')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment