1

I want to add a column on a table for the visibility. I like the standard YouTube approach, where an item can be public, private or unlisted. I've never done something like this before so I'm curious as to how others may have done it, and what the tradeoffs were for them, before I implement it in my app.

Would it be a bad idea to store these as hard strings like public, private, unlisted, or are there better approaches?

I would be checking that field in a lot of queries, for instance in my feeds I want to show only public items, so there would have to be something like WHERE visibility = 'public' in those queries.

Lansana Camara
  • 9,497
  • 11
  • 47
  • 87

2 Answers2

1

If all interactions with the db are kept consistent, preferably with an ORM, and the list of visibility options doesn't grow exceptionally long then putting these strings directly in a "visibility" column seems perfectly reasonable to me.

user3798820
  • 111
  • 1
  • 1
  • 5
1

If you use

ENUM('unknown', 'public', 'private', 'unlisted')

you get the advantage of using human readable stuff, such as exactly the same

WHERE visibility = 'public'

and the advantage of taking only 1 byte to store the info.

(Some people think ENUM is bad; I don't think so.)

Rick James
  • 135,179
  • 13
  • 127
  • 222
  • I like this approach. I don't think an ENUM will ever be a limitation, this is a very simple use case that won't ever really need to change. Thanks. – Lansana Camara Mar 09 '18 at 16:06