Ruby 如何判断DataMapper中是否存在表
此代码在最后一行失败,具体原因是检查表_是否存在?如何在Datamapper中正确执行此操作Ruby 如何判断DataMapper中是否存在表,ruby,datamapper,Ruby,Datamapper,此代码在最后一行失败,具体原因是检查表_是否存在?如何在Datamapper中正确执行此操作 require 'sinatra' require 'DataMapper' DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/blog.db") class Post include DataMapper::Resource property :id, Serial property :title, String
require 'sinatra'
require 'DataMapper'
DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/blog.db")
class Post
include DataMapper::Resource
property :id, Serial
property :title, String
property :body, Text
property :created_at, DateTime
end
DataMapper.finalize
# automatically create the post table
DataMapper.auto_migrate! unless Post.table_exists?
您可以使用
DataMapper.auto\u更新代码>应该是非破坏性的(仅添加表/列)。您可以使用DataMapper.auto\u update代码>应该是非破坏性的(仅添加表/列)。Justin
如果您需要dm迁移
(这基本上意味着您正在使用RDBMS适配器),您可以执行以下操作以确定是否存在表(或该表中的列)
请注意,如果需要进行dm迁移
,并且您使用的是DataObjectsAdapter
子代,则这些API方法只会混合到适配器中。Justin
如果您需要dm迁移
(这基本上意味着您正在使用RDBMS适配器),您可以执行以下操作以确定是否存在表(或该表中的列)
请注意,如果需要dm迁移
,并且您使用的是DataObjectsAdapter
子代,则这些API方法只会混合到适配器中。是的,谢谢,这就是我为解决此问题所做的工作,然而,我真的很想了解foo到底发生了什么事。table_存在?是的,谢谢你,这就是我一直在做的事情来解决这个问题,但是我真的很想了解foo到底发生了什么事。table_存在吗?
# Find out if the table named 'people' exists
DataMapper.repository(:default).adapter.storage_exists?('people')
# Find out if there's a 'name' column in the 'people' table
DataMapper.repository(:default).adapter.field_exists?('people', 'name')