我有一张桌子transactions
id | bigint | NOT NULL DEFAULT nextval('transactions_id_seq'::regclass)
transaction_id | bigint | NOT NULL
middleware_id | text |
opname | optype | NOT NULL
created_at | timestamp without time zone | NOT NULL
finished_at | timestamp without time zone |
request | jsonb | NOT NULL
answer | jsonb |
Run Code Online (Sandbox Code Playgroud)
其中请求可以包含以下数据:
{ plugin_id: string, item_src_id: string, item_dst_id: string, payload: {}}
或
{ plugin_id: string, item_id: string, payload: {}}
item_id我可以使用纯 SQL来选择事务列表:
SELECT id, request
FROM transactions
WHERE 'BEX456' …Run Code Online (Sandbox Code Playgroud) 我花了大约两天时间尝试使用 Rack::Test 发送自定义标头,但没有成功。我只是无法将任何标头发送到我的应用程序中。我在网上找到了很多类似代码的例子——方法(地址、正文、标题),但对我来说它们根本不起作用。
ruby 2.5.1p57 (2018-03-29 修订版 63029) [x86_64-linux]
# grep rack Gemfile.lock
rack (2.0.4)
rack-protection (2.0.1)
rack
rack-test (1.0.0)
rack (>= 1.0, < 3)
rack-protection (>= 1.5.0)
rack (~> 2.0)
rack-protection (= 2.0.1)
rack-test
Run Code Online (Sandbox Code Playgroud)
应用程序中的代码(sinatra):
$log = Logger.new STDERR
class MyApi < Sinatra::Application
before do
$log.debug{ "Headers: #{ headers.keys.inspect }" }
end
get '/offers' do
#... some code
end
post '/offers' do
# .. some another code
end
end
Run Code Online (Sandbox Code Playgroud)
规格/api_spec.rb
RSpec.describe MyApi, '/offers' do
include Rack::Test::Methods
def app
MyApi …Run Code Online (Sandbox Code Playgroud) 我坚持这一点。无法在文档中的任何地方找到如何声明诸如 inet 和 jsonb 或 json 之类的空间数据类型。
红宝石 2.4.1,续集 4.47
带有require 'sequel'.
声明如
DB.create_table :requests do
primary_key :id
foreign_key :client_id, :clients
foreign_key :service_id, :services
DateTime :created_at, null: false
DateTime :answered_at, null: false
JsonBType :request, null: false
end
Run Code Online (Sandbox Code Playgroud)