Skip to content

RaiZela/CsvToSqliteMigrationUtility

Repository files navigation

CsvToSqliteMigrationUtility

A lightweight .NET utility that automatically converts CSV files into SQLite databases. It infers column types, generates tables dynamically, and inserts all rows without requiring predefined models.

✨ Features

  • 📂 CSV Upload – Accepts any CSV file with headers.
  • 🧠 Type Inference – Detects INTEGER, REAL, BOOLEAN, DATETIME, and falls back to STRING.
  • 🗄️ Dynamic Table Creation – Builds SQLite schemas on the fly, based on CSV headers and inferred types.
  • 📥 Data Insertion – Inserts rows into SQLite using parameterized SQL.
  • Generic – Works with any CSV structure, no hardcoding required.
  • 📝 Summary Report – Returns a quick overview of detected columns and types.

🛠️ Getting Started

Prerequisites

  • .NET 8 SDK
  • SQLite (included via Microsoft.Data.Sqlite NuGet package)

Installation

Clone the repository:

git clone https://github.com/yourusername/CsvToSqliteMigrationUtility.git
cd CsvToSqliteMigrationUtility

Install dependencies:

dotnet restore

🚀 Usage

Example: Process a CSV file

using var fileStream = File.OpenRead("books.csv");
var service = new FileProcessingService();

string result = await service.ProcessFileAsync(fileStream, "books.csv");

Console.WriteLine(result);

Console Output

Detected columns in 'books.csv':
Id: INTEGER
Title: STRING
Price: REAL
PublishedOn: DATETIME
IsAvailable: BOOLEAN

Generated SQLite Database

A new file named books.db will be created, containing a Books table with all imported data.


⚙️ How It Works

  1. Reads header row → extracts column names.
  2. Samples first rows → infers types for each column.
  3. Generates CREATE TABLE SQL → builds schema dynamically.
  4. Reads entire CSV → converts values to proper types.
  5. Executes INSERT INTO → adds rows into SQLite.

📂 Example CSV

Id,Title,Price,PublishedOn,IsAvailable
1,The Hobbit,12.5,1937-09-21,true
2,1984,9.99,1949-06-08,false
3,Brave New World,15.0,1932-01-01,true

📜 License

MIT License. Feel free to use and modify.

About

A lightweight .NET utility that automatically converts CSV files into SQLite databases. It infers column types, generates tables dynamically, and inserts all rows without requiring predefined models.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages