使用 h2-browser 访问播放项目数据库 [英] Accessing play project database with h2-browser

查看:29
本文介绍了使用 h2-browser 访问播放项目数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在通过 Play 框架项目上的 h2-browser 访问 mem 数据库时遇到了一些问题.

使用下面的配置,我认为这是正确的(显然不是!)我得到了一个 h2 浏览器,但没有表(除了架构之外),即使我已经应用了一些迁移.

我在这里错过了什么?提前致谢.

conf/application.conf:

db.default.driver=org.h2.Driverdb.default.url="jdbc:h2:mem:play"db.default.user=sadb.default.password=""

解决方案

当您使用 in-mem 数据库时,实际上您正在访问两个不同的数据库(尽管使用相同的路径).您有两种解决方案:

  1. 首先从你的控制台开始裸播放"控制台,运行 h2-browser,最后运行你的应用程序(在同一个 play 控制台内)
  2. 服务器模式下运行 H2,这种方法的额外好处是您不会丢失每个应用程序重新启动时的数据,因为 DB 存储在文件中.然后您可以从多个点(也从独立"H@ 浏览器或其他一些 GUI)访问该数据库,路径类似于:

Unix (~ 表示你的主目录)

db.default.url="jdbc:h2:tcp://localhost/~/some/path/to/MyPlayDB"

或 Windows

db.default.url="jdbc:h2:tcp://localhost/c:/some/path/to/MyPlayDB"

请注意,为了在生产模式下获得最佳性能,值得切换回嵌入式模式,但是对于开发阶段,该解决方案应该足够好(仍然比示例 MySQL 快)

I am having some trouble accessing the mem database via the h2-browser on a Play framework project.

With the configuration below, that I think is the correct one (apparently not!) I am getting a h2-browser, but with no tables (beside schema, that is), even though I have applied some migrations.

What am I missing here? Thanks in advance.

conf/application.conf:

db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play"
db.default.user=sa
db.default.password=""

解决方案

When you are using in-mem databases actually you are accessing two different databases (although with the same path). You have two solutions:

  1. First from your console start bare 'play' console, run h2-browser and finally run your app (withinh the same play console)
  2. Run H2 in server mode, additional beneffit from this approach is fact that you won't loose your data at every app's restart as DB is stored in the file. Then you can access this database from many points (also from 'standalone' H@ browser or some other GUI) with path similar to:

Unix (~ means your home directory)

db.default.url="jdbc:h2:tcp://localhost/~/some/path/to/MyPlayDB"

or Windows

db.default.url="jdbc:h2:tcp://localhost/c:/some/path/to/MyPlayDB"

Note that for best performance in production mode it's worthy switch back to embedded mode, however for dev stage that solution should be good enough (still faster than for an example MySQL)

这篇关于使用 h2-browser 访问播放项目数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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