使用 Sequel 插入数据库
Insert Into DB using Sequel
我想使用 Sequel 将一些数据插入到 Postgres 数据库中。我尝试了两种方法,none 得到了我想要的结果。
我的第一个方法是“Querying in Sequel”:
connection = Sequel.connect('postgres://admin:admin@localhost:5432/test_tcp')
insert_values = connection["INSERT INTO cards (:card_number, :phone_number, :uuid, :created_at, :updated_at) VALUES (?)", '766877868', '256700000000', '9043', '2016-09-07 11:11:31 +0300', '2016-09-07 11:11:31 +0300']
insert_values.insert
connection.close
我的第二种方法是“Inserting Records”:
connection = Sequel.connect('postgres://admin:admin@localhost:5432/test_tcp')
cards = connection.from(:cards)
cards.insert(:id => 1, :card_number => "13668389", :phone_number => "256700000000", :uuid => "9014", :created_at => '2016-09-07 11:11:31 +0300', :updated_at => '2016-09-07 11:11:31 +0300')
connection.close
只需遵循以下代码对我有用:
connection = Sequel.connect('postgres://admin:admin@localhost:5432/test_tcp')
cards = connection.from(:cards)
cards.insert(id: 1, card_number: "13668389", phone_number: "256700000000", uuid: "9014", created_at: '2016-09-07 11:11:31', updated_at: '2016-09-07 11:11:31')
connection.close
更改 :created_at
和 :updated_at
的值以存储没有时区的时间戳就成功了。
奇怪的是 Sequel 没有输出错误警告。
我想使用 Sequel 将一些数据插入到 Postgres 数据库中。我尝试了两种方法,none 得到了我想要的结果。
我的第一个方法是“Querying in Sequel”:
connection = Sequel.connect('postgres://admin:admin@localhost:5432/test_tcp')
insert_values = connection["INSERT INTO cards (:card_number, :phone_number, :uuid, :created_at, :updated_at) VALUES (?)", '766877868', '256700000000', '9043', '2016-09-07 11:11:31 +0300', '2016-09-07 11:11:31 +0300']
insert_values.insert
connection.close
我的第二种方法是“Inserting Records”:
connection = Sequel.connect('postgres://admin:admin@localhost:5432/test_tcp')
cards = connection.from(:cards)
cards.insert(:id => 1, :card_number => "13668389", :phone_number => "256700000000", :uuid => "9014", :created_at => '2016-09-07 11:11:31 +0300', :updated_at => '2016-09-07 11:11:31 +0300')
connection.close
只需遵循以下代码对我有用:
connection = Sequel.connect('postgres://admin:admin@localhost:5432/test_tcp')
cards = connection.from(:cards)
cards.insert(id: 1, card_number: "13668389", phone_number: "256700000000", uuid: "9014", created_at: '2016-09-07 11:11:31', updated_at: '2016-09-07 11:11:31')
connection.close
更改 :created_at
和 :updated_at
的值以存储没有时区的时间戳就成功了。
奇怪的是 Sequel 没有输出错误警告。