与Facebook相似的通知系统的数据库模式 [英] Database Schema For Notification System Similar to Facebooks

查看:587
本文介绍了与Facebook相似的通知系统的数据库模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计一个类似于Facebook的通知系统,我已经到了一个砖墙。我的要求是能够支持无限数量的可能需要呈现不同类型的元数据的通知类型。

I am trying to design a notification system similar to facebook and I have reached a bit of a brick wall. My requirement is to be able to support an infinite number of notification types that may have different types of meta data required to be rendered.

我在想我会设计模式如下:

I'm thinking that I will design the schema as follows:

**Notification**
Id (int)
TypeId (int)
RecipientId (int)
SenderId (int)
SendDateTime (DateTime)
Read (bool)
MessageData (...Blob?)
Deleted (bool)

**NotificationType**
Id
Name
Description

我真的想尝试避免在我的数据库中存储HTML字符串,但是我也不太喜欢存储blob。

I really want to try to avoid storing HTML strings in my database, however, I also am not particularly fond of storing blobs either.

可能我可以查看NotificationType表,并引用另一个存储特定于该类型的数据的表,但这意味着每次创建新的通知类型时,我都需要创建一个新的表。我相信我也会把自己变成一个必须编写动态SQL来获取数据的世界。

It is possible that I could do a look up on the NotificationType table and reference another table that stores data specific to that type, however, that would mean that everytime that I created an new notificationtype i would need to create a new table. I believe that I would also be getting myself into a world of having to write dynamic SQL to get the data out.

有没有人对我有任何建议? >

Does anyone have any suggestions for me?

推荐答案

这是我如何解决这个问题。

Here is how I ended up solving this problem.

我决定使用字典存储数据是每个通知类型唯一的。然后我将该字典对象序列化为二进制字符串,并将其存储在数据库中以及每个通知。我有一个模板分配给每个通知类型,包含占位符即。 '{song-title}',我可以快速替换我的字典对象的值。

I decided to use a dictionary to store data that is unique to each notification type. I then serialize that dictionary object into a binary string and store that in the database along with each notification. I have a template assigned to each notification type that contains place-holders ie. '{song-title}' that I can quickly replace with values from my dictionary object.

这篇关于与Facebook相似的通知系统的数据库模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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