Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for SQL[ite] #44

Open
alixaxel opened this issue Nov 13, 2015 · 1 comment
Open

Support for SQL[ite] #44

alixaxel opened this issue Nov 13, 2015 · 1 comment
Milestone

Comments

@alixaxel
Copy link
Contributor

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.

@alixaxel
Copy link
Contributor Author

alixaxel commented Dec 1, 2015

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants