将设置存储在数据库中
有人可以告诉我在一个文件中存储许多不同设置的最佳方法是什么吗 数据库?我应该使用一张包含 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为最好的方法是为每种类型的设置创建一个字段。这样做的作用是,
,等等
the best I think is to create a field for each type of setting. What does this do is,
ETC
是的,这可行,但缺点是设置值没有正确的类型。您必须将所有内容声明为 VARCHAR,您的应用程序必须检查值的有效性。
当然,可以为每种设置类型创建一个表,例如,
另一种方法是为每个设置创建一个包含一行和一列的表。这样您就可以进行正确的输入,并可以在数据库级别添加检查约束。但我认为这个更难维护和扩展,所以我更喜欢第一个,但一如既往,这取决于您的具体需求。
另一种方法是使用一个简单的文本文件并将设置读取到哈希表中,这将是迄今为止最快的方法。也许您可以看看像 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.
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.