为日历应用程序布置数据库模式 [英] Laying out a database schema for a calendar application

查看:116
本文介绍了为日历应用程序布置数据库模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个日历应用程序。它是真正重复的项目,在数据库模式的工程中抛出一个扳手。



如果用户创建一个事件,并输入它重复每个人星期一,永远?我如何存储所有的数据库?我不能创建无限的事件。我只是在那里放一个表,其中包含相关的信息,所以我可以计算在哪里所有的事件?如果是这样,我将不得不在每次用户查看日历的新部分时计算它们。



此外,当用户点击某个项目时,模式需要处理,并说编辑此项一个在序列中不是序列中的所有项目。



更新1

>我没有看过iCal。要清楚,我认为保存信息允许你计算经常性项目,并分裂任何不同的顺序是一个伟大的方式来存储它,以能够传输它。

解决方案

我在一个应用程序中,这将是太慢了,做日期数学在所有的地方。最近创建了一个日历应用程序,这是我面临的众多挑战之一。



我最终想出了一个半Hack-ish解决方案。我创建了一个event_type列。在那一列中,我有每日,每周,每月或每年。我也有一个start_date和end_date列。一切都在实际的后端代码中处理。



如果用户只编辑一个事件,我从未尝试拆分事件。在这种情况下没有必要。但是,您可以通过更改第一个的end_date来分割事件,创建具有新开始日期和结束日期的新事件,最后是刚刚选择编辑的新事件。这个过程最终会创建3个事件。



Hack-ish,我知道。我想不出一个聪明的方法来处理这个问题。


I want to write a calendar application. It is really recurring items that throw a wrench in the works for the DB schema. I would love some input on how to organize this.

What if a user creates an event, and inputs that it repeats everyone Monday, forever? How could I store all that in the database? I can't create infinite events. Do I simply put a table in there that holds the relevant info so I can calculate where all the events go? If so, I would have to calculate them every time the user views a new part of the calendar. What if they page through the months, but they have a ton of recurring items?

Also, the schema needs to handle when a user clicks an item and says "Edit this one in the sequence" not all items in the sequence. Do I then split the one item off of the sequence?

Update 1

I have not looked at iCal at all. To be clear, I think saving the info that allows you to calculate the recurring items, and splitting off any that differ from the sequence is a great way to store it to be able to transfer it. But I think that in an application, this would be too slow, to do the date math all over the place.

解决方案

I recently created a calendar application and this was one of the many challenges that I faced.

I eventually came up with a semi hack-ish solution. I created an event_type column. In that column, I had either: "daily", "weekly", "monthly", or "yearly". I also had a start_date and an end_date columns. Everything else was handled in the actual backend code.

I never tried to split an event if a user edited only one event. It wasn't necessary in the situation. However, you could split an event by changing the end_date of the first, creating a new event with a new start date and the end_date of the original, and finally, a new event for the one you just chose to edit. This process would end up creating 3 events.

Hack-ish, I know. I couldn't think of a clever way to handle this problem at the time.

这篇关于为日历应用程序布置数据库模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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