我知道slick-codegen可以从数据库表生成scala类。如果模型中的数据库中不存在表,我们可以做相反的事情吗?
您可以通过模型在Slick中创建表:不过,它与代码生成工具无关。
在Slick中定义模型时,可以使用该.schema
方法生成数据库模式命令。《The Slick Manual》中有一些例子:
// Assuming we have coffees and suppliers queries, we combine the schemas:
val schema = coffees.schema ++ suppliers.schema
// Now we can run a variety of commands to CREATE TABLE etc:
db.run(DBIO.seq(
schema.create,
schema.createIfNotExists,
schema.drop,
schema.dropIfExists
))
但是,这不是自动的:您需要在启动代码中编写一些内容来决定是否运行DDL命令。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句