如何在数据库中结构配置数据? [英] How do you structure config data in a database?

查看:114
本文介绍了如何在数据库中结构配置数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

人们将应用程序配置数据存储在数据库中的首选方法是什么。

What is people's prefered method of storing application configuration data in a database. From having done this in the past myself, I've utilised two ways of doing it.


  1. 您可以创建一个表,在其中存储密钥/ value对,其中key是config选项的名称,value是其值。 Pro的这个是添加新的值很容易,你可以使用相同的例程来设置/获取数据。

  2. 或者,您可以对配置表进行硬编码,每个列都是值的名称及其数据类型。

使用这两个选项后,我的偏好设置第一个选项是更快地设置的东西,但它的风险更大,可以降低性能(轻微)查找数据时。有没有其他方法?

Having used both, my preferences lie with the first option as its quicker to set things up, however its also riskier and can reduce performance (slightly) when looking up data. Does anyone have any alternative methods?

更新

数据库中的信息,因为如下所述,可能存在需要以相同方式配置的程序的多个实例,以及可能使用相同值的存储过程。

It's necessary to store the information in a database because as noted below, there may be multiple instances of the program that require configuring the same way, as well as stored procedures potentially using the same values.

推荐答案

您可以将选项1展开为第三列,并提供数据类型。您的应用程序可以使用此数据类型列来转换值。

You can expand option 1 to have a 3rd column, giving a data-type. Your application can than use this data-type column to cast the value.

但是,我会选择选项1,如果配置文件不是一个选项。选项1的另一个优点是,您可以将其读入一个Dictionary对象(或等效的对象),以方便地在应用程序中使用。

But yeah, I would go with option 1, if config files are not an option. Another advantage of option 1 is you can read it into a Dictionary object (or equivalent) for use in your application really easily.

这篇关于如何在数据库中结构配置数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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