npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

xl2sql

v1.0.5

Published

A library to convert Excel / CSV files into SQL statements with a high level of control.

Downloads

11

Readme

xl2sql

xl2sql is a TypeScript library and CLI tool for parsing csv and excel files and generating SQL queries to generate tables and insert data. This stems from the common problem I have encountered of importing data from a CSV file into a database.

A key feature of this library is type parsing. From a raw file, types are deduced as best as possible through a series of strong regex checks in HCore. Xl2sql determines the correct datatype that encapsulates all other datatypes within each column. For example, if an int and a float are found in a column, the least common datatype will be a float. If an int, float and a string were found, it would be a varchar.

Installation

CLI Usage

For cli usage, you should install xl2sql globally with

npm install xl2sql -g

Library Usage

For library usage, you should install as a dependency with

npm install xl2sql --save

Usage

CLI Usage

The easiest way to use xl2sql is via the CLI. Here are the simple usage docs:

Usage: xl2sql [options]

Options:
  -f, --file <file>      File path to parse
  -d, --directory <dir>  Directory to parse (default: "/home/henry/xl2sql/dist")
  -r, --recursive        If no file is present, recurse all files in directory (default: false)
  -o, --output <file>    Output queries to this file
  -n, --dry-run          Grab the files to run without processing them. (default: false)
  -h, --help             display help for command

Library Usage

Here is a minimal example of collecting file input and parsing it into a full sql query

import xl2sql from 'xl2sql';

// Initialize a file upload button. This is just for convience!
const fileUploader = xl2sql.FileInput.generate(document.getElementById('xl2sql'));

fileUploader.onUpload(async (file) => {

    // parse the file into a data table. Attempts all available ITableParser implementations.
    const table = await TableParser.parse(file);

    // Instantiate a builder for a specific SQL engine. For now, there is only the standard builder.
    const builder = new xl2sql.SqlBuilder();

    // SqlUtils contains helpful utilities! This function will convert as many strings as possible to table friendly names. Example: TheNewTable -> the_new_table or nutritional_Facts.csv -> nutritional_facts
    const tableName = xl2sql.SqlUtils.toSnakeCase(file.name);

    // The full sql to create a table and insert all rows of data.
    console.log(builder.createFullQuery(tableName, table));

})