使用H2-浏览器访问Play项目数据库
在Play
框架项目上通过h2-browser
访问mem数据库时遇到一些麻烦.
I am having some trouble accessing the mem database via the h2-browser
on a Play
framework project.
使用以下配置,我认为是正确的配置(显然不是!),尽管我已经进行了一些迁移,但我正在获取h2-浏览器,但是没有表(即在模式旁边)没有表.
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:
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:
- 首先从控制台启动"play"控制台,运行h2-browser,最后运行您的应用程序(在同一
play
控制台内) - 以服务器模式运行H2,这种方法带来的其他好处是您不会放松数据库存储在文件中时,每个应用程序重新启动时您的数据.然后,您可以从多个点(也可以从独立" H @浏览器或某些其他GUI)访问该数据库,其路径类似于:
- First from your console start bare 'play' console, run h2-browser and finally run your app (withinh the same
play
console) - 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(~
表示您的主目录)
Unix (~
means your home directory)
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更快)
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)