将数据库无缝包装到用户的应用程序中 [英] Packaging database into application seamlessly for users

查看:143
本文介绍了将数据库无缝包装到用户的应用程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个使用关系数据库的桌面应用程序(例如postgres - 我们最好的情况是在这个应用程序中使用postgres)。



我想让用户不知道数据库。目前,我不得不安装postgres到我的本地计算机,并让我的应用程序与之通信。



我使用Go。


$ b $



这不是PostgreSQL的理想工作,但您可以稍微小心使用它



请不要捆绑安装程序并无人值守运行它。后来去安装PostgreSQL的用户在看到它已经在他们的计算机上时会很困惑,但他们不知道为什么,安装它或者密码是什么。



initdb 在应用程式的%APPDATA% c>%PROGRAMDATA%。设置自定义端口(不要使用默认5432)。使用 pg_ctl寄存器创建一个新服务,以 NETWORKSERVICE 运行,或者只需根据需要启动/停止 pg_ctl 。这样,你不会妨碍任何现有的PostgreSQL安装或新的安装,并有一个私人的PostgreSQL只为你的应用程序。



请为用户提供选项为现有的PostgreSQL提供连接字符串。如果应用程序坚持使用自己的嵌入式副本,当你不想要它们是一个痛苦。



通常最好看看使用SQLite,H2,Derby,Firebird ,或其他嵌入式数据库之一。


I want to create a desktop application that uses a relational database (such as postgres - let's say my best case scenario is to use postgres in this application).

I want users to be unaware of the database. Currently, I had to install postgres into my local computer and have my application communicate with that.

I am using Go.

How can I avoid this?

解决方案

You're looking for an embedded database.

This isn't an ideal job for PostgreSQL, but you can use it that way with a bit of care.

Please don't bundle the installer and run it unattended. Users who later go to install PostgreSQL will be very confused when they see it's already on their computer but they don't know why, who installed it, or what the password is.

Instead initdb a new datadir inside your app's %APPDATA% or (for multiuser shared) in %PROGRAMDATA%. Set a custom port (don't use the default 5432). Create a new service with pg_ctl register, running as NETWORKSERVICE, or just start/stop on demand with pg_ctl. That way you won't get in the way of any existing PostgreSQL installs or new ones and have a private PostgreSQL just for your app.

Please offer users the option of instead supplying a connection string for an existing PostgreSQL though. It's a pain if apps insist on using their own embedded copy when you don't want them to.

Often it's better to look at using SQLite, H2, Derby, Firebird, or one of the other embedded DBs, though.

这篇关于将数据库无缝包装到用户的应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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