GithubHelp home page GithubHelp logo

csv-to-sql's Introduction

CSV to SQL

Setup

  • run install_dependencies.sh
  • compile: make clean && make init

How to use

Requires 3 arguments:

  1. path to csv i.e ./test.csv
  2. name of database table to create i.e test
  3. json schema
./csv-sql ./example.csv example ./example.json
row_number,uuid,start_date,end_date,uuid_2
1,83e0721f-f426-46f8-b2fa-6b3ed6246860,2020-12-23,2020-12-26,2687ec46-0e3d-4842-b582-091050c31252
2,48540f8a-e7a9-4670-8283-6452895f9933,2021-01-11,2021-01-04,3c6627a6-1bae-4865-88b5-95df12cf340b
3,653833a1-4d4b-4b6c-8c6f-08c00e82c6cb,2021-01-05,2020-12-29,242b03bf-887f-4486-8ee6-c412d9da1156

This would output the file "example.sql":

CREATE TABLE "example" ("row_number" INTEGER, "uuid" TEXT, "start_date" TIMESTAMP, "end_date" TIMESTAMP, "uuid_2" TEXT);

INSERT INTO "example" ("row_number", "uuid", "start_date", "end_date", "uuid_2") VALUES
('1', '83e0721f-f426-46f8-b2fa-6b3ed6246860', '2020-12-23T00:00:00Z', '2020-12-26T00:00:00Z', '2687ec46-0e3d-4842-b582-091050c31252'),
('2', '48540f8a-e7a9-4670-8283-6452895f9933', '2021-01-11T00:00:00Z', '2021-01-04T00:00:00Z', '3c6627a6-1bae-4865-88b5-95df12cf340b'),
('3', '653833a1-4d4b-4b6c-8c6f-08c00e82c6cb', '2021-01-05T00:00:00Z', '2020-12-29T00:00:00Z', '242b03bf-887f-4486-8ee6-c412d9da1156');

JSON schema

The json provides mapping to the csv. The key is the name of the csv column.

The value is an array:

A date will be parsed to a format matching '2020-12-26T00:00:00Z'

example:

{
	"row_number": ["INTEGER", 0, "int"],
	"uuid": ["VARCHAR(50)", 1, "string"],
	"start_date": ["TIMESTAMP", 2, "date", "%Y-%m-%d"],
	"end_date": ["TIMESTAMP", 3, "date", "%Y-%m-d"],
	"uuid_2": ["TEXT", 4, "string"],
}

raw data types

"string"
"date"
"float"
"int"
"currency"
"percentage"

csv-to-sql's People

Contributors

jamesbarford avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.