voltrondata/sqlflite[]([] []([] []([] []([] []([] []([] []([***]
This repo demonstrates how to build an Apache Arrow Flight SQL server implementation using DuckDB or SQLite as a backend database.
It enables authentication via middleware and allows for encrypted connections to the database via TLS.
For more information about Apache Arrow Flight SQL - please see this article.
Open a terminal, then pull and run the published Docker image which has everything setup (change: "--detach" to "--interactive" if you wish to see the stdout on your screen) - with command:
bashdocker run --name sqlflite \ --detach \ --rm \ --tty \ --init \ --publish 31337:31337 \ --env TLS_ENABLED="1" \ --env SQLFLITE_PASSWORD="sqlflite_password" \ --env PRINT_QUERIES="1" \ --pull missing \ voltrondata/sqlflite:latest
The above command will automatically mount a very small TPC-H DuckDB database file.
Note: You can disable TLS in the container by setting environment variable: TLS_ENABLED to "0" (default is "1" - enabled). This is not recommended unless you are using an mTLS sidecar in Kubernetes or something similar, as it will be insecure.
When running the Docker image - you can have it run your own DuckDB database file (the database must be built with DuckDB version: 1.1.1).
Prerequisite: DuckDB CLI
Install DuckDB CLI version 1.1.1 - and make sure the executable is on your PATH.
Platform Downloads:
Linux x86-64
Linux arm64 (aarch64)
MacOS Universal
In this example, we'll generate a new TPC-H Scale Factor 1 (1GB) database file, and then run the docker image to mount it:
bash# Generate a TPC-H database in the host's /tmp directory pushd /tmp duckdb ./tpch_sf1.duckdb << EOF .bail on .echo on SELECT VERSION(); INSTALL tpch; LOAD tpch; CALL dbgen(sf=1); EOF # Run the sqlflite docker container image - and mount the host's DuckDB database file created above inside the container docker run --name sqlflite \ --detach \ --rm \ --tty \ --init \ --publish 31337:31337 \ --env TLS_ENABLED="1" \ --env SQLFLITE_PASSWORD="sqlflite_password" \ --pull missing \ --mount type=bind,source=$(pwd),target=/opt/sqlflite/data \ --env DATABASE_FILENAME="data/tpch_sf1.duckdb" \ voltrondata/sqlflite:latest
You can now run initialization commands upon container startup by setting environment variable: INIT_SQL_COMMANDS to a string of SQL commands separated by semicolons - example value:
SET threads = 1; SET memory_limit = '1GB';.
Here is a full example of running the Docker image with initialization SQL commands:
bashdocker run --name sqlflite \ --detach \ --rm \ --tty \ --init \ --publish 31337:31337 \ --env TLS_ENABLED="1" \ --env SQLFLITE_PASSWORD="sqlflite_password" \ --env PRINT_QUERIES="1" \ --env INIT_SQL_COMMANDS="SET threads = 1; SET memory_limit = '1GB';" \ --pull missing \ voltrondata/sqlflite:latest
You can also specify a file containing initialization SQL commands by setting environment variable: INIT_SQL_COMMANDS_FILE to the path of the file containing the SQL commands - example value: /tmp/init.sql. The file must be mounted inside the container.
Note: for the DuckDB back-end - the following init commands are automatically run for you:
SET autoinstall_known_extensions = true; SET autoload_known_extensions = true;
Note: Initialization SQL commands which SELECT data will NOT show the results (this is not supported).
Note: Initialization SQL commands which fail will cause the Flight SQL server to abort and exit with a non-zero exit code.
Download the Apache Arrow Flight SQL JDBC driver
You can then use the JDBC driver to connect from your host computer to the locally running Docker Flight SQL server with this JDBC string (change the password value to match the value specified for the SQLFLITE_PASSWORD environment variable if you changed it from the example above):
bashjdbc:arrow-flight-sql://localhost:31337?useEncryption=true&user=sqlflite_username&password=sqlflite_password&disableCertificateVerification=true
For instructions on setting up the JDBC driver in popular Database IDE tool: DBeaver Community Edition - see this repo.
Note - if you stop/restart the Flight SQL Docker container, and attempt to connect via JDBC with the same password - you could get error: "Invalid bearer token provided. Detail: Unauthenticated". This is because the client JDBC driver caches the bearer token signed with the previous instance's secret key. Just change the password in the new container by changing the "SQLFLITE_PASSWORD" env var setting - and then use that to connect via JDBC.
You can now use the new Apache Arrow Python ADBC Flight SQL driver to query the Flight SQL server. ADBC offers performance advantages over JDBC - because it minimizes serialization/deserialization, and data stays in columnar format at all phases.
You can learn more about ADBC and Flight SQL here.
Ensure you have Python 3.9+ installed, then open a terminal, then run:
bash# Create a Python virtual environment python3 -m venv .venv # Activate the virtual environment . .venv/bin/activate # Install the requirements including the new Arrow ADBC Flight SQL driver pip install --upgrade pip pip install pandas pyarrow adbc_driver_flightsql # Start the python interactive shell python
In the Python shell - you can then run:
pythonimport os from adbc_driver_flightsql import dbapi as sqlflite, DatabaseOptions with sqlflite.connect(uri="grpc+tls://localhost:31337", db_kwargs={"username": os.getenv("SQLFLITE_USERNAME", "sqlflite_username"), "password": os.getenv("SQLFLITE_PASSWORD", "sqlflite_password"), DatabaseOptions.TLS_SKIP_VERIFY.value: "true" # Not needed if you use a trusted CA-signed TLS cert } ) as conn: with conn.cursor() as cur: cur.execute("SELECT n_nationkey, n_name FROM nation WHERE n_nationkey = ?", parameters=[24] ) x = cur.fetch_arrow_table() print(x)
You should see results:
textpyarrow.Table n_nationkey: int32 n_name: string ---- n_nationkey: [[24]] n_name: [["UNITED STATES"]]
sqlflite_client CLI toolYou can also use the new sqlflite_client CLI tool to connect to the Flight SQL server, and then run a single command. This tool is built into the Docker image, and is also available as a standalone executable for Linux and MacOS.
Example (run from the host computer's terminal):
bashsqlflite_client \ --command Execute \ --host "localhost" \ --port 31337 \ --username "sqlflite_username" \ --password "sqlflite_password" \ --query "SELECT version()" \ --use-tls \ --tls-skip-verify
That should return:
textResults from endpoint 1 of 1 Schema: version(): string Results: version(): [ "v1.1.1" ] Total: 1
See: [***]
See: [***]
Stop the docker image with:
bashdocker stop sqlflite
Download (and unzip) the latest release of the sqlflite_server CLI executable from these currently supported platforms:
Linux x86-64
Linux arm64
MacOS x86-64
MacOS arm64
Then from a terminal - you can run:
bashSQLFLITE_PASSWORD="sqlflite_password" sqlflite_server --database-filename data/some_db.duckdb --print-queries
To see all program options - run:
bashsqlflite_server --help
In order to run build the solution manually, and run SQLite and DuckDB Flight SQL server, you need to set up a new Python 3.9+ virtual environment on your machine. Follow these steps to do so (thanks to David Li!).
bashgit clone [***] --recurse-submodules cd sqlflite # Build and install the static library and executable cmake -S . -B build -G Ninja -DCMAKE_INSTALL_PREFIX=/usr/local cmake --build build --target install
bashpython3 -m venv .venv . .venv/bin/activate pip install --upgrade pip setuptools wheel pip install --requirement ./requirements.txt
bashwget [***] -O ./data/TPC-H-small.sqlite
bashpython "scripts/create_duckdb_database_file.py" \ --file-name="TPC-H-small.duckdb" \ --file-path="data" \ --overwrite-file=true \ --scale-factor=0.01
bashpushd tls ./gen-certs.sh popd
bashSQLFLITE_PASSWORD="sqlflite_password" sqlflite_server --database-filename data/TPC-H-small.duckdb --print-queries
This option allows choosing from two backends: SQLite and DuckDB. It defaults to DuckDB.
bash$ SQLFLITE_PASSWORD="sqlflite_password" sqlflite_server --database-filename data/TPC-H-small.duckdb Apache Arrow version: 17.0.0 WARNING - TLS is disabled for the SQLFlite server - this is insecure. DuckDB version: v1.1.1 Running Init SQL command: SET autoinstall_known_extensions = true; Running Init SQL command: SET autoload_known_extensions = true; Using database file: "/opt/sqlflite/data/TPC-H-small.duckdb" Print Queries option is set to: false SQLFlite server - with engine: DuckDB - will listen on grpc+tcp://0.0.0.0:31337 SQLFlite server - started
The above call is equivalent to running sqlflite_server -B duckdb or sqlflite --backend duckdb. To select SQLite run
bashSQLFLITE_PASSWORD="sqlflite_password" sqlflite_server -B sqlite -D data/TPC-H-small.sqlite
or
bashSQLFLITE_PASSWORD="sqlflite_password" sqlflite_server --backend sqlite --database-filename data/TPC-H-small.sqlite
The above will produce the following:
bashApache Arrow version: 17.0.0 WARNING - TLS is disabled for the SQLFlite server - this is insecure. SQLite version: 3.45.0 Using database file: "/opt/sqlflite/data/TPC-H-small.sqlite" Print Queries option is set to: false SQLFlite server - with engine: SQLite - will listen on grpc+tcp://0.0.0.0:31337 SQLFlite server - started
To see all the available options run sqlflite_server --help.
bashsqlflite_server --help Allowed options: --help produce this help message --version Print the version and exit -B [ --backend ] arg (=duckdb) Specify the database backend. Allowed options: duckdb, sqlite. -H [ --hostname ] arg Specify the hostname to listen on for the SQLFlite Server. If not set, we will use env var: 'SQLFLITE_HOSTNAME'. If that isn't set, we will use the default of: '0.0.0.0'. -R [ --port ] arg (=31337) Specify the port to listen on for the SQLFlite Server. -D [ --database-filename ] arg Specify the database filename (absolute or relative to the current working directory) -U [ --username ] arg Specify the username to allow to connect to the SQLFlite Server for clients. If not set, we will use env var: 'SQLFLITE_USERNAME'. If that isn't set, we will use the default of: 'sqlflite_username'. -P [ --password ] arg Specify the password to set on the SQLFlite Server for clients to connect with. If not set, we will use env var: 'SQLFLITE_PASSWORD'. If that isn't set, the server will exit with failure. -S [ --secret-key ] arg Specify the secret key used to sign JWTs issued by the SQLFlite Server. If it isn't set, we use env var: 'SECRET_KEY'. If that isn't set, the server will create a random secret key. -T [ --tls ] arg Specify the TLS certificate and key file paths. -I [ --init-sql-commands ] arg Specify the SQL commands to run on server startup. If not set, we will use env var: 'INIT_SQL_COMMANDS'. -F [ --init-sql-commands-file ] arg Specify a file containing SQL commands to run on server startup. If not set, we will use env var: 'INIT_SQL_COMMANDS_FILE '. -M [ --mtls-ca-cert-filename ] arg Specify an optional mTLS CA certificate path used to verify clients. The certificate MUST be in PEM format. -Q [ --print-queries ] Print queries run by clients to stdout
There is now a slim docker image available, without Python, tls certificate generation, sample database files, etc.
You must supply the following environment variables to the slim image:
DATABASE_FILENAME - the path to the database file to useSQLFLITE_PASSWORD - the password to use for the SQLFlite serverYou can optionally supply the following environment variables:
TLS_ENABLED - set to "1" to enable TLS (default is "0" - disabled)TLS_CERT - If TLS_ENABLED is 1 - provide the path to the TLS certificate file (it must be mounted in the container)TLS_KEY - If TLS_ENABLED is 1 - provide the path to the TLS key file (it must be mounted in the container)To run that image - use the following command:
bashdocker run --name sqlflite-slim \ --detach \ --rm \ --tty \ --init \ --publish 31337:31337 \ --env DATABASE_FILENAME="data/some_database.duckdb" \ --env TLS_ENABLED="0" \ --env SQLFLITE_PASSWORD="sqlflite_password" \ --env PRINT_QUERIES="1" \ --pull missing \ voltrondata/sqlflite:latest-slim
See start_sqlflite_slim.sh - the container's entrypoint script for more details.
探索更多轩辕镜像的使用方法,找到最适合您系统的配置方式
通过 Docker 登录认证访问私有仓库
在 Linux 系统配置镜像服务
在 Docker Desktop 配置镜像
Docker Compose 项目配置
Kubernetes 集群配置 Containerd
K3s 轻量级 Kubernetes 镜像加速
VS Code Dev Containers 配置
MacOS OrbStack 容器配置
在宝塔面板一键配置镜像
Synology 群晖 NAS 配置
飞牛 fnOS 系统配置镜像
极空间 NAS 系统配置服务
爱快 iKuai 路由系统配置
绿联 NAS 系统配置镜像
QNAP 威联通 NAS 配置
Podman 容器引擎配置
HPC 科学计算容器配置
ghcr、Quay、nvcr 等镜像仓库
无需登录使用专属域名
需要其他帮助?请查看我们的 常见问题Docker 镜像访问常见问题解答 或 提交工单
免费版仅支持 Docker Hub 访问,不承诺可用性和速度;专业版支持更多镜像源,保证可用性和稳定速度,提供优先客服响应。
专业版支持 docker.io、gcr.io、ghcr.io、registry.k8s.io、nvcr.io、quay.io、mcr.microsoft.com、docker.elastic.co 等;免费版仅支持 docker.io。
当返回 402 Payment Required 错误时,表示流量已耗尽,需要充值流量包以恢复服务。
通常由 Docker 版本过低导致,需要升级到 20.x 或更高版本以支持 V2 协议。
先检查 Docker 版本,版本过低则升级;版本正常则验证镜像信息是否正确。
使用 docker tag 命令为镜像打上新标签,去掉域名前缀,使镜像名称更简洁。
来自真实用户的反馈,见证轩辕镜像的优质服务