profile.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2014-2016 OpenMarket Ltd
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from ._base import SQLBaseStore
  16. class ProfileStore(SQLBaseStore):
  17. def create_profile(self, user_localpart):
  18. return self._simple_insert(
  19. table="profiles",
  20. values={"user_id": user_localpart},
  21. desc="create_profile",
  22. )
  23. def get_profile_displayname(self, user_localpart):
  24. return self._simple_select_one_onecol(
  25. table="profiles",
  26. keyvalues={"user_id": user_localpart},
  27. retcol="displayname",
  28. desc="get_profile_displayname",
  29. )
  30. def set_profile_displayname(self, user_localpart, new_displayname):
  31. return self._simple_update_one(
  32. table="profiles",
  33. keyvalues={"user_id": user_localpart},
  34. updatevalues={"displayname": new_displayname},
  35. desc="set_profile_displayname",
  36. )
  37. def get_profile_avatar_url(self, user_localpart):
  38. return self._simple_select_one_onecol(
  39. table="profiles",
  40. keyvalues={"user_id": user_localpart},
  41. retcol="avatar_url",
  42. desc="get_profile_avatar_url",
  43. )
  44. def set_profile_avatar_url(self, user_localpart, new_avatar_url):
  45. return self._simple_update_one(
  46. table="profiles",
  47. keyvalues={"user_id": user_localpart},
  48. updatevalues={"avatar_url": new_avatar_url},
  49. desc="set_profile_avatar_url",
  50. )