dexec
dexec copied to clipboard
Support for SQL[ite]
I guess having at least one kind of SQL dialect implement would be a good addition.
I'm gonna try and submit a PR sometime soon for .sql > SQLite support.
Unfortunately I didn't had much time to learn how to create a new integration following dexec conventions.
I started with a simple Dockerfile:
FROM ubuntu:14.04
MAINTAINER alixaxel
ENV LANG C.UTF-8
RUN apt-get update -qq -y && \
apt-get install -y sqlite3 && \
apt-get clean
VOLUME /tmp/dexec/build
And then:
docker build -t dexec/lang-sqlite .
To test it, I created a new file (HelloWorld.sql) with the following contents:
CREATE TABLE "primes" (
"id" INTEGER NOT NULL,
"is_prime" INTEGER NOT NULL DEFAULT (0)
);
INSERT INTO "primes" ("id", "is_prime") VALUES (1, 0);
INSERT INTO "primes" ("id", "is_prime") VALUES (2, 1);
INSERT INTO "primes" ("id", "is_prime") VALUES (3, 1);
INSERT INTO "primes" ("id", "is_prime") VALUES (4, 0);
INSERT INTO "primes" ("id", "is_prime") VALUES (5, 1);
INSERT INTO "primes" ("id", "is_prime") VALUES (6, 0);
INSERT INTO "primes" ("id", "is_prime") VALUES (7, 1);
INSERT INTO "primes" ("id", "is_prime") VALUES (8, 0);
INSERT INTO "primes" ("id", "is_prime") VALUES (9, 0);
SELECT 'Hello World!';
SELECT COUNT(1) FROM "primes" WHERE "is_prime" = 0;
SELECT COUNT(1) FROM "primes" WHERE "is_prime" = 1;
And executed it directly with the containers SQLite 3 binary:
docker run --rm -v $(pwd -P)/HelloWorld.sql:/tmp/dexec/build/HelloWorld.sql \
dexec/lang-sqlite sqlite3 \
--init /tmp/dexec/build/HelloWorld.sql
It's also possible to "annex" additional query commands within the context of the SQL file:
docker run --rm -v $(pwd -P)/HelloWorld.sql:/tmp/dexec/build/HelloWorld.sql \
dexec/lang-sqlite sqlite3 \
--init /tmp/dexec/build/HelloWorld.sql \
--cmd 'SELECT SUM("id") FROM "primes" WHERE "is_prime" = 1;'
The output of that being:
Hello World!
5
4
17
@andystanton Could you give some guidance on how to integrate additional languages?