A pure SQL PostgreSQL extension to weave binary data and text into the colorful tapestry of emojis! โจ
- About โน๏ธ
- Dependencies ๐
- Installation & Usage (Docker - Recommended) ๐ณ
- Installation (Manual) โ๏ธ
- Usage ๐ก
- Documentation ๐
- Project Structure ๐
EmojigreSQL
is a pure SQL PostgreSQL extension designed to seamlessly encode/decode bytea
(binary data) and text
to/from emojis.
It utilizes a lookup table constructed from the first 1024 emojis sourced from the Unicode Emoji Test File v13.1. Each emoji in this table uniquely maps to a 10-bit sequence.
How it works:
- Input data is fragmented into 10-bit chunks.
- Each chunk is mapped to its corresponding emoji from the lookup table.
- The first emoji in the resulting sequence acts as a header:
- The first bit indicates if zero-padding was applied (1 for true).
- The remaining 9 bits form a checksum derived from the input data.
Note: If the checksum is invalid during the decoding process (e.g., due to data corruption or an incomplete sequence), the function will return
NULL
.
โ None! This extension is self-contained.
This is the easiest way to get started, as it handles all dependencies and build steps within a container.
-
Ensure Docker Desktop is running.
-
Build the Image: Open your terminal in the project root directory and run:
docker build -t emojigresql-image .
-
Run the Container:
# Replace YOUR_STRONG_PASSWORD with a password of your choice docker run --name emojigresql-db -e POSTGRES_PASSWORD=YOUR_STRONG_PASSWORD -p 5432:5432 -d emojigresql-image
-
Enable the Extension: Connect to the running container's PostgreSQL instance and enable the extension for your desired database (e.g., the default
postgres
database):# Connect to psql inside the container (enter your password when prompted) docker exec -it emojigresql-db psql -U postgres # Inside psql (prompt looks like postgres=#), run: CREATE EXTENSION emojigresql; # You can now exit psql by typing \q
-
Connect: You can now connect to the database running in Docker using any standard PostgreSQL client with these details:
- Host:
localhost
- Port:
5432
- Database:
postgres
(or any other database you create) - User:
postgres
- Password: The
YOUR_STRONG_PASSWORD
you set in step 3. - Connection URI:
postgresql://postgres:YOUR_STRONG_PASSWORD@localhost:5432/postgres
- Host:
There are two ways to manually install the extension if you have PostgreSQL installed locally, depending on your operating system and available tools.
4a. For Linux/macOS (or Windows with Git Bash/WSL/MSYS2)
This method uses the standard make
utility.
-
Prerequisites:
git
,curl
make
(usually pre-installed or available via package managers likeapt
,yum
,brew
)- PostgreSQL server development package (e.g.,
postgresql-server-dev-XX
,postgresqlXX-devel
) for your PostgreSQL version. - Ensure
pg_config
from your PostgreSQL installation is in your system's PATH.
-
Steps:
# 1. Clone the repository git clone https://github.com/VinsmokeSomya/EmojigreSQL.git # 2. Navigate into the project directory cd EmojigreSQL # 3. Compile/Generate the extension files make # 4. Install the extension (may require sudo/admin privileges) # On Linux/macOS: sudo make install # On Windows (Git Bash/WSL run as Admin): # make install # 5. (Optional) Run the installation checks make installcheck
4b. For Windows Native (CMD/PowerShell)
This method uses a PowerShell script to generate the necessary SQL file, avoiding the need for make
or a Linux-like environment. It does not automatically install the files into your PostgreSQL directory.
-
Prerequisites:
git
- PowerShell (usually built-in)
- PostgreSQL server installed (development headers not strictly required for this script, but needed to use the extension).
-
Steps:
# 1. Clone the repository git clone https://github.com/VinsmokeSomya/EmojigreSQL.git # 2. Navigate into the project directory cd EmojigreSQL # 3. Run the PowerShell build script .\build.ps1
-
Manual File Installation: After the script runs successfully, it will create
emojigresql--1.0.sql
and potentiallyemojigresql-chars.sql
. You need to manually copy these files, along withemojigresql.control
, to your PostgreSQL installation's extension directory.- Find your PostgreSQL share directory (often
C:\Program Files\PostgreSQL\XX\share
). You can runpg_config --sharedir
in a CMD/PowerShell ifpg_config
is in your PATH to find it. - Copy
emojigresql.control
to theextension
sub-directory (e.g.,...\share\extension
). - Copy
emojigresql--1.0.sql
to theextension
sub-directory. (Administrative privileges will likely be required to copy files into the Program Files directory)
- Find your PostgreSQL share directory (often
-
Enable in Database: Once the files are copied, connect to your database using
psql
or another client and runCREATE EXTENSION emojigresql;
.
Activate the extension within your PostgreSQL database:
- Connect to your database using
psql
or your preferred client. - Execute the following SQL command:
CREATE EXTENSION emoji;
Now you're ready to use the EmojigreSQL
functions!
Detailed documentation for all functions (encode
, decode
, from_text
, to_text
) can be found in the DOCUMENTATION.md file.
.
โโโ Dockerfile # ๐ณ Defines the Docker build process
โโโ Makefile # ๐ ๏ธ Build instructions for the extension
โโโ README.md # ๐ This file
โโโ build.ps1 # ๐ช Windows PowerShell build script
โโโ complain_header.sql # โ ๏ธ SQL header included in the extension script
โโโ emojigresql.control # ๐ฉ Extension control file
โโโ fetch-chars.sh # ๐ Script to download emoji list for the table
โโโ emoji-chars.sql # ๐๏ธ (Old generated file, can be ignored/deleted)
โโโ FUNCTIONS/ # โจ Directory containing SQL function definitions
โ โโโ decode.sql # โก๏ธ Decodes emojis to data
โ โโโ encode.sql # โฌ
๏ธ Encodes data to emojis
โ โโโ from_text.sql # ๐ Encodes text to emojis
โ โโโ to_text.sql # ๐ Decodes emojis to text
โโโ sql/ # ๐งช Directory for test SQL scripts
โ โโโ test.sql # โถ๏ธ Main test script
โโโ TABLES/ # ๐ Directory for table definitions
โ โโโ chars.sql # ๐ Emoji character lookup table definition
โโโ expected/ # โ
Expected output for tests
โโโ results/ # ๐ Actual output from tests
โโโ .git/ # ๐ Git directory
โโโ .gitignore # ๐ Files ignored by Git (if present)
by VinsmokeSomya