Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added #empty? to MySql2::Result #1003

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/mysql2/result.rb
Original file line number Diff line number Diff line change
@@ -2,6 +2,10 @@ module Mysql2
class Result
attr_reader :server_flags

def empty?
count.zero?
end

include Enumerable
end
end
13 changes: 13 additions & 0 deletions spec/mysql2/result_spec.rb
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@
r = @client.query "SELECT 1"
expect(r.count).to eql(1)
expect(r.size).to eql(1)
expect(r.empty?).to eq(false)
end

context "metadata queries" do
@@ -53,6 +54,18 @@
end
end

context "#empty?" do
it "should return true when result is not exists" do
r = @client.query "SELECT * FROM mysql2_test WHERE 0 = 1"
expect(r).to be_empty
end

it "should return false when result exists" do
r = @client.query "SELECT 1"
expect(r).not_to be_empty
end
end

context "#each" do
it "should yield rows as hash's" do
@result.each do |row|