我正在使用Sequel与Sinatra并且我一直在尝试它并且我注意到它创建了重复的条目(3x)。我试图调试它但最后我不明白为什么会发生这种情况
这是我的代码:
require 'sinatra'
require 'mysql2'
require 'sequel'
DB=Sequel.connect(
:adapter => "mysql2",
:host =>"localhost",
:user => "root",
:password => "",
:database => "test"
)
if !DB.table_exists? :users
DB.create_table :users do
primary_key :id
String :username ,:size=>20 #,:unique=>true
String :password ,:size=>30
end
puts "Schema created"
else
puts "Already exists"
end
class User < Sequel::Model;end
class Test < Sinatra::Base
get '/:username' do
"Creating user"
User.create(:username => "#{params['username']}",:password => "test")
end
end