Skip to content
Michael Keller edited this page Mar 12, 2015 · 9 revisions

Why would I need this?

If you have a dataset in json format, Tablespoon makes it really easy to run SQL queries on it by generating the CREATE and INSERT commands for your. It also provides methods for easily querying and getting data back.

You can also use it on the command linen as an easy way to print CREATE and INSERT commands without inserting them into a database.

It supports SQLite for basic queries and datatypes, as well as PostgreSQL, if you have it installed, for more complicated projects.

How do I figure out my PostgreSQL database connection string?

Tablespoon tests and examples connect to the database at pg://postgres:5432@localhost, which gives it access to the main database of your PostgreSQL installation. In order to better sandbox your Tablespoon projects, you might want to create a separate database called tablespoon. To do this, log into psql by running psql on the command line and run CREATE DATABASE tablespoon;. Don't forget the ; at the end. *Note: You might not have a postgres user. To create a postgres super user, enter createuser -s -r postgres in the command line.

Then specify your connection in with ts.connection('pg://postgres:5432@localhost/tablespoon') when using Tablespoon through nodejs or through -c <new_connection_string> through the command line.

You could also obviously set up a different user as well if you don't want to give Tablespoon root access. If you have a user called, mike that owns a database tablespoon, your connection string would be pg://mike:5432@localhost/tablespoon

How do I convert csv, tsv or some other data format into json?

Check out the indian-ocean package which supports a whole bunch of data formats such as csv, tsv, json and dbf.

If you prefer to run things yourself, dsv is a great library for reading data. If your data is in csv you can do it like this:

var fs  = require('fs'),
    dsv = require('dsv');

var data = dsv.csv.parse( fs.readFileSync('path/to/data.csv').toString() )

For any other delimiter, do something like:

var fs  = require('fs'),
    dsv = require('dsv'),
    tsv = dsv('\t');

var data = tsv.parse( fs.readFileSync('path/to/data.tsv').toString() )

How do I read a json file into Node.js?

var fs = require('fs');

var json = JSON.parse( fs.readFileSync('path/to/data.json') )

How do I install PostgreSQL?

There are currently three ways (that I know of) to install PostgreSQL.

Generally, it's a good idea to only use one of these methods, since mixing and matching can cause problems. Also, keep in mind that your PostgreSQL client can be a different version from your PostgreSQL server, which can cause problems if you're trying to use new features that aren't supported in older versions.

I found a situation it doesn't support or something I'd like it to do. How can it be fixed?

Log an issue on the GitHub repo!