Skip to content

xavierchow/metabase-couchbase-driver

Repository files navigation

Couchbase Metabase Driver

Couchbase database driver for the Metabase. This is still an experimental project, it provides the SQL(N1QL) support and limited features basing on MBQL.

Usage

As a noSQL database, the coucbhase doesn't have the concept of table, this driver maps the coubhase bucket to the DB in the Metabase, and it requires you to have a type field _type to define the documents in a table.

Configuration

Go to the Metabase admin page and add a new database,

The Database name needs to be the bucket name, Host, Username and Password are self-explanatory. The Table defintion tells the Metabase the schema of the document in the bucket.

  • name: the table name in Metabase

  • schema: it's used to identify which documents belong to this table, it can either a string to present the value of doc._type, or a column separated string defines the doc type. e.g. "schema": "mytype:Ticket" will select all documents with mytype=Ticket from the bucket.

  • fields

    • name: column name
    • type: the JSON type of the field, optional.
    • pk?: a boolean whether it's primary key
    • database-position: column position
    • base-type: the Metabase type defined in types.clj without :type/ prefix, optional.
  • Example

{"tables":[{"name": "order", "schema": "Order", 
  "fields": [{ "name": "id", "type": "string","database-position": 0, "pk?": true},
             { "name": "state", "type": "string","database-position": 1 },
             { "name": "userPhoneNumber", "type": "string","database-position": 2 },
             { "name": "SKU code", "type": "string","database-position": 3 },
             { "name": "productName", "type": "string","database-position": 4 },
             { "name": "amount", "type": "number","database-position": 5 },
             { "name": "createdAt", "base-type": "Text","database-position": 6 }]}]}

Building the driver

Local build

Prereq: Install Metabase as a local maven dependency, compiled for building drivers

Clone the Metabase repo first if you haven't already done so.

cd /path/to/metabase_source
lein install-for-building-drivers

Build the Couchbase driver

# (In the Couchbase driver directory)
lein clean
DEBUG=1 LEIN_SNAPSHOTS_IN_RELEASE=true lein uberjar

Copy it to your plugins dir and restart Metabase

mkdir -p /path/to/metabase/plugins/
cp target/uberjar/couchbase.metabase-driver.jar /path/to/metabase/plugins/
jar -jar /path/to/metabase/metabase.jar

Build with docker

Option 1, build from the source code

docker build -t xavchow/metabase-with-cb .
docker run --rm -p 3000:3000 --name metabase xavchow/metabase-with-cb

Option 2, build with release package.

Go to the ./build directory, build with docker file Dockerfile-tag with sepcified version,

docker build -f Dockerfile-tag -t xavchow/metabase-with-cb --build-arg DRIVER_VERSION=v1.0.5 .

or build with latest release,

docker build -f Dockerfile-latest -t xavchow/metabase-with-cb .

Then,

docker run --rm -p 3000:3000 --name metabase xavchow/metabase-with-cb

License

Licensed under MIT