Skip to content

Lightweight concurrent microservice API built in Go for executing SQL queries against multiple ODBC drivers.

Notifications You must be signed in to change notification settings

bon4to/go-odbc-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-odbc-middleware

badge-db2 badge-sqlite badge-sqlite badge-sqlite badge-sqlite

A lightweight, concurrent microservice API built in Go for executing SQL queries against multiple ODBC drivers.


Requirements

  • Golang 1.20+

  • .env file with database credentials

    Duplicate .env.example to .env and fill in the values.

  • IBM DB2 CLI Driver installed

How to build

Docker

Wait for Docker Compose instructions.

Cross-compilation for Windows

You need to set GOOS and GOARCH:

GOOS=windows GOARCH=amd64 go build -o app.exe main.go

⚠️ The IBM DB2 driver must be available in the build machine. For Windows, you may need to compile inside a Windows VM or Docker container with the proper environment.

Running the Server

./app.exe

The server will start on port 40500 and expose one endpoint.

Running as a Service (Recommended)

This application can (and should) be installed as a system service for production use.

Windows (with NSSM)

  1. Download NSSM and add it to PATH

  2. Run:

    nssm install ODBC_API_Service "C:\go-odbc-middleware\app.exe"
  3. Start the service:

    nssm start ODBC_API_Service

Make sure the port is free (e.g. 40500) and your environment variables are set correctly.


Endpoint

POST /query

Request Body (JSON):

{
  "query": "SELECT * FROM table_name",
  "source": 1
}
  • query: SQL string to execute
  • source: integer matching the DB_DSN_n environment variable

Response:

{
  "columns": ["id", "name", "email"],
  "data": [
    {"id": 1, "name": "Alice", "email": "alice@example.com"},
    {"id": 2, "name": "Bob", "email": "bob@example.com"}
  ]
}

⚠️ This API executes raw SQL. Do not expose to untrusted users.

Upcoming

  • Token-based auth (e.g. HMAC or JWT)
  • Configurable query whitelisting
  • Logging control and access auditing
  • Rate limiting to prevent abuse

Feel free to contribute or open issues for feature requests.

This app is maintained by @bon4to.

About

Lightweight concurrent microservice API built in Go for executing SQL queries against multiple ODBC drivers.

Resources

Stars

Watchers

Forks