自动创建OrmLite表

时间:2017-10-14 01:25:01

标签: google-app-engine orm google-cloud-sql ormlite

我使用OrmLiteGoogle App Engine应用程序中的Java对象映射到一堆数据库表(MySQL)。有没有办法在Google的Cloud SQL或类似的基于云的SQL服务上自动创建表,而不必自己手动创建表。

OrmLite的文档没有涵盖这一点,Google App Engine也没有。

非常感谢任何指向正确方向的指针。

1 个答案:

答案 0 :(得分:1)

  

有没有办法自动创建表格......   OrmLite的文档不包括这个......

我不确定您是否专门讨论云SQL,但ORMLite 当然有大量关于创建表的文档。

  • TableUtils是支持(嗯)table utility methods的类,例如create和delete。这是javadocs
  • Getting Started部分中,它讨论了使用TableUtil在代码示例中创建架构。 “如何使用”
  • 中的更多详细信息
  • documentation index中,我看到以下条目:“创建表格”和“创建表格”。

引用Getting Started文档中的示例代码。

// instantiate the dao
Dao<Account, String> accountDao =
DaoManager.createDao(connectionSource, Account.class);

// if you need to create the 'accounts' table make this call
TableUtils.createTable(connectionSource, Account.class);

TableUtil还有一个返回创建的SQL statements的方法。

相关问题