-
Notifications
You must be signed in to change notification settings - Fork 5
Faq
- Why would I need this?
- How do I figure out my PostgreSQL database connection string?
- How do I convert csv, tsv or some other data format into json?
- How do I read a JSON file into Node.js?
- How do I install PostgreSQL?
- I found a situation it doesn't support or something I'd like it to do. How can it be fixed?
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.
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
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() )
var fs = require('fs');
var json = JSON.parse( fs.readFileSync('path/to/data.json') )
There are currently three ways (that I know of) to install PostgreSQL.
- Through Homebrew
brew install postgresql
- Through the Postgres app
- Through the KyngChaos installers
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.
Log an issue on the GitHub repo!