assafmo / SQLiteQueryServer

Bulk query SQLite database over the network
MIT License
51 stars 2 forks source link
bulk-api bulk-operation csv http-server json query-server sql sql-query sqlite sqlite3

SQLiteQueryServer

Bulk query SQLite database over the network.
Way faster than SQLiteProxy!

CircleCI Coverage Status Go Report Card

Installation

Usage

Usage of SQLiteQueryServer:
  -db string
        Filesystem path of the SQLite database
  -port uint
        HTTP port to listen on (default 80)
  -query string
        SQL query to prepare for

Note: SQLiteQueryServer is optimized for the SELECT command. Other commands such as INSERT, UPDATE, DELETE, CREATE, etc might be slow because SQLiteQueryServer doesn't use transactions (yet). Also, the response format and error messages from these commands may be odd or unexpected.

Examples

Creating a server

SQLiteQueryServer --db "$DB_PATH" --query "$PARAMETERIZED_SQL_QUERY" --port "$PORT"
SQLiteQueryServer --db ./test_db/ip_dns.db --query "SELECT * FROM ip_dns WHERE dns = ?" --port 8080

This will expose the ./test_db/ip_dns.db database with the query SELECT * FROM ip_dns WHERE dns = ? on port 8080.
Requests will need to provide the query parameters.

Querying the server

echo -e "github.com\none.one.one.one\ngoogle-public-dns-a.google.com" | curl "http://localhost:8080/query" --data-binary @-
echo -e "$QUERY1_PARAM1,$QUERY1_PARAM2\n$QUERY2_PARAM1,$QUERY2_PARAM2" | curl "http://$ADDRESS:$PORT/query" --data-binary @-
curl "http://$ADDRESS:$PORT/query" -d "$PARAM_1,$PARAM_2,...,$PARAM_N"

Getting a response

echo -e "github.com\none.one.one.one\ngoogle-public-dns-a.google.com" | curl "http://localhost:8080/query" --data-binary @-
[
  {
    "in": ["github.com"],
    "headers": ["ip", "dns"],
    "out": [["192.30.253.112", "github.com"], ["192.30.253.113", "github.com"]]
  },
  {
    "in": ["one.one.one.one"],
    "headers": ["ip", "dns"],
    "out": [["1.1.1.1", "one.one.one.one"]]
  },
  {
    "in": ["google-public-dns-a.google.com"],
    "headers": ["ip", "dns"],
    "out": [["8.8.8.8", "google-public-dns-a.google.com"]]
  }
]

Static query

SQLiteQueryServer --db ./test_db/ip_dns.db --query "SELECT * FROM ip_dns" --port 8080
curl "http://localhost:8080/query"
[
  {
    "in": [],
    "headers": ["ip", "dns"],
    "out": [
      ["1.1.1.1", "one.one.one.one"],
      ["8.8.8.8", "google-public-dns-a.google.com"],
      ["192.30.253.112", "github.com"],
      ["192.30.253.113", "github.com"]
    ]
  }
]