Go language. About runes (data type), PostgreSQL and JS

If you are making a Go network application that works with databases and/or javascript, you need to be careful when using the rune data type.

For example, PostgreSQL does not have a data type that matches rune; There are options for storing rune:

  1. store in CHAR(1) – then you will need to convert every time you unload from the database like this: []rune(symbolStr)[0]
  2. store in BYTEA; unload via w…. make([]byte, 4)
  3. or a slightly less obvious variant – store in the database as INT; which is the most relevant.

Plus… Javascript can’t handle runes either. I have to render the output like this: String.fromCharCode(.Icon);

By the way… It’s funny, not all emoji (unicode characters like ) can be stored in rune. Because some of them exceed the size of rune, because they use an extra Unicode selector:

  • “🏘️” houses (U+1F3D8 U+FE0F)
  • “⛰️” mountain (U+26F0 U+FE0F)
  • “🏔️” mountain with snow (U+1F3D4 U+FE0F)

And it’s not just emoji, but just some basic Unicode characters.

So you have to be careful with rune.

This entry was posted in Go (en). Bookmark the permalink.

Leave a Reply

🇬🇧 Attention! Comments with URLs/email are not allowed.
🇷🇺 Комментарии со ссылками/email удаляются автоматически.