如何在数据库中存储站点范围的设置? [英] How to store site wide settings in a database?

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

问题描述

我在讨论三种不同的方法来存储网络应用程序的网站设置。



键/值对查找表,每个键代表一个设置。 / p>


  • 优点易于实施


  • 没有限制个别设定



单行设定表。




  • 优点根据设置默认值和约束

  • 缺点 - 很多设置很多列。不确定Postgres是否会有问题



只是硬编码,因为设置不会经常改变。




  • 优点易于设置和添加更多设置。

  • 更难改变。$ / b>


想去哪里?

解决方案

我使用了一个键/值对查找表,很好地描述了良好的结果。






此外,表格还有一个配置名称列,提供了一种简单的方法来选择/激活特定的集合配置设置。这意味着 prod dev test 生活在同一个表中,虽然它是由应用程序选择使用哪个集。在我们的情况下,JVM参数是有意义的。在同一个DB表中存储不同的设置配置设置可能是有意义的;






如果您正在考虑基于文件的配置,我喜欢 INI YAML 。您仍然可以将其存储在数据库中,尽管您可能找不到INI或YAML列类型(如可能针对XML)。


I'm debating three different approaches to to storing sitewide settings for a web application.

A key/value pair lookup table, each key represents a setting.

  • Pros Simple to implement
  • Cons No Constraints on the individual settings

A single row settings table.

  • Pros Per setting defaults and constraints
  • Cons - Lots of settings would mean lots of columns. Not sure if Postgres would have an issue with that

Just hard code it since the settings won't change that often.

  • Pros Easy to setup and add more settings.
  • Cons Much harder to change

Thoughts on which way to go?

解决方案

I've used a key/value pair lookup table much in the way you describe with good results.


As an added bonus the table had a "configuration name" column which provided a simple way to choose/activate a specific set of configuration settings. That meant that prod, dev, and test could all live in the same table, though it was up to the application to choose which set to use. In our case a JVM argument made sense. It might make sense to store different "sets" of config settings in the same DB table; then again, it might not.


If you are thinking about file-based configuration, I like INI or YAML. You could still store it in a database, though you probably won't find an INI or YAML column type (as you might for XML).

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

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