play framework H2 db evolutions compatible with sqlite / mysql?

这一生的挚爱 提交于 2020-01-04 04:06:35

问题


So far, I have been using play framework's default SQL generation with H2 in memory db. Is there any other DB with which these SQL scripts are fully compatible? I like the auto generation of SQL as I am still in the developing phase, but I would like to use a persistent db along with it. What are my options?

I briefly tried with sqlite, but there are some incompatibilities such as AUTOINCREMENT, constraints etc.


回答1:


There are two good options and choice belongs to you:

  1. Preferably for development choose the same DB engine which you are suppose to use in production, MySQL or Postgres are quite typical choices as they are available in many environments and are open source. Play will generate for both of them correct DDL. You can also...
  2. Use H2 stored in the file instead of memory and access it for an example with TCP, in that case it will be persistant, and you'll keep possibility to access DB with H2 console.

Sample connection URL in that case is: (where ~ is your home directory, so it will save the MainDB.h2.db file there)

db.default.url="jdbc:h2:tcp://localhost/~/MainDB"

You need to download H2 package for your platform and run it in server mode as described in the doc. You'll find a scripts/batch files in the bin directory or you can just do it with the command line.

It also has included java wrapper, so you can run H2 server as a service in Windows to make sure it's always starting on the boot.

Finally after successful development phase, you can just copy DB file to the target machine and use it on the production, if you'll switch from TCP to Embedded mode you'll get famous H2 performance boost and also will avoid need for running the server.



来源:https://stackoverflow.com/questions/15187594/play-framework-h2-db-evolutions-compatible-with-sqlite-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!