如何从Sequel连接到SQLite

时间:2018-10-09 01:12:31

标签: ruby sequel

我的SQLite数据库位于p:\StockSymbols.db

我正在尝试通过sequel gem进行连接,但它不喜欢它。

C:\Users\murth>irb irb(main):001:0> require 'sqlite3'
=> true irb(main):002:0> require 'sequel'
=> true irb(main):003:0> Sequel.sqlite('P:\\StockSymbols.db')
=> #<Sequel::SQLite::Database: {:adapter=>:sqlite, :database=>"P:\\StockSymbols.db"}> irb(main):004:0>  Sequel.connect("P:\\StockSymbols.db") URI::InvalidURIError: bad URI(is not URI?): P:\StockSymbols.db
        from C:/Ruby24-x64/lib/ruby/2.4.0/uri/rfc3986_parser.rb:67:in `split'
        from C:/Ruby24-x64/lib/ruby/2.4.0/uri/rfc3986_parser.rb:73:in `parse'
        from C:/Ruby24-x64/lib/ruby/2.4.0/uri/common.rb:231:in `parse'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/sequel-5.13.0/lib/sequel/database/connecting.rb:34:in `connect'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/sequel-5.13.0/lib/sequel/core.rb:121:in `connect'
        from (irb):4
        from C:/Ruby24-x64/bin/irb.cmd:19:in `<main>' irb(main):005:0> Sequel.connect("sqllite:///P:/StockSymbols.db") Sequel::AdapterNotFound: LoadError: cannot load such file -- sequel/adapters/sqllite
        from C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from C:/Ruby24-x64/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/sequel-5.13.0/lib/sequel/database/connecting.rb:88:in `load_adapter'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/sequel-5.13.0/lib/sequel/database/connecting.rb:17:in `adapter_class'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/sequel-5.13.0/lib/sequel/database/connecting.rb:36:in `connect'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/sequel-5.13.0/lib/sequel/core.rb:121:in `connect'
        from (irb):5
        from C:/Ruby24-x64/bin/irb.cmd:19:in `<main>'

1 个答案:

答案 0 :(得分:0)

希望您也安装了sqlite3。您可能还需要在require 'sqlite3'之前的同一irb会话中Sequel.connect

此外,使用snake_case重命名数据库。只是一个约定。

require 'sequel'
require 'sqlite3'

DB = Sequel.connect('sqlite://your_db.db') # ./your_db.db