Skip to content

๐Ÿ˜ EmojigreSQL: A pure SQL PostgreSQL extension to encode/decode binary data (bytea) and text into colorful emoji sequences! โœจ Includes basic checksum validation.

License

Notifications You must be signed in to change notification settings

VinsmokeSomya/EmojigreSQL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

9 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿšฉ๐Ÿงก๐Ÿ•‰๏ธ || เคœเคฏ เคถเฅเคฐเฅ€ เคฐเคพเคฎ || ๐Ÿ•‰๏ธ๐Ÿงก๐Ÿšฉ

๐Ÿ˜ EmojigreSQL ๐Ÿ˜

A pure SQL PostgreSQL extension to weave binary data and text into the colorful tapestry of emojis! โœจ


๐Ÿ“œ Table of Contents

  1. About โ„น๏ธ
  2. Dependencies ๐Ÿ”—
  3. Installation & Usage (Docker - Recommended) ๐Ÿณ
  4. Installation (Manual) โš™๏ธ
  5. Usage ๐Ÿ’ก
  6. Documentation ๐Ÿ“š
  7. Project Structure ๐Ÿ“

โ„น๏ธ 1. About

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:

  1. Input data is fragmented into 10-bit chunks.
  2. Each chunk is mapped to its corresponding emoji from the lookup table.
  3. 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.


๐Ÿ”— 2. Dependencies

โœ… None! This extension is self-contained.


๐Ÿณ 3a. Installation & Usage (Docker - Recommended)

This is the easiest way to get started, as it handles all dependencies and build steps within a container.

  1. Ensure Docker Desktop is running.

  2. Build the Image: Open your terminal in the project root directory and run:

    docker build -t emojigresql-image .
  3. 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
  4. 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
  5. 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

โš™๏ธ 4. Installation (Manual)

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 like apt, 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 potentially emojigresql-chars.sql. You need to manually copy these files, along with emojigresql.control, to your PostgreSQL installation's extension directory.

    1. Find your PostgreSQL share directory (often C:\Program Files\PostgreSQL\XX\share). You can run pg_config --sharedir in a CMD/PowerShell if pg_config is in your PATH to find it.
    2. Copy emojigresql.control to the extension sub-directory (e.g., ...\share\extension).
    3. Copy emojigresql--1.0.sql to the extension sub-directory. (Administrative privileges will likely be required to copy files into the Program Files directory)
  • Enable in Database: Once the files are copied, connect to your database using psql or another client and run CREATE EXTENSION emojigresql;.


๐Ÿ’ก 5. Usage

Activate the extension within your PostgreSQL database:

  1. Connect to your database using psql or your preferred client.
  2. Execute the following SQL command:
CREATE EXTENSION emoji;

Now you're ready to use the EmojigreSQL functions!


๐Ÿ“š 6. DOCUMENTATION

Detailed documentation for all functions (encode, decode, from_text, to_text) can be found in the DOCUMENTATION.md file.


๐Ÿ“ 7. Project Structure

.
โ”œโ”€โ”€ 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

About

๐Ÿ˜ EmojigreSQL: A pure SQL PostgreSQL extension to encode/decode binary data (bytea) and text into colorful emoji sequences! โœจ Includes basic checksum validation.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published