sqlite-map-parser
$
npx mdskill add elizaOS/eliza/sqlite-map-parserParse SQLite databases by exploring schemas first, then extracting data into structured JSON.
SKILL.md
.github/skills/sqlite-map-parserView on GitHub ↗
---
name: sqlite-map-parser
description: Parse SQLite databases into structured JSON data. Use when exploring unknown database schemas, understanding table relationships, and extracting map data as JSON.
---
# SQLite to Structured JSON
Parse SQLite databases by exploring schemas first, then extracting data into structured JSON.
## Step 1: Explore the Schema
Always start by understanding what tables exist and their structure.
### List All Tables
```sql
SELECT name FROM sqlite_master WHERE type='table';
```
### Inspect Table Schema
```sql
-- Get column names and types
PRAGMA table_info(TableName);
-- See CREATE statement
SELECT sql FROM sqlite_master WHERE name='TableName';
```
### Find Primary/Unique Keys
```sql
-- Primary key info
PRAGMA table_info(TableName); -- 'pk' column shows primary key order
-- All indexes (includes unique constraints)
PRAGMA index_list(TableName);
-- Columns in an index
PRAGMA index_info(index_name);
```
## Step 2: Understand Relationships
### Identify Foreign Keys
```sql
PRAGMA foreign_key_list(TableName);
```
### Common Patterns
**ID-based joins:** Tables often share an ID column
```sql
-- Main table has ID as primary key
-- Related tables reference it
SELECT m.*, r.ExtraData
FROM MainTable m
LEFT JOIN RelatedTable r ON m.ID = r.ID;
```
**Coordinate-based keys:** Spatial data often uses computed coordinates
```python
# If ID represents a linear index into a grid:
x = id % width
y = id // width
```
## Step 3: Extract and Transform
### Basic Pattern
```python
import sqlite3
import json
def parse_sqlite_to_json(db_path):
conn = sqlite3.connect(db_path)
conn.row_factory = sqlite3.Row # Access columns by name
cursor = conn.cursor()
# 1. Explore schema
cursor.execute("SELECT name FROM sqlite_master WHERE type='table'")
tables = [row[0] for row in cursor.fetchall()]
# 2. Get dimensions/metadata from config table
cursor.execute("SELECT * FROM MetadataTable LIMIT 1")
metadata = dict(cursor.fetchone())
# 3. Build indexed data structure
data = {}
cursor.execute("SELECT * FROM MainTable")
for row in cursor.fetchall():
key = row["ID"] # or compute: (row["X"], row["Y"])
data[key] = dict(row)
# 4. Join related data
cursor.execute("SELECT * FROM RelatedTable")
for row in cursor.fetchall():
key = row["ID"]
if key in data:
data[key]["extra_field"] = row["Value"]
conn.close()
return {"metadata": metadata, "items": list(data.values())}
```
### Handle Missing Tables Gracefully
```python
def safe_query(cursor, query):
try:
cursor.execute(query)
return cursor.fetchall()
except sqlite3.OperationalError:
return [] # Table doesn't exist
```
## Step 4: Output as Structured JSON
### Map/Dictionary Output
Use when items have natural unique keys:
```json
{
"metadata": {"width": 44, "height": 26},
"tiles": {
"0,0": {"terrain": "GRASS", "feature": null},
"1,0": {"terrain": "PLAINS", "feature": "FOREST"},
"2,0": {"terrain": "COAST", "resource": "FISH"}
}
}
```
### Array Output
Use when order matters or keys are simple integers:
```json
{
"metadata": {"width": 44, "height": 26},
"tiles": [
{"x": 0, "y": 0, "terrain": "GRASS"},
{"x": 1, "y": 0, "terrain": "PLAINS", "feature": "FOREST"},
{"x": 2, "y": 0, "terrain": "COAST", "resource": "FISH"}
]
}
```
## Common Schema Patterns
### Grid/Map Data
- Main table: positions with base properties
- Feature tables: join on position ID for overlays
- Compute (x, y) from linear ID: `x = id % width, y = id // width`
### Hierarchical Data
- Parent table with primary key
- Child tables with foreign key reference
- Use LEFT JOIN to preserve all parents
### Enum/Lookup Tables
- Type tables map codes to descriptions
- Join to get human-readable values
## Debugging Tips
```sql
-- Sample data from any table
SELECT * FROM TableName LIMIT 5;
-- Count rows
SELECT COUNT(*) FROM TableName;
-- Find distinct values in a column
SELECT DISTINCT ColumnName FROM TableName;
-- Check for nulls
SELECT COUNT(*) FROM TableName WHERE ColumnName IS NULL;
```
More from elizaOS/eliza
- ac-branch-pi-modelAC branch pi-model power flow equations (P/Q and |S|) with transformer tap ratio and phase shift, matching `acopf-math-model.md` and MATPOWER branch fields. Use when computing branch flows in either direction, aggregating bus injections for nodal balance, checking MVA (rateA) limits, computing branch loading %, or debugging sign/units issues in AC power flow.
- academic-pdf-redactionRedact text from PDF documents for blind review anonymization
- ada-plan-view-accessibilityUse when checking simplified ADA-derived plan-view bathroom accessibility constraints such as turning space, door clear width, toilet centerline, grab bars, and lavatory knee/toe clearance.
- analyze-ciAnalyze failed GitHub Action jobs for a pull request.
- architectural-dxf-extractionUse when extracting plan-view architectural geometry from DXF files with semantic CAD layers, especially when outputs must normalize rooms, doors, fixtures, clearances, and grab bars into machine-checkable JSON.
- attitude-controller-plannerUse this skill when implementing the inner control loop for a quadrotor — attitude (roll/pitch/yaw) PID control and attitude planning (converting desired acceleration to desired Euler angles). Covers gain layout, integral reset pattern, and the attitude planner inverse kinematics.
- azure-bgpAnalyze and resolve BGP oscillation and BGP route leaks in Azure Virtual WAN–style hub-and-spoke topologies (and similar cloud-managed BGP environments). Detect preference cycles, identify valley-free violations, and propose allowed policy-level mitigations while rejecting prohibited fixes.
- box-least-squaresBox Least Squares (BLS) periodogram for detecting transiting exoplanets and eclipsing binaries. Use when searching for periodic box-shaped dips in light curves. Alternative to Transit Least Squares, available in astropy.timeseries. Based on Kovács et al. (2002).
- browser-testingVERIFY your changes work. Measure CLS, detect theme flicker, test visual stability, check performance. Use BEFORE and AFTER making changes to confirm fixes. Includes ready-to-run scripts: measure-cls.ts, detect-flicker.ts
- cache-policy-comparisonCompare and implement eviction policies (LRU, LFU, FIFO, S3FIFO, ARC) for bounded-capacity caches. Use when choosing or implementing an eviction policy for a buffer pool, page cache, CDN edge, or LLM KV cache, or when writing a replay simulator that supports multiple policies. Clarifies recency vs frequency semantics, queue topology, saturating counters, ghost buffers, and the second-chance rule that distinguishes modern FIFO-family policies from classic LRU.