問(wèn)題描述
只是一個(gè)關(guān)于存儲(chǔ)日歷數(shù)據(jù)的快速架構(gòu)問(wèn)題.
Just a quick architecture question really on storing calendar data.
基本上,我有一個(gè)租賃服務(wù)數(shù)據(jù)庫(kù).在前端,有一個(gè)日歷顯示未來(lái)每個(gè)日期的可用"或不可用".在后端,用戶可以在 jQuery 日歷上將任何日期/日期范圍設(shè)置為可用或不可用(1 或 0).
Basically, I have a database of services for rental. On the front end, there is a calendar to show either "Available" or "Unavailable" for every future date. In the back-end the user can set any date/date range to available or unavailable (1 or 0) on a jQuery calendar.
我的問(wèn)題是您將如何將這些數(shù)據(jù)存儲(chǔ)在 mysql 中并在前端檢索它?
The question I have is how would you go about storing this data in mysql and retrieving it on the front end?
可能有所有可用的日期并存儲(chǔ)不可用的日期?然后,如果它們?cè)俅卧O(shè)置為可用,則刪除該日期的記錄?
Possible have all dates available and store the unavailable dates? Then if they are set to available again, remove the record for that date?
干杯,RJ
推薦答案
可能有所有可用的日期并存儲(chǔ)不可用的日期?然后,如果它們?cè)俅卧O(shè)置為可用,則刪除該日期的記錄?
Possible have all dates available and store the unavailable dates? Then if they are set to available again, remove the record for that date?
是的,我會(huì)這樣做,除非我不會(huì)在租用到期時(shí)刪除記錄 - 您很容易知道租用已過(guò)期,因?yàn)樗沁^(guò)去的,因此您也會(huì)自動(dòng)保留租用歷史記錄.
Yes, I'd go with that, except I would not remove the record when renting expires - you'll easily know a renting expired because it's in the past, so you automatically keep the history of renting as well.
畢竟,可用日期的數(shù)量是無(wú)限的1,因此如果您反過(guò)來(lái)(和存儲(chǔ)的免費(fèi)日期),則必須人為地限制支持的日期范圍.
After all, there is infinite number of available dates1, so you'd have to artificially limit the supported range of dates if you went the other way around (and stored free dates).
1 未來(lái).而且,在某種意義上,過(guò)去也是如此.
1 In the future. And, in some sense, in the past as well.
另外,我猜您需要一些額外的信息,以防租用服務(wù)(例如租用者的姓名),如果租用由不存在的行表示,則無(wú)處存儲(chǔ)!
Also, I'm guessing you want some additional information in case a service is rented (e.g. name of the renter) and there would be nowhere to store that if renting were represented by a non-existent row!
由于租用的粒度是一整天,我覺得你看的數(shù)據(jù)庫(kù)結(jié)構(gòu)是這樣的:
Since the granularity of renting is a whole day, I think you are looking at a database structure similar to this:
注意 RENTING_DAY PK 如何自然地防止重疊.
Note how RENTING_DAY PK naturally prevents overlaps.
或者,您可以放棄 RENTING_DAY 并直接在 RENTING 中設(shè)置 START_DATE 和 END_DATE,但這需要明確的范圍重疊檢查,可能無(wú)法理想地?cái)U(kuò)展.
Alternatively, you might ditch the RENTING_DAY and have START_DATE and END_DATE directly in RENTING, but this would require explicit range overlap checks, which may not scale ideally.
這篇關(guān)于在 MySQL 中存儲(chǔ)日歷數(shù)據(jù)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!