Skip to content

Commit

Permalink
database
Browse files Browse the repository at this point in the history
  • Loading branch information
tianyicui committed Nov 14, 2010
1 parent 129d598 commit e594c0b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 10 additions & 2 deletions lib/minisql/record.rb
Expand Up @@ -49,8 +49,16 @@ def col_name_to_num name
end

def where_functor where
return lambda {|x| true}# if where==nil
raise "Not implemented"
return lambda {|x| true} if where==nil
lambda do |l|
where.each do |w|
v0 = l[col_name_to_num(w[1])]
v1 = w[2]
exp = "#{v0.inspect}#{w[0]}#{v1.inspect}"
return false unless eval(exp)
end
true
end
end

def serialize item
Expand Down
6 changes: 4 additions & 2 deletions spec/database_spec.rb
Expand Up @@ -105,11 +105,13 @@

it 'can delete specified data from table' do
insert_sample_data
insert_sample_data [0, 1.0, 'another one']
insert_sample_data [0, 1.0, 'another one ']
@db.delete_from :tbl do
column[:int_col] < 1
end
@db.select['*'].from(:tbl).to_a.should == [sample_data]
result = @db.select['*'].from(:tbl).to_a
result.size.should == 1
record_equal result[0], sample_data
end

end

0 comments on commit e594c0b

Please sign in to comment.