SQL to Magic Converter
Transform SQL database dumps into Magic scripting language formats including Python dictionaries, Ruby hashes, and JavaScript objects
SQL Input
Magic Output
About SQL to Magic Converter
Convert SQL database dumps (CREATE TABLE and INSERT statements) to Magic scripting language formats. Supports Python dictionaries, Ruby hashes, and JavaScript objects for easy integration into your applications and scripts.
Key Features
- Multiple Languages: Python, Ruby, and JavaScript output formats
- Automatic Type Detection: Converts numbers, booleans, strings, and null values
- Usage Examples: Optional code comments with usage examples
- Clean Syntax: Properly formatted and indented code
- Smart Parsing: Extracts column names and data from SQL dumps
- File Download: Save as .py, .rb, or .js file
How to Use
- Input SQL Data: Paste your SQL CREATE TABLE and INSERT statements or upload a .sql file
- Choose Format: Select Python, Ruby, or JavaScript output format
- Configure Options: Toggle comments and usage examples
- Copy or Download: Use the Copy or Download button to save your code
Output Formats
Python (List of Dictionaries):
- List containing dictionary objects
- String keys with proper quoting
- None for null values
- True/False for booleans
- Perfect for data processing and analysis
Ruby (Array of Hashes):
- Array containing hash objects
- Symbol keys for better performance
- nil for null values
- true/false for booleans
- Ideal for Rails applications and Ruby scripts
JavaScript (Array of Objects):
- Array containing object literals
- Property names without quotes (when valid)
- null for null values
- true/false for booleans
- Perfect for Node.js and web applications
Example Conversion
SQL Input:
CREATE TABLE mtg_cards (
id INT,
name VARCHAR(100),
mana_cost VARCHAR(20),
card_type VARCHAR(50)
);
INSERT INTO mtg_cards VALUES (1, 'Lightning Bolt', '{R}', 'Instant');
INSERT INTO mtg_cards VALUES (2, 'Serra Angel', '{3}{W}{W}', 'Creature - Angel'); Python Output:
# Magic: The Gathering card data from mtg_cards
# Python dictionary format
mtg_cards_data = [
{
'id': 1,
'name': 'Lightning Bolt',
'mana_cost': '{R}',
'card_type': 'Instant',
},
{
'id': 2,
'name': 'Serra Angel',
'mana_cost': '{3}{W}{W}',
'card_type': 'Creature - Angel',
}
]
# Usage example:
# for card in mtg_cards_data:
# print(f"{card['id']} - {card['name']}") Ruby Output:
# Magic: The Gathering card data from mtg_cards
# Ruby hash format
mtg_cards_data = [
{
id: 1,
name: 'Lightning Bolt',
mana_cost: '{R}',
card_type: 'Instant',
},
{
id: 2,
name: 'Serra Angel',
mana_cost: '{3}{W}{W}',
card_type: 'Creature - Angel',
}
]
# Usage example:
# mtg_cards_data.each do |card|
# puts "#{card[:id]} - #{card[:name]}"
# end JavaScript Output:
// Magic: The Gathering card data from mtg_cards
// JavaScript object format
const mtgCardsData = [
{
id: 1,
name: 'Lightning Bolt',
mana_cost: '{R}',
card_type: 'Instant',
},
{
id: 2,
name: 'Serra Angel',
mana_cost: '{3}{W}{W}',
card_type: 'Creature - Angel',
}
];
// Usage example:
// mtgCardsData.forEach(card => {
// console.log(`${card.id} - ${card.name}`);
// }); Common Use Cases
- Magic: The Gathering Apps: Convert card databases for MTG applications
- Data Migration: Move data from SQL to NoSQL databases
- Testing: Create test fixtures and mock data
- API Development: Generate seed data for APIs
- Web Applications: Convert database dumps to JSON-like structures
- Data Analysis: Import SQL data into Python/Ruby scripts
Type Conversion
- Numbers: Integers and decimals are converted to native numeric types
- Booleans: true/false, 1/0 → True/False (Python), true/false (Ruby/JS)
- Strings: Text values are properly quoted and escaped
- Null Values: NULL → None (Python), nil (Ruby), null (JavaScript)
Integration Examples
Python - Pandas DataFrame:
import pandas as pd # Use the converted data df = pd.DataFrame(mtg_cards_data) print(df.head())
Ruby on Rails - Seed Data:
# db/seeds.rb mtg_cards_data.each do |card_data| MtgCard.create!(card_data) end
JavaScript - MongoDB:
// Insert into MongoDB
await db.collection('mtg_cards').insertMany(mtgCardsData); Privacy & Security
All conversions happen locally in your browser. Your SQL data is never uploaded to any server, ensuring complete privacy and security.
