resty-snowflake
is a Lua library that integrates Snowflake's powerful capabilities with the high-performance web platform OpenResty. It leverages the Snowflake SQL REST API and supports fast JSON processing, enabling efficient and scalable data management in modern web applications.
- Direct integration of Snowflake with OpenResty
- High-performance JSON processing using libraries like
rsjson
,dkjson
, orcjson
- Support for Snowflake SQL API operations:
- Submit SQL statements for execution
- Check execution status
- Cancel statement execution
- Fetch query results concurrently
- Integration with CortexAI Services for AI-powered functionalities
- Flexible configuration via environment variables or Lua scripts
- Ensure you have OpenResty installed on your system.
- Clone this repository:
git clone https://github.com/skitsanos/resty-snowflake.git
- Install the required OpenResty packages:
opm get bsiara/dkjson opm get fffonion/lua-resty-openssl opm get pintsized/lua-resty-http opm get SkyLothar/lua-resty-jwt
You can configure resty-snowflake
using either environment variables or Lua configuration.
Set the following environment variables:
SNOWFLAKE_ACCOUNT_NAME
SNOWFLAKE_USERNAME
SNOWFLAKE_PRIVATE_KEY
SNOWFLAKE_PUBLIC_KEY_FINGERPRINT
Initialize the library with a configuration table:
local snowflake = require("snowflake")
snowflake.init({
account_name = "your_account_name",
username = "your_username",
private_key = "your_private_key",
private_key_password = "your_private_key_password", -- optional
public_key_fp = "your_public_key_fingerprint"
})
Here's a basic example of how to use resty-snowflake
:
local snowflake = require("snowflake")
snowflake.init()
local result, err = snowflake.execute_sql("SELECT CURRENT_TIMESTAMP()")
if err then
ngx.say("Error: " .. err)
return
end
ngx.say("Result: ", result.data[1])
A Dockerfile is provided for easy deployment. Build and run the Docker image using the following commands:
docker build -t resty-snowflake-demo .
docker run -it -d -p "8000:80" -v "$(pwd)/app:/app" -v "$(pwd)/lib:/app-libs" -v "$(pwd)/nginx/conf/nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf" -e SNOWFLAKE_ACCOUNT_NAME="your_account_name" -e SNOWFLAKE_USERNAME="your_username" -e SNOWFLAKE_PRIVATE_KEY="your_private_key" -e SNOWFLAKE_PUBLIC_KEY_FINGERPRINT="your_public_key_fingerprint" resty-snowflake-demo
A Taskfile is included to simplify common operations:
generate-keypair
: Generate RSA key pairtest-keypair
: Test Snowflake connectivitygenerate-jwt
: Generate JWT for authenticationtest-sql
: Test Snowflake SQL REST APIdocker-build
: Build Docker imagedocker-run
: Run Docker container
To use these tasks, install Task and run task <taskname>
.
Contributions are welcome! Please feel free to submit a Pull Request.
If you encounter any problems or have any questions, please open an issue on this GitHub repository.