将设置存储在数据库中

发布于 2024-09-14 05:39:48 字数 1442 浏览 2 评论 0原文

有人可以告诉我在一个文件中存储许多不同设置的最佳方法是什么吗 数据库?我应该使用一张包含 id、key、value 的表吗?

这是我必须存储的一个示例:

PageNavigation.Font = "fontRegular";
PageNavigation.FontSize = 14;
PageNavigation.FontColor = 0x000000;
PageNavigation.SubFont = "fontRegular";
PageNavigation.SubFontSize = 12;
PageNavigation.SubFontColor = 0x000000;
PageNavigation.width = 200;
PageNavigation.height = 22;
PageNavigation.spacing = 5;
PageNavigation.LetterSpacing = 0;
PageNavigation.top = 250;
PageNavigation.rightMargin = 24;
PageNavigation.RollOverColor = 0xFF3300;
PageNavigation.ActiveColor = 0xCCCCCC;
PageNavigation.Icon = "/assets/images/arrow_default.png";
PageNavigation.IconLeft = 5;
PageNavigation.TextLeft = 5;
PageNavigation.SubIcon = "";
PageNavigation.SubIconLeft = 5;
PageNavigation.SubTextLeft = 22;

PageViewer.BackgroundColor = 0xe9edee;
PageViewer.ThumbSource = "";
PageViewer.maxVisible = 17;
PageViewer.ThumbWidth = 38;
PageViewer.ThumbHeight = 49;
PageViewer.ThumbActiveBorder = 2;
PageViewer.ThumbActiveBorderColor = 0xEE2233;
PageViewer.ThumbSpacing = 10;
PageViewer.ThumbLeft = 20;
PageViewer.ThumbBorderColor = 0xFF3300;
PageViewer.ThumbBorderSize = 1;
PageViewer.ThumbRollOverColor = 0xDDDDDD;
PageViewer.ThumbActiveColor = 0xCCCCCC;
PageViewer.ThumbSelectColor = 0xCCCCCC;
PageViewer.ThumbShadow = 1;
PageViewer.ThumbLayout = "Layout1";
PageViewer.ButtonLayout = "ButtonLayout1";

我是数据库设计的新手,不知道学习数据库设计的好资源

干杯, 多姆

can someone tell me what's the best way to store many different settings in a
database? Should I use one table with id,key,value?

Here is an example what i have to store:

PageNavigation.Font = "fontRegular";
PageNavigation.FontSize = 14;
PageNavigation.FontColor = 0x000000;
PageNavigation.SubFont = "fontRegular";
PageNavigation.SubFontSize = 12;
PageNavigation.SubFontColor = 0x000000;
PageNavigation.width = 200;
PageNavigation.height = 22;
PageNavigation.spacing = 5;
PageNavigation.LetterSpacing = 0;
PageNavigation.top = 250;
PageNavigation.rightMargin = 24;
PageNavigation.RollOverColor = 0xFF3300;
PageNavigation.ActiveColor = 0xCCCCCC;
PageNavigation.Icon = "/assets/images/arrow_default.png";
PageNavigation.IconLeft = 5;
PageNavigation.TextLeft = 5;
PageNavigation.SubIcon = "";
PageNavigation.SubIconLeft = 5;
PageNavigation.SubTextLeft = 22;

PageViewer.BackgroundColor = 0xe9edee;
PageViewer.ThumbSource = "";
PageViewer.maxVisible = 17;
PageViewer.ThumbWidth = 38;
PageViewer.ThumbHeight = 49;
PageViewer.ThumbActiveBorder = 2;
PageViewer.ThumbActiveBorderColor = 0xEE2233;
PageViewer.ThumbSpacing = 10;
PageViewer.ThumbLeft = 20;
PageViewer.ThumbBorderColor = 0xFF3300;
PageViewer.ThumbBorderSize = 1;
PageViewer.ThumbRollOverColor = 0xDDDDDD;
PageViewer.ThumbActiveColor = 0xCCCCCC;
PageViewer.ThumbSelectColor = 0xCCCCCC;
PageViewer.ThumbShadow = 1;
PageViewer.ThumbLayout = "Layout1";
PageViewer.ButtonLayout = "ButtonLayout1";

I'm new to database design and don't know good resources to learn db-design

Cheers,
Dom

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你如我软肋 2024-09-21 05:39:48

我认为最好的方法是为每种类型的设置创建一个字段。这样做的作用是,

  • 我们可以将许多用户的许多用户定义设置保存在一张表中。
  • 我们可以创建不同的预定义设置集,这些设置在多种情况下很有用

,等等

the best I think is to create a field for each type of setting. What does this do is,

  • we can keep many user defined settings of many users in one table.
  • we can create different sets of predefined setting which can be useful in several cases

ETC

兰花执着 2024-09-21 05:39:48

是的,这可行,但缺点是设置值没有正确的类型。您必须将所有内容声明为 VARCHAR,您的应用程序必须检查值的有效性。

当然,可以为每种设置类型创建一个表,例如,

create table Settings
(
  settings_id primary key int not null,
  name VARCHAR(255) not null,
);

create table DoubleValues
(
  value double not null
  fk_setting int not null;
);

create table ColorValues
(
  value char(8) not null
  fk_setting int not null;
);

..

另一种方法是为每个设置创建一个包含一行和一列的表。这样您就可以进行正确的输入,并可以在数据库级别添加检查约束。但我认为这个更难维护和扩展,所以我更喜欢第一个,但一如既往,这取决于您的具体需求。

另一种方法是使用一个简单的文本文件并将设置读取到哈希表中,这将是迄今为止最快的方法。也许您可以看看像 MongoDb 或 CouchDb 这样的 noSQL 数据库。

考虑您的设置是否大部分是静态的,或者插入或删除新设置键的频率。

Yes this would work but has the downside that settings values has no proper type. You would have to declare everything as VARCHAR, your application would have to check the validity of the values.

Sure it would be possible to create a table for each setting type, e.g.

create table Settings
(
  settings_id primary key int not null,
  name VARCHAR(255) not null,
);

create table DoubleValues
(
  value double not null
  fk_setting int not null;
);

create table ColorValues
(
  value char(8) not null
  fk_setting int not null;
);

..

Another way would be to create a table consisting of one row with a column for every setting. This way you have proper typing and can add check constraints at database level. But I consider this one as worse to maintain and to extend, so I would prefer the first one, but as always, it depends on your specific needs.

Another way would be to use a simple text file and read the settings into a hashtable which will be by far the fastest way. Maybe you can have a look at a noSQL database like MongoDb or CouchDb.

Think if your settings are mostly static or how often new settings keys are inserted or removed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文