Skip to content

Create a SQL table from CSV using Node.js script

Notifications You must be signed in to change notification settings

clementherve/csv2sql

 
 

Repository files navigation

CodeQL Jest

CSV-TO-SQL

Create a MySQL table from any CSV using javascript.

Setup

    git clone https://github.com/clementherve/csv2sql.git
    pnpm i
    pnpm build:watch

Testing

    pnpm tests
    # or
    pnpm run tests:watch

Usage

Run the following command and the SQL file should be generated.

    node ./out/src/cli.js <csv file>

Example

The file ./example/example.csv

A; B; C; D
0; 1; 2; hoy
; 1; 3; hoy
2; 2; 5; h'ay

will be transformed to

drop table if exists `example`;
create table if not exists `example` (
	`A` int unique,
	`B` int not null,
	`C` int unique not null,
	`D` text not null
);
insert into `example`
	(`A`, `B`, `C`, `D`)
 values
	(0, 1, 2, 'hoy'),
	(null, 1, 3, 'hoy'),
	(2, 2, 5, 'h\'ay');

About

Create a SQL table from CSV using Node.js script

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 90.5%
  • JavaScript 9.5%