4 ms·
I don’t think so. Without digging into the source - and I intend to do that, if someone more familiar with this doesn’t chime in - it appears that it’s targete
by Ancapistani 6y ago
I don’t think so.
Without digging into the source - and I intend to do that, if someone more familiar with this doesn’t chime in - it appears that it’s targeted at reducing resource consumption.
UTF-8 can encode emoji fine. Consider (“ grinning face with smiling eyes”), which is `\xF0\x9F\x98\x81` in bytes. That’s four bytes. From the pg-emoji Readme:
> A lookup-table is constructed from the first 1024 emojis from [https://unicode.org/Public/emoji/13.1/emoji-test.txt https://unicode.org/Public/emoji/13.1/emoji-test.txt], where each emoji maps to a unique 10 bit sequence.
> The input data is split into 10 bit fragments, mapped to the corresponding emojis.
If my understanding is correct thus far, then instead of storing four bytes for each emoji, you’d only need 10 bits.
I don’t know where this would be worthwhile.
I’m further confused by the purpose of `to_text()` and `from_text()`. Their example shows a string composed of mostly Latin characters being encoded into a string of emoji and back.
- JoelJacobson 6y ago> I’m further confused by the purpose of `to_text()` and `from_text()`. Their example shows a string composed of mostly Latin characters being encoded into a string of emoji and back. This is meant to be used if you want to pass some text containing escape characters or perhaps JSON. Note also that the first emoji is a checksum, which might be useful if you want to make sure a user correctly copy/pasted a string, as opposed to sending a raw text string (without checksum).
- Ancapistani 6y ago> This is meant to be used if you want to pass some text containing escape characters or perhaps JSON. I guess I don’t understand how this is an improvement. Perhaps it’s because I typically interact with the DB through a language-specific library/protocol like Python’s DB API, which handles escaping strings and parameterization without my really having to think about it. Could you provide a specific example of when this might solve a real-world problem?
- JoelJacobson 6y agoOne intended use-case for the from_text()/to_text() functions is when information is manually copied from some place and pasted somewhere else, where you are worried the user might make a mistake and select the wrong piece of text. For instance, if you instruct the user to copy "this text string" and paste it somewhere, some users might copy the text string with the double-quotes and some without them. By instead emoji encode the string, the receiver of the copied emoji string can detect if not all emojis were copied.
- Ancapistani 6y agoThis strikes me as data validation, which should reside in the application layer - I don't see how pg-emoji helps in any way. Further... if the receiver can validate the encoded string itself, they implicitly already have the string. Why require the user to copy/paste at all? If you meant "Ensure that the user hasn't copied quotation marks as well", then we're back to it being application logic. If I'm understanding correctly that the primary benefit is that there is a checksum, then there are already many solutions for this in common use - base58checksum, as used to ensure the validity of Bitcoin addresses, comes immediately to mind. I wrote an implementation of that quite a while ago: https://github.com/lyndsysimon/cryptocoin/blob/primary/cryptocoin/base58.py https://github.com/lyndsysimon/cryptocoin/blob/primary/crypt... Please don't misunderstand, I'm in no way intending to be argumentative. I don't understand the practical use of this project, which leads me to believe that there is a problem being solved that I lack the context to identify.
- JoelJacobson 6y agoIn my case, PostgreSQL is the application layer, the application is written in database functions, and I’m using PostgREST to expose it to my front-end.
- Ancapistani 6y agoAh, that makes more sense then.
- MrStonedOne 6y agothis is not an emoji support system or a system for storing emojis. Its a system for encoding data as emojis. "this is a string" => some emojis. ie baseemoji or base1024