From JSON to SQL: The Road to Efficient Icon Management

Today, I made great strides in processing my list of Material UI icons and integrating them into a database. I started with a well-organized JSON file, categorizing everything into seven distinct groups. The focus of my work was generating SQL scripts for importing this data efficiently. I’ve designed the database to run multiple times while ensuring that it only inserts data if it doesn’t already exist. This thoughtful setup empowers me to modify existing data without the concern of accidental overwrites—unless I choose to completely rebuild the database from scratch, which is a task I’m currently embracing.

As a result of my efforts, I generated over 30,000 files for the database. Initially, I considered running each script individually using the mysql2 package, but I quickly realized that this could take one or two hours—definitely not the most efficient approach! So, I took the initiative to restructure my process, enabling batch scripts to run multiple queries simultaneously. This change not only streamlined my workflow but also simplified version control; instead of tracking 30,000 files, I only needed to manage a few.

While implementing this, I encountered challenges with running multiple queries, even something as straightforward as select 1; select 2, which resulted in errors. However, I remained determined to solve the issue. During my research, I came across a discussion where @notthelewis had reported a similar problem a couple of years ago regarding multiple statements in one prepared statement (Issue #1490). The recommended solution was to use query instead of execute, and I was pleased to find that it worked for me as well. In a lighthearted moment, I responded in the discussion with, “I am the Lewis,” and expressed my gratitude for the helpful fix.

I was gearing up to import around 3.5 megabytes of queries into the database. My next step was to set up API endpoints to facilitate data requests and modifications, adhering to REST API conventions. I successfully created 15 endpoints, allowing for a variety of operations on the data. However, since it was getting late, I didn’t have the opportunity to test them yet. The PHP files are all set up and ready for action, just waiting to be called via the RTK Query apiSlice. This progress is a significant step towards enhancing the functionality of my project!

icon/_routes.php
<?php
function get_routes()
{
    return [
        '/sets\/([^\/]+)$/' => [
            'GET' => ['set-get.php', 'setId'],
            'PUT' => ['set-update.php', 'setId'],
        ],
        '/sets\/([^\/]+)\/icons$/' => [
            'GET' => ['set-icons-list.php', 'setId'],
        ],
        '/sets\/([^\/]+)\/icons\/([^\/]+)$/' => [
            'GET' => ['set-icons-get.php', 'setId', 'iconId'],
            'PUT' => ['set-icons-update.php', 'setId', 'iconId'],
        ],
        '/sets\/([^\/]+)\/tags$/' => [
            'GET' => ['set-tags-list.php', 'setId'],
            'POST' => ['set-tags-create.php', 'setId'],
        ],
        '/sets\/([^\/]+)\/tags\/([^\/]+)$/' => [
            'GET' => ['set-tags-get.php', 'setId', 'tagId'],
            'PUT' => ['set-tags-update.php', 'setId', 'tagId'],
            'DELETE' => ['set-tags-delete.php', 'setId', 'tagId'],
        ],
        '/sets\/([^\/]+)\/filters$/' => [
            'GET' => ['set-filters-list.php', 'setId'],
            'POST' => ['set-filters-create.php', 'setId'],
        ],
        '/sets\/([^\/]+)\/filters\/([^\/]+)$/' => [
            'GET' => ['set-filters-get.php', 'setId', 'filterId'],
            'PUT' => ['set-filters-update.php', 'setId', 'filterId'],
            'DELETE' => ['set-filters-delete.php', 'setId', 'filterId'],
        ],
    ];
}

Recently, I’ve been exploring OpenAPI, and from my quick review of the OpenAPI specification, it seems to serve as a comprehensive description of an API’s endpoints, the structure of expected data, and the format of returned data. It reminds me of the old Web Services Description Language (WSDL) used in the Microsoft .NET platform.

While OpenAPI appears to be a “nice to have,” I currently don’t see an immediate benefit since I lack public consumers for my API. However, I noticed that the Redux Toolkit offers code generation capabilities that integrate with OpenAPI, which could be useful. I plan to investigate this further as I focus on finalizing the Icons interface. This integration might enhance my workflow and ensure my API remains robust and well-documented for future users.

Microsoft Designer: Image Creator Prompt

Generate an image of a modern programmer at a desk, surrounded by open coding screens and a visual database with icons. The workspace should include digital representations of REST API endpoints, SQL queries, and a JSON file, with code snippets floating above the desk. In the background, showcase an open creative space labeled ‘Studio 330’ with modern tech equipment, signifying a Maker Space. “Studio 330” is a part of a library that has 3D printers. laser cutters, and sewing machines. The mood should be productive and innovative, combining technology and creativity.

Tomorrow promises to be an exciting and busy day! The grand opening of the Maker Space and Memory Lab at Samuels Public Library, dubbed Studio 330, is set for 3:00 PM. This innovative space will likely offer the community various resources and programs, fostering creativity and learning. Following that, I’ll be attending an emergency board meeting of the trustees at 4:30 PM. Balancing the fun of the opening with the responsibilities of the meeting makes for a well-rounded day of community engagement!

Discover more from Lewis Moten

Subscribe now to keep reading and get access to the full archive.

Continue reading