Sign In

sql-csv

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sql-csv

A simple library to run sql queries on csv files

latest
Source
npmnpm
Version
1.0.2
Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

sql-csv

sql-csv is a simple library that allows you to run SQL queries on CSV files.

Table of Contents

  • Installation
  • Usage
  • Supported SQL Syntax
  • Examples
  • Benchmark Results

Installation

You can install sql-csv using npm: npm install sql-csv

Usage

To use sql-csv, you first need to create a new instance of the CsvSql class:

const CsvSql = require('sql-csv');

const csvSql = new CsvSql('path/to/csv/file.csv');

You can also pass url to a CSV file:

const csvSql = new CsvSql('https://example.com/file.csv');

You can then run SQL queries on the CSV data using the query method:

const result = await csvSql.query('SELECT * FROM file WHERE column1 = "value"');
  • The table name in the query must match the name of the CSV file.

  • The column names in the query must match the column names in the CSV file.

  • The values in the query must be enclosed in double quotes.

  • The query must end with a semicolon.

  • The result will be an array of objects, where each object represents a row in the CSV file.

Supported SQL Syntax

sql-csv supports a subset of the SQL syntax. The following SQL statements are supported:

  • SELECT
  • FROM
  • WHERE
  • AND
  • OR
  • ORDER BY
  • GROUP BY
  • HAVING
  • LIMIT
  • OFFSET

The following operators are supported:

  • =
  • !=
  • >
  • <
  • >=
  • <=

The following functions are supported:

  • COUNT
  • MIN
  • MAX
  • AVG
  • SUM
  • DISTINCT

Examples

const result = csvSql.query('SELECT * FROM data');
const result = csvSql.query('SELECT column1, column2 FROM data');

Benchmark Results

Query 1: SELECT * FROM data

RowsTime (ms)
100019.9
1000054.7
10000063.5376
10000004528.325

Query 2: SELECT * FROM data WHERE column1 = "value"

RowsTime (ms)
10008.53
1000043.8
10000052.5
10000002330.46

FAQs

Package last updated on 26 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts