简体   繁体   English

如何为 postgres 应用程序组织参数

[英]How to organize parameters for a postgres application

I am working on a postgres application.我正在处理 postgres 应用程序。 For the moment I am not sure how to manage application constant parameters best.目前我不确定如何最好地管理应用程序常量参数。 For example I want to define a threshold variable which I am going to use in several functions.例如,我想定义一个阈值变量,我将在几个函数中使用它。

One idea is making a table "config" and query the variable every time I need them.一个想法是制作一个表“config”并在每次需要时查询变量。 And for a shortcut wrap the sql query into an other function ie: t := get_Config('Threshold');对于快捷方式,将 sql 查询包装到另一个函数中,即: t := get_Config('Threshold');

But in fact I am not really lucky with this.但事实上,我并不是很幸运。 What is the best way to handle custom application configuration parameters?处理自定义应用程序配置参数的最佳方法是什么? They should be handy in maintainance and I want to avoid querying every time for constants.它们在维护方面应该很方便,我想避免每次都查询常量。 In oracle for example you could compile constants into package specs.例如,在 oracle 中,您可以将常量编译为包规范。 Are there any better ways to deal with such configuration parameters?有没有更好的方法来处理这样的配置参数?

I have organized global parameters just the way you describe it for some years now.多年来,我一直按照您描述的方式组织全局参数。 It seems a bit awkward but it works just fine.这似乎有点尴尬,但它工作得很好。

I have got quite a number of those, so I added an integer plus index to my config table and use get_config($my_id) (plus comment) - which is slightly faster but less readable.我有很多这样的东西,所以我在我的配置表中添加了一个整数加索引并使用get_config($my_id) (加注释)——它稍微快一点但可读性较差。

OR you can use custom_variable_classes .或者您可以使用custom_variable_classes See:看:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM