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

Sequel::Mysql2::Dataset problem with Sequel::Postgres::Database #1034

Closed
etagwerker opened this issue Jul 2, 2015 · 3 comments
Closed

Sequel::Mysql2::Dataset problem with Sequel::Postgres::Database #1034

etagwerker opened this issue Jul 2, 2015 · 3 comments

Comments

@etagwerker
Copy link

Hi,

I'm getting this error:

2015-07-02 13:40:29 - NoMethodError - undefined method `paginate' for #<Sequel::Mysql2::Dataset: "SELECT * FROM `questions`">:
    /Users/etagwerker/Projects/ombushop/lib/ayuda/models/question.rb:46:in `paginated'
    /Users/etagwerker/Projects/ombushop/lib/ayuda/lib/static.rb:10:in `block in <class:Static>'
    /Users/etagwerker/.rvm/gems/ruby-2.1.5@ombu/gems/sinatra-1.4.6/lib/sinatra/base.rb:1610:in `call'
    /Users/etagwerker/.rvm/gems/ruby-2.1.5@ombu/gems/sinatra-1.4.6/lib/sinatra/base.rb:1610:in `block in compile!'
    /Users/etagwerker/.rvm/gems/ruby-2.1.5@ombu/gems/sinatra-1.4.6/lib/sinatra/base.rb:974:in `[]'
    /Users/etagwerker/.rvm/gems/ruby-2.1.5@ombu/gems/sinatra-1.4.6/lib/sinatra/base.rb:974:in `block (3 levels) in route!'
    /Users/etagwerker/.rvm/gems/ruby-2.1.5@ombu/gems/sinatra-1.4.6/lib/sinatra/base.rb:993:in `route_eval'
    /Users/etagwerker/.rvm/gems/ruby-2.1.5@ombu/gems/sinatra-1.4.6/lib/sinatra/base.rb:974:in `block (2 levels) in route!'
    /Users/etagwerker/.rvm/gems/ruby-2.1.5@ombu/gems/sinatra-1.4.6/lib/sinatra/base.rb:1014:in `block in process_route'
    /Users/etagwerker/.rvm/gems/ruby-2.1.5@ombu/gems/sinatra-1.4.6/lib/sinatra/base.rb:1012:in `catch'
    /Users/etagwerker/.rvm/gems/ruby-2.1.5@ombu/gems/sinatra-1.4.6/lib/sinatra/base.rb:1012:in `process_route'
    /Users/etagwerker/.rvm/gems/ruby-2.1.5@ombu/gems/sinatra-1.4.6/lib/sinatra/base.rb:972:in `block in route!'
    /Users/etagwerker/.rvm/gems/ruby-2.1.5@ombu/gems/sinatra-1.4.6/lib/sinatra/base.rb:971:in `each'
    /Users/etagwerker/.rvm/gems/ruby-2.1.5@ombu/gems/sinatra-1.4.6/lib/sinatra/base.rb:971:in `route!'
    /Users/etagwerker/.rvm/gems/ruby-2.1.5@ombu/gems/sinatra-1.4.6/lib/sinatra/base.rb:1084:in `block in dispatch!'
    /Users/etagwerker/.rvm/gems/ruby-2.1.5@ombu/gems/sinatra-1.4.6/lib/sinatra/base.rb:1066:in `block in invoke'
    /Users/etagwerker/.rvm/gems/ruby-2.1.5@ombu/gems/sinatra-1.4.6/lib/sinatra/base.rb:1066:in `catch'
    /Users/etagwerker/.rvm/gems/ruby-2.1.5@ombu/gems/sinatra-1.4.6/lib/sinatra/base.rb:1066:in `invoke'
    /Users/etagwerker/.rvm/gems/ruby-2.1.5@ombu/gems/sinatra-1.4.6/lib/sinatra/base.rb:1081:in `dispatch!'
    /Users/etagwerker/.rvm/gems/ruby-2.1.5@ombu/gems/sinatra-1.4.6/lib/sinatra/base.rb:906:in `block in call!'
    /Users/etagwerker/.rvm/gems/ruby-2.1.5@ombu/gems/sinatra-1.4.6/lib/sinatra/base.rb:1066:in `block in invoke'
    /Users/etagwerker/.rvm/gems/ruby-2.1.5@ombu/gems/sinatra-1.4.6/lib/sinatra/base.rb:1066:in `catch'
    /Users/etagwerker/.rvm/gems/ruby-2.1.5@ombu/gems/sinatra-1.4.6/lib/sinatra/base.rb:1066:in `invoke'
    /Users/etagwerker/.rvm/gems/ruby-2.1.5@ombu/gems/sinatra-1.4.6/lib/sinatra/base.rb:906:in `call!'
    /Users/etagwerker/.rvm/gems/ruby-2.1.5@ombu/gems/sinatra-1.4.6/lib/sinatra/base.rb:894:in `call'
    /Users/etagwerker/.rvm/gems/ruby-2.1.5@ombu/gems/rack-flash3-1.0.5/lib/rack/flash.rb:124:in `call'
    /Users/etagwerker/.rvm/gems/ruby-2.1.5@ombu/gems/rack-1.4.7/lib/rack/methodoverride.rb:21:in `call'

The odd thing is that AFAIK it shouldn't be using Sequel::Mysql2::Dataset, it should be using Sequel::Postgres::Dataset.

This is how I'm connecting to the database:

require 'sinatra'
require 'haml'
require 'yaml'
require 'pg'
require 'sequel'
require 'sequel/adapters/postgres'
require 'sequel_pg'
require 'compass'
require 'sinatra/support/i18nsupport'

class Faqtly::App

    def self.connect
      hash = config
      url = "postgres://#{hash['username']}:"\
            "#{hash['password']}@#{hash['host']}:#{hash['port']}/"\
            "#{hash['database']}"
      Sequel.connect(url)
    end

end

DB = Faqtly::App.connect unless Object.const_defined?('DB')
DB.extension :pagination

I've checked that the URL is correct:

(byebug) DB
#<Sequel::Postgres::Database: "postgres://etagwerker:@127.0.0.1:5432/faqtly_development">

This is what my Gemfile.lock looks like:

PATH
  remote: .
  specs:
    faqtly (1.0)
      chronic
      compass (~> 0.12.0)
      grid-coordinates (~> 1.1.4)
      haml (~> 4.0.5)
      httparty (~> 0.8.1)
      i18n
      nokogiri (~> 1.5.0)
      pg (~> 0.13.2)
      rack-flash3
      rake (~> 0.9.2.2)
      sass (~> 3.2.19)
      sequel (~> 4.11.0)
      sequel_pg
      sinatra (~> 1.4.5)
      sinatra-support
      will_paginate (~> 3.0.5)

GEM
  remote: http://rubygems.org/
  specs:
    addressable (2.3.2)
    capybara (2.0.3)
      mime-types (>= 1.16)
      nokogiri (>= 1.3.3)
      rack (>= 1.0.0)
      rack-test (>= 0.5.4)
      selenium-webdriver (~> 2.0)
      xpath (~> 1.0.0)
    childprocess (0.3.9)
      ffi (~> 1.0, >= 1.0.11)
    chronic (0.10.2)
    chunky_png (1.3.1)
    coderay (1.0.9)
    compass (0.12.6)
      chunky_png (~> 1.2)
      fssm (>= 0.2.7)
      sass (~> 3.2.19)
    daemons (1.1.9)
    database_cleaner (0.9.1)
    eventmachine (1.0.3)
    excon (0.16.4)
    ffi (1.6.0)
    fssm (0.2.10)
    grid-coordinates (1.1.9)
      compass (>= 0.11.5)
    haml (4.0.6)
      tilt
    heroku (2.32.4)
      heroku-api (~> 0.3.5)
      launchy (>= 0.3.2)
      netrc (~> 0.7.7)
      rest-client (~> 1.6.1)
      rubyzip
    heroku-api (0.3.5)
      excon (~> 0.16.1)
    httparty (0.8.3)
      multi_json (~> 1.0)
      multi_xml
    i18n (0.7.0)
    launchy (2.1.2)
      addressable (~> 2.3)
    method_source (0.8.1)
    mime-types (1.19)
    multi_json (1.3.6)
    multi_xml (0.5.5)
    netrc (0.7.7)
    nokogiri (1.5.5)
    pg (0.13.2)
    pry (0.9.12)
      coderay (~> 1.0.5)
      method_source (~> 0.8)
      slop (~> 3.4)
    pry-nav (0.2.4)
      pry (>= 0.9.10, < 0.11.0)
    rack (1.4.1)
    rack-flash3 (1.0.5)
      rack
    rack-protection (1.5.3)
      rack
    rack-test (0.6.2)
      rack (>= 1.0)
    rake (0.9.2.2)
    rest-client (1.6.7)
      mime-types (>= 1.16)
    rubyzip (0.9.9)
    sass (3.2.19)
    selenium-webdriver (2.31.0)
      childprocess (>= 0.2.5)
      multi_json (~> 1.0)
      rubyzip
      websocket (~> 1.0.4)
    sequel (4.11.0)
    sequel_pg (1.6.11)
      pg (>= 0.8.0)
      sequel (>= 3.39.0)
    shotgun (0.9)
      rack (>= 1.0)
    sinatra (1.4.5)
      rack (~> 1.4)
      rack-protection (~> 1.4)
      tilt (~> 1.3, >= 1.3.4)
    sinatra-support (1.2.2)
      sinatra (>= 1.0)
    slop (3.4.4)
    thin (1.5.1)
      daemons (>= 1.0.9)
      eventmachine (>= 0.12.6)
      rack (>= 1.0.0)
    tilt (1.4.1)
    websocket (1.0.7)
    will_paginate (3.0.7)
    xpath (1.0.0)
      nokogiri (~> 1.3)

PLATFORMS
  ruby

DEPENDENCIES
  capybara
  database_cleaner
  faqtly!
  heroku
  pry
  pry-nav
  rack-test
  shotgun (~> 0.9)
  thin

Do you know what could be wrong with my code? Why isn't it using Sequel::Postgres::Dataset?

Thank you!

@jeremyevans
Copy link
Owner

My guess is that one of your dependencies is creating a Sequel::Database object, and since that is the first Sequel::Database object created, it's the default model database. Try:
Sequel::Model.db = DB before DB.extension :pagination and see if that fixes the issue.

In the future, note that as mentioned in the contribution guidelines, general help questions like this should be asked on the sequel-talk Google Group or IRC. GitHub Issues should only be used if you are fairly certain there is bug in Sequel itself, it should not be used as a help forum.

@etagwerker
Copy link
Author

@jeremyevans That was it. It's working as expected now.

I realize that this isn't a bug, but where can I find what you told me in the documentation? If it's missing, I'd be happy to submit a PR with this info for the right section.

Next time I'll ask in the Google Group.

@jeremyevans
Copy link
Owner

Well, setting the default database for models is covered in the method RDoc (http://sequel.jeremyevans.net/rdoc/classes/Sequel/Model/ClassMethods.html#method-i-db), but I agree this isn't well covered by any of the guides. If you can think of a good place to mention this in the documentation, I'll definitely accept a patch for it.

Which library were you using that was creating a Database object? Libraries that create Database objects should generally be using the block form so things like this don't happen. If I know the library, I can probably send them a pull request to fix this behavior.

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

2 participants