shanescott.sql-data-exporter
1.2.3
dotnet tool install --global shanescott.sql-data-exporter --version 1.2.3
dotnet new tool-manifest
dotnet tool install --local shanescott.sql-data-exporter --version 1.2.3
#tool dotnet:?package=shanescott.sql-data-exporter&version=1.2.3
nuke :add-package shanescott.sql-data-exporter --version 1.2.3
CLI Tool Get Table Data - Project Root
This repository contains a .NET CLI tool for exporting SQL Server table data to JSON format and generating SQL scripts for database schema and data migration.
📁 Repository Structure
cliToolGetTableData/
├── cli-sql-plan.md # Original project plan and architecture
├── cli-developer-setup.md # Developer setup documentation
├── IMPLEMENTATION_SUMMARY.md # Implementation summary and status
├── README.md # This file
└── sql-table-export/ # Main CLI tool project
├── Commands/ # CLI command implementations
├── Configuration/ # Configuration management
├── Models/ # Data models
├── Services/ # Business logic services
├── Program.cs # Application entry point
├── README.md # Tool documentation
├── QUICKSTART.md # Quick start guide
└── EXAMPLES.md # Usage examples
🚀 Quick Start
1. Navigate to the Project
cd sql-table-export
2. Build the Project
dotnet build
3. Install the Tool
# Install from NuGet.org
dotnet tool install --global shanescott.sql-data-exporter
# Or run from source
dotnet run -- generate-json --table users
4. Use the Tool
# Set connection string
$env:SQL_CONNECTION_STRING = "Server=localhost;Database=MyDb;Integrated Security=true;"
# Generate JSON from a table
shanescott.sql-data-exporter generate-json --table users
# Generate SQL script from the exported JSON
shanescott.sql-data-exporter generate-sql --table users
📖 Documentation
- cli-sql-plan.md - Complete project plan with architecture and technical details
- IMPLEMENTATION_SUMMARY.md - Implementation status and summary
- sql-table-export/README.md - Complete tool documentation
- sql-table-export/QUICKSTART.md - 5-minute quick start guide
- sql-table-export/EXAMPLES.md - 30+ usage examples
✨ Features
- ✅ Generate JSON from SQL Server table structure and data
- ✅ Generate SQL scripts (CREATE TABLE + INSERT) from exported JSON
- ✅ Complete metadata extraction (columns, PKs, FKs, constraints)
- ✅ Flexible connection string configuration (CLI, env var, config file)
- ✅ Row filtering with WHERE clauses
- ✅ Row limiting for large tables
- ✅ Custom input/output paths
- ✅ Proper data type conversion
- ✅ Comprehensive error handling
- ✅ Support for DROP TABLE IF EXISTS option
🎯 Usage Examples
Generate JSON
shanescott.sql-data-exporter generate-json --table users
Generate JSON with Options
shanescott.sql-data-exporter generate-json \
--connection "Server=localhost;Database=MyDb;Integrated Security=true;" \
--table orders \
--schema sales \
--limit 100 \
--where "status = 'pending'" \
--output ./exports/pending-orders.json
Generate SQL Script
shanescott.sql-data-exporter generate-sql --table users
Generate SQL Script with Options
shanescott.sql-data-exporter generate-sql \
--table orders \
--schema sales \
--drop-if-exists \
--input ./exports/orders.json \
--output ./sql/orders.sql
Output Format
{
"metadata": {
"schema": "dbo",
"tableName": "users",
"exportedAt": "2025-11-25T21:04:00Z",
"rowCount": 150,
"totalRowsInTable": 1000,
"primaryKeys": ["userId"],
"foreignKeys": [...]
},
"columns": [...],
"data": [...]
}
🛠️ Technology Stack
- .NET 8.0 - Application framework
- System.CommandLine - CLI argument parsing
- Microsoft.Data.SqlClient - SQL Server connectivity
- System.Text.Json - JSON serialization
- Microsoft.Extensions.Configuration - Configuration management
📦 Installation
From NuGet.org (Recommended)
dotnet tool install --global shanescott.sql-data-exporter
From Source
cd sql-table-export
dotnet build
dotnet run -- --help
# Run commands from source
dotnet run -- generate-json --table users
dotnet run -- generate-sql --table users
Package Information
- Package Name: shanescott.sql-data-exporter
- Command Name: shanescott.sql-data-exporter
- NuGet Page: https://www.nuget.org/packages/shanescott.sql-data-exporter
✅ Project Status
Status: ✅ Complete and Published to NuGet.org
Build Status: ✅ Builds Successfully
NuGet Package: ✅ Published at https://www.nuget.org/packages/shanescott.sql-data-exporter
Implementation Date: November 25, 2025
All planned features have been implemented, tested, and published. See IMPLEMENTATION_SUMMARY.md for details.
📝 Development Notes
This project follows:
- .NET 8 best practices
- Async/await patterns
- Service-oriented architecture
- Comprehensive error handling
- User-defined coding standards:
- camelCase for column names
- snake_case for table names
- sp. prefix for stored procedures
- No Entity Framework (direct SQL queries)
🧩 Available Commands
generate-json
Generates JSON data from SQL Server tables.
shanescott.sql-data-exporter generate-json --table "table_name" [options]
generate-sql
Generates SQL scripts (CREATE TABLE + INSERT) from exported JSON data.
shanescott.sql-data-exporter generate-sql --table "table_name" [options]
migrate
Migrates data between SQL Server databases using JSON exports.
shanescott.sql-data-exporter migrate [subcommand] [options]
🔗 Related Files
- Project Plan: cli-sql-plan.md
- Implementation Summary: IMPLEMENTATION_SUMMARY.md
- Tool Documentation: sql-table-export/README.md
- Quick Start: sql-table-export/QUICKSTART.md
- Examples: sql-table-export/EXAMPLES.md
🎓 Learning Resources
The project demonstrates:
- Building .NET CLI tools with System.CommandLine
- SQL Server metadata extraction
- JSON serialization best practices
- Configuration management patterns
- Service layer architecture
- Error handling strategies
📞 Support
For detailed usage instructions, troubleshooting, and examples, see the documentation in the sql-table-export directory.
Ready to use! Navigate to sql-table-export and follow the QUICKSTART.md guide.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
This package has no dependencies.
v1.2.3: Update to README.md to reflect additional features.
v1.2.2: Fixed IDENTITY column type - now uses INT instead of DECIMAL for identity columns, which SQL Server requires.
v1.2.1: Fixed SQL generation bug where NVARCHAR columns with MAX length (-1) produced invalid syntax like NVARCHAR(-1) or NVARCHAR({0}). Now correctly outputs NVARCHAR(MAX).
v1.2.0: Renamed 'export' command to 'generate-json' for consistency. Added new 'generate-sql' command to create SQL scripts (CREATE TABLE + INSERT) from exported JSON data. Supports DROP TABLE IF EXISTS option and custom input/output paths.
v1.1.0: Added data migration feature. New 'migrate' command with 'generate' and 'execute' subcommands. Supports flexible column mapping, data transformation, default values, and transaction-safe execution.