Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: df93c5ec00
Fetching contributors…

Cannot retrieve contributors at this time

file 99 lines (68 sloc) 2.887 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
CouchDB FDW (beta) for PostgreSQL 9.1+
======================================

This PostgreSQL extension implements a Foreign Data Wrapper (FDW) for
the CouchDB document-oriented database: http://couchdb.apache.org/

IMPORTANT: There're bugs in the existing version. I'm working on it and will
be releasing another version very soon.


Building
--------

To build the code, you need the yajl(Yet Another JSON Library) and libcurl installed
on your system.

You can checkout the yajl from GitHub:
https://github.com/lloyd/yajl
OR
download from:
http://lloyd.github.com/yajl/

libcurl C interface can be found here:
http://curl.haxx.se/libcurl/c/

Once that's done, the extension can be built with:

PATH=/usr/local/pgsql91/bin/:$PATH make USE_PGXS=1 make
sudo PATH=/usr/local/pgsql91/bin/:$PATH make USE_PGXS=1 install

(assuming you have PostgreSQL 9.1 in /usr/local/pgsql91).

I've tested on Mac OS X 10.6 only, but other *nix's should also work.
I haven't tested on Windows, but the code should be good on MinGW.

Limitations
-----------

- If there is no quals to pushdown, we get a list of '_id's to begin with,
  and then fetch whatever records still exist as we build the tuples.

- We can only pushdown '_id' (with or without '_rev') to CouchDB, which must use
  the TEXTEQ operator.

- The top-level-attributes of a document can be mapped to columns in a
  foreign table.
  
- In case you want the map a column to the entire JOSN doc, use
columnname '_doc'
  in foreign table options (which means your remote couchdb shouldn't have
  a top-level-attribute called '_doc', otherwise there will be conficts).

Usage
-----

The following parameters can be set on a CouchDB foreign server:

address: The address or hostname of the CouchDB server.
Default: 127.0.0.1

port: The port number on which the CouchDB server is listening.
      Default: 5984

The following parameter can be set on a CouchDB foreign table:

database: The name of the CouchDB database to query.
Default: test

<column name>: The column mapping to remote JSON attributes.
If there is no column mapping specified, default is the origninal column name.
Please note that '_doc' is reserved for mapping the entire JSON document.

The following parameter can be set on a user mapping for a CouchDB
foreign server:

username: The username to authenticate to the CouchDB server with.
Default: <none>

password: The password to authenticate to the CouchDB server with.
Default: <none>

Example
-------

CREATE SERVER couchdb_server
FOREIGN DATA WRAPPER couchdb_fdw
OPTIONS (address '127.0.0.1', port '5984');

CREATE FOREIGN TABLE couchdb_table (key text, value text)
SERVER couchdb_server
OPTIONS (database 'testdb', key '_id', value '_doc');

CREATE USER MAPPING FOR PUBLIC
SERVER couchdb_server
OPTIONS (username 'testuser', password 'secret');

--
Zheng Yang
zhengyang4k@gmail.com
Something went wrong with that request. Please try again.