带有JRuby和Sequel的SQLite3

时间:2018-10-05 10:37:51

标签: windows sqlite jruby sequel

我需要在Windows上将SQLite3与Jruby和Sequel gem一起使用。

require 'sequel'
DB = Sequel.sqlite

我收到此错误:

Sequel::AdapterNotFound: LoadError: no such file to load -- sqlite3
     load_adapter at C:/jruby-9.1.13.0/lib/ruby/gems/shared/gems/sequel-5.9.0/lib/sequel/database/connecting.rb:93
    adapter_class at C:/jruby-9.1.13.0/lib/ruby/gems/shared/gems/sequel-5.9.0/lib/sequel/database/connecting.rb:17
          connect at C:/jruby-9.1.13.0/lib/ruby/gems/shared/gems/sequel-5.9.0/lib/sequel/database/connecting.rb:45
          connect at C:/jruby-9.1.13.0/lib/ruby/gems/shared/gems/sequel-5.9.0/lib/sequel/core.rb:116
   adapter_method at C:/jruby-9.1.13.0/lib/ruby/gems/shared/gems/sequel-5.9.0/lib/sequel/core.rb:394
  block in sqlite at C:/jruby-9.1.13.0/lib/ruby/gems/shared/gems/sequel-5.9.0/lib/sequel/core.rb:401
           <main> at test.rb:53

当我尝试安装sqlite3 gem时,构建本机扩展时会失败:

Building native extensions. This could take a while...
ERROR:  Error installing sqlite3:
        ERROR: Failed to build gem native extension.

    current directory: C:/jruby-9.1.13.0/lib/ruby/gems/shared/gems/sqlite3-1.3.1
3/ext/sqlite3
C:/jruby-9.1.13.0/bin/jruby.exe -r ./siteconf20181005-6576-1e4h1cf.rb extconf.rb

checking for sqlite3.h... RuntimeError: The compiler failed to generate an executable file.
You have to install development tools first.

                 try_do at C:/jruby-9.1.13.0/lib/ruby/stdlib/mkmf.rb:456
                try_cpp at C:/jruby-9.1.13.0/lib/ruby/stdlib/mkmf.rb:587
   block in find_header at C:/jruby-9.1.13.0/lib/ruby/stdlib/mkmf.rb:1144
  block in checking_for at C:/jruby-9.1.13.0/lib/ruby/stdlib/mkmf.rb:942
      block in postpone at C:/jruby-9.1.13.0/lib/ruby/stdlib/mkmf.rb:350
                   open at C:/jruby-9.1.13.0/lib/ruby/stdlib/mkmf.rb:320
      block in postpone at C:/jruby-9.1.13.0/lib/ruby/stdlib/mkmf.rb:350
                   open at C:/jruby-9.1.13.0/lib/ruby/stdlib/mkmf.rb:320
               postpone at C:/jruby-9.1.13.0/lib/ruby/stdlib/mkmf.rb:346
           checking_for at C:/jruby-9.1.13.0/lib/ruby/stdlib/mkmf.rb:941
            find_header at C:/jruby-9.1.13.0/lib/ruby/stdlib/mkmf.rb:1143
                 <main> at extconf.rb:50
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=C:/jruby-9.1.13.0/bin/jruby
        --with-sqlite3-config
        --without-sqlite3-config
        --with-pkg-config
        --without-pkg-config
        --with-sqlite3-dir
        --without-sqlite3-dir
        --with-sqlite3-include
        --without-sqlite3-include=${sqlite3-dir}/include
        --with-sqlite3-lib
        --without-sqlite3-lib=${sqlite3-dir}/lib

To see why this extension failed to compile, please check the mkmf.log which can
 be found here:

  C:/jruby-9.1.13.0/lib/ruby/gems/shared/extensions/universal-java-1.8/2.3.0/sql
ite3-1.3.13/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in C:/jruby-9.1.13.0/lib/ruby/gems/shared/gems/s
qlite3-1.3.13 for inspection.
Results logged to C:/jruby-9.1.13.0/lib/ruby/gems/shared/extensions/universal-ja
va-1.8/2.3.0/sqlite3-1.3.13/gem_make.out

我已经在jruby / bin文件夹中复制了SQLite库(sqlite3.dll,sqlite3.def)。

JRuby官方页面建议使用activerecord-jdbc-adapter,但是我需要在内存中创建db,而不是连接到现有数据库。

我该怎么办?

我的环境:
Jruby v.9.1.13
续集v.5.9.0
Windows Server 2012 R2

1 个答案:

答案 0 :(得分:1)

您要使用Sequel jdbc适配器和jdbc-sqlite3 gem:

require 'sequel'
DB = Sequel.connect("jdbc:sqlite::memory:")

FWIW,如果您想要一个带有JRuby,h2,hsqldb和derby的内存数据库可能是更好的选择(并且Sequel支持所有它们)。