Messages: Query a user's chats

徘徊边缘 提交于 2020-01-24 01:42:06

问题


For an app like iOS Messages:

  1. How should I design the server database queries & schema?

    Queries

    • Create a user.
    • Get a user's chats.
    • Get the messages between two users.
    • Add a message to a chat (creating the chat if it doesn't yet exist).

    Note:

    • Every chat only has two users (no group chats).
    • Every chat's id equals this unique unordered pairing function applied to user_id & with_id.
  2. How should I query a user's chats, each with its latest message?

    Example User Interface (UI)

See my design & query on SQLFiddle. It works, but how can I make it better?

来源:https://stackoverflow.com/questions/22367688/messages-query-a-users-chats

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!