玩与sqlite/mysql兼容的H2 db框架吗? [英] play framework H2 db evolutions compatible with sqlite / mysql?

查看:102
本文介绍了玩与sqlite/mysql兼容的H2 db框架吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我一直在内存数据库中使用Play框架的默认SQL生成和H2.还有其他与这些SQL脚本完全兼容的数据库吗? 我仍处于开发阶段,因此喜欢自动生成SQL,但是我想与它一起使用持久数据库.我有什么选择?

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?

我曾短暂尝试过sqlite,但存在一些不兼容问题,例如AUTOINCREMENT,约束等.

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

推荐答案

有两个不错的选择,而选择属于您:

There are two good options and choice belongs to you:

  1. 对于开发来说,最好选择要在生产环境中使用的数据库引擎,MySQL或Postgres是非常典型的选择,因为它们在许多环境中都可用并且是开源的.播放将为他们两个生成正确的DDL.您还可以...
  2. 使用存储在文件中的H2代替内存,并以TCP为例进行访问,在这种情况下它将持久存在,并且您将保持使用H2控制台访问DB的可能性.

在这种情况下,示例连接URL为:(其中~是您的主目录,因此它将MainDB.h2.db文件保存在其中)

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"

您需要为您的平台下载H2软件包并在server mode中运行如文档中所述.您可以在bin目录中找到一个scripts/batch files,也可以只使用命令行来完成它.

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.

它还包括Java包装程序,因此您可以在Windows中将H2服务器作为服务运行,以确保它始终在启动时启动.

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.

最后,在成功的开发阶段之后,您可以将DB文件复制到目标计算机上并在生产环境中使用它,如果从TCP切换到Embedded模式,则将获得著名的H2性能提升,并且将避免需要运行服务器.

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.

这篇关于玩与sqlite/mysql兼容的H2 db框架吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆