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

undefined method `size' for an instance of Trilogy::Result #206

Closed
pasl opened this issue Nov 2, 2024 · 2 comments
Closed

undefined method `size' for an instance of Trilogy::Result #206

pasl opened this issue Nov 2, 2024 · 2 comments

Comments

@pasl
Copy link

pasl commented Nov 2, 2024

Hi,

I'm unsure if Trilogy is designed as a direct replacement for Mysql2 without compatibility issues, but I've encountered one.

undefined method `size' for an instance of Trilogy::Result

With MySQL2

> results = ActiveRecord::Base.connection.execute("select sn from products")
   (12.8ms)  select sn from products
 => 
#<Mysql2::Result:0x00000001623d13d8
... 
> results.size
 => 27706 
> results.count
 => 27706 

With Trilogy

> results = ActiveRecord::Base.connection.execute("select sn from products")
   (38.7ms)  select sn from products
 => 
#<Trilogy::Result:0x0000000127554f60
... 
> results.size
...gems/irb-1.14.0/lib/irb.rb:1285:in `full_message': undefined method `size' for an instance of Trilogy::Result (NoMethodError)

results.size
       ^^^^^
3.3.4 :003 > results.count
 => 27706 

I am using : trilogy (2.9.0) and mysql2 (0.5.6)

Thank you

nickborromeo added a commit to nickborromeo/trilogy that referenced this issue Nov 20, 2024
It was reported in trilogy-libraries#206 that `size` was not defined.

Looking at the mysql2 implementation `size` is just an alias to `count`

```
  rb_define_method(cMysql2Result, "count", rb_mysql_result_count, 0);
  rb_define_alias(cMysql2Result, "size", "count");
```

[source](https://github.com/brianmario/mysql2/blob/f6a9b68b42a51d1a370403f11eb88527dcb42dc6/ext/mysql2/result.c#L1241-L1242)

This adds an alias for `count` called `size`
@nickborromeo
Copy link
Contributor

It looks like in mysql2, size is an alias to count. I added this alias in #209. Let see what the maintainers say 🤞

@jhawthorn
Copy link
Member

I think it makes sense for us to add size but in general Trilogy does not intend to implement the methods mysql2 has 1:1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants