首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >可以将CockroachDB Sequel与Ruby/Sequel连接起来

可以将CockroachDB Sequel与Ruby/Sequel连接起来
EN

Stack Overflow用户
提问于 2022-08-28 01:30:12
回答 1查看 60关注 0票数 0

要连接CockrachDB Serverless,我必须在连接字符串(?sslmode=verify-full&options=--cluster%3Dblackstack-4545)中传递一些参数。

完整连接字符串如下所示:

代码语言:javascript
复制
postgresql://blackstack:<db-password>@free-tier14.aws-us-east-1.cockroachlabs.cloud:26257/blackstack?sslmode=verify-full&options=--cluster%3Dblackstack-4545

在Ruby中,如果我使用pg gem,这样的连接字符串工作得很好,但是如果我使用Sequel,它就会失败。

下面是测试代码:

代码语言:javascript
复制
require 'pg'
require 'sequel'
    
DATABASE_URL="postgresql://blackstack:<db-password>@free-tier14.aws-us-east-1.cockroachlabs.cloud:26257/blackstack?sslmode=verify-full&options=--cluster%3Dblackstack-4545"
    
conn = PG.connect(DATABASE_URL)
p conn.exec("SELECT 'Hello CockroachDB!' AS message").first
# => {"message"=>"Hello CockroachDB!"}
    
DB = Sequel.connect(DATABASE_URL)
p DB["SELECT 'Hello CockroachDB!' AS message"].first
# => "/home/leandro/.rvm/gems/ruby-3.1.2/gems/pg-1.3.5/lib/pg/connection.rb:637:in `async_connect_or_reset': PG::ConnectionBad: FATAL:  codeParamsRoutingFailed: missing cluster identifier (Sequel::DatabaseConnectionError)"

下面是命令的完整输出:

代码语言:javascript
复制
leandro@dev5:~/code/mysaas/examples/1.db$ ruby 1.connect.rb
{"message"=>"Hello CockroachDB!"}
/home/leandro/.rvm/gems/ruby-3.1.2/gems/pg-1.3.5/lib/pg/connection.rb:637:in `async_connect_or_reset': PG::ConnectionBad: FATAL:  codeParamsRoutingFailed: missing cluster identifier (Sequel::DatabaseConnectionError)
    from /home/leandro/.rvm/gems/ruby-3.1.2/gems/pg-1.3.5/lib/pg/connection.rb:707:in `new'
    from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/adapters/postgres.rb:208:in `connect'
    from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/connection_pool.rb:122:in `make_new'
    from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/connection_pool/threaded.rb:209:in `assign_connection'
    from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/connection_pool/threaded.rb:139:in `acquire'
    from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/connection_pool/threaded.rb:91:in `hold'
    from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/database/connecting.rb:269:in `synchronize'
    from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/database/connecting.rb:278:in `test_connection'
    from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/database/misc.rb:175:in `initialize'
    from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/database/connecting.rb:57:in `new'
    from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/database/connecting.rb:57:in `connect'
    from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/core.rb:124:in `connect'
    from 1.connect.rb:10:in `<main>'
/home/leandro/.rvm/gems/ruby-3.1.2/gems/pg-1.3.5/lib/pg/connection.rb:637:in `async_connect_or_reset': FATAL:  codeParamsRoutingFailed: missing cluster identifier (PG::ConnectionBad)
    from /home/leandro/.rvm/gems/ruby-3.1.2/gems/pg-1.3.5/lib/pg/connection.rb:707:in `new'
    from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/adapters/postgres.rb:208:in `connect'
    from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/connection_pool.rb:122:in `make_new'
    from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/connection_pool/threaded.rb:209:in `assign_connection'
    from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/connection_pool/threaded.rb:139:in `acquire'
    from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/connection_pool/threaded.rb:91:in `hold'
    from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/database/connecting.rb:269:in `synchronize'
    from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/database/connecting.rb:278:in `test_connection'
    from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/database/misc.rb:175:in `initialize'
    from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/database/connecting.rb:57:in `new'
    from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/database/connecting.rb:57:in `connect'
    from /home/leandro/.rvm/gems/ruby-3.1.2/gems/sequel-5.56.0/lib/sequel/core.rb:124:in `connect'
    from 1.connect.rb:10:in `<main>'
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-30 15:02:48

我自己修好了。

我使用cluster_name.db_name格式来处理下面的连接字符串。

代码语言:javascript
复制
postgresql://blackstack:<db-password>@free-tier14.aws-us-east-1.cockroachlabs.cloud:26257/blackstack-4545.blackstack?sslmode=verify-full
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73515424

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档