D2RQ
====

Accessing Relational Databases as Virtual RDF Graphs
----------------------------------------------------

From <http://d2rq.org>:

> The D2RQ Platform is a system for accessing relational databases as
> virtual, read-only RDF graphs. It offers RDF-based access to the
> content of relational databases without having to replicate it into an
> RDF store. Using D2RQ you can:

> * query a non-RDF database using SPARQL
> * access the content of the database as Linked Data over the Web
> * create custom dumps of the database in RDF formats for loading into an RDF store
> * access information in a non-RDF database using the Apache Jena API

> D2RQ is Open Source software and published under the Apache license. The source code is available on GitHub. You can contact the dev team through the issue tracker.

This is a Docker image based on the official Docker Java 7 JRE image
itself based on Alpine linux, an incredibly lightweight distribution.

Build
-----

The image can be built directly and comes with database drivers for
MySQL and Postgres.

`docker build -t res:d2rq .`

For more complex scenarios, the image can be used as a base image,
e.g. using the common Docker wait-for-it.sh script to allow waiting
for a linked MariaDB container to come up and include a MariaDB JDBC
driver:

```
FROM res:d2rq

COPY wait-for-it.sh ./
COPY mariadb-java-client-1.4.5.jar lib/db-drivers/
```

Configuration
-------------

D2R is configured by way of a
[mapping file](http://d2rq.org/d2rq-language) which can itself point
to other configuration files such as metadata templates, SQL scripts,
transformation tables and ontologies.

An initial configuration file can be generated directly by
introspecting the relations in an existing SQL database:

`docker run -it res:d2rq ./generate-mapping`

Typically, the generated mapping file is then hand edited to make the
transformation more naturally reflect RDF and LOD conventions.  The
resulting configuration file can be placed in `config/mapping.ttl` for
instance.

Running
-------

The image can be used stand-alone with the mapping file in
`config/mapping.ttl` as follows.  The default 

`docker run -p 2020:2020 -v $PWD/config:/var/lib/d2rq -p 2020:2020 -t res:d2rq`

Environment Variables
---------------------

D2R Server does need to be told where it will be hosted by passing
the environment variable D2R_BASEURI.  This defaults to
http://localhost:2020/, but for example using docker-machine on OSX,
one could run the container as:

`docker run -v $PWD/config:/var/lib/d2rq --env D2R_BASEURI=http://$(docker-machine ip default)/ -p 80:2020 -t res:d2rq

This would tell D2R Server that its resources are published at the IP
address of the local default docker machine VM on default HTTP port
80, forwarding to D2R Server running on port 2020 in the container.
