如何在Ruby Sequel arbitary sql运行中查找列名

如何在Ruby Sequel arbitary sql运行中查找列名,ruby,sequel,Ruby,Sequel,我正在使用Ruby Sequel DB.run运行任意sql。我想找出数据集的列名 在Ruby Sequel中可能吗?您能否提供一个简单的工作示例(一个代码示例,看看您想要什么,如果可能的话,不需要) 我猜你在做什么: require 'sequel' db = Sequel.sqlite() db.create_table(:test){ field :x1 field :x2 } db[:test].insert(1,2) p db.run('select * from test'

我正在使用Ruby Sequel DB.run运行任意sql。我想找出数据集的列名


在Ruby Sequel中可能吗?

您能否提供一个简单的工作示例(一个代码示例,看看您想要什么,如果可能的话,不需要)

我猜你在做什么:

require 'sequel'

db = Sequel.sqlite()
db.create_table(:test){
  field :x1
  field :x2
}
db[:test].insert(1,2)
p db.run('select * from test') #->nil
如果您不使用
运行
而使用
[]
则会得到另一个结果:

p db['select * from test']  #-> #<Sequel::SQLite::Dataset: "select * from test">

你能提供一个简单的工作示例(一个代码示例,看看你想要什么,如果可能的话,没有)

我猜你在做什么:

require 'sequel'

db = Sequel.sqlite()
db.create_table(:test){
  field :x1
  field :x2
}
db[:test].insert(1,2)
p db.run('select * from test') #->nil
如果您不使用
运行
而使用
[]
则会得到另一个结果:

p db['select * from test']  #-> #<Sequel::SQLite::Dataset: "select * from test">
使用Sequel的:

该方法将返回为特定表定义的字段:

items.columns # => [:id, :name, :price]
您也可以直接使用:

DB[:items].columns # => [:id, :name, :price]
使用Sequel的:

该方法将返回为特定表定义的字段:

items.columns # => [:id, :name, :price]
您也可以直接使用:

DB[:items].columns # => [:id, :name, :price]

给出文档链接。询问代码的问题必须表明对所解决问题的最低理解。包括尝试过的解决方案、它们不起作用的原因以及预期结果。另请参见:[堆栈溢出问题检查表()。提供文档链接。.询问代码的问题必须证明对正在解决的问题的最低理解。包括尝试的解决方案、为什么不起作用以及预期结果。另请参见:[堆栈溢出问题检查表()“MWE”?您能提供一个“SUA”吗(完全可以理解的首字母缩略词)?@theTinMan抱歉,在不同的社区之间用不同的措辞跳跃让我感到困惑。“MWE”?你能提供一个“SUA”(完全可以理解的首字母缩略词)?@theTinMan抱歉,在不同的社区之间用不同的措辞跳跃让我感到困惑。