{"id":13753485,"url":"https://github.com/chop-dbhi/sql-agent","last_synced_at":"2025-10-26T18:31:39.927Z","repository":{"id":36296453,"uuid":"40600999","full_name":"chop-dbhi/sql-agent","owner":"chop-dbhi","description":"HTTP interface for executing ad-hoc SQL queries.","archived":false,"fork":false,"pushed_at":"2023-07-05T15:01:34.000Z","size":68084,"stargazers_count":93,"open_issues_count":9,"forks_count":23,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-01-31T22:11:42.003Z","etag":null,"topics":["database","microservice","mysql","oracle","postgresql","sql","sql-agent","sqlite"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chop-dbhi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2015-08-12T13:05:30.000Z","updated_at":"2024-01-10T19:40:52.000Z","dependencies_parsed_at":"2024-01-17T15:02:51.114Z","dependency_job_id":"49769b3f-0204-41de-9c68-60f982f90e90","html_url":"https://github.com/chop-dbhi/sql-agent","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chop-dbhi%2Fsql-agent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chop-dbhi%2Fsql-agent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chop-dbhi%2Fsql-agent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chop-dbhi%2Fsql-agent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chop-dbhi","download_url":"https://codeload.github.com/chop-dbhi/sql-agent/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238386068,"owners_count":19463290,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","microservice","mysql","oracle","postgresql","sql","sql-agent","sqlite"],"created_at":"2024-08-03T09:01:23.148Z","updated_at":"2025-10-26T18:31:34.620Z","avatar_url":"https://github.com/chop-dbhi.png","language":"Go","readme":"# SQL Agent\n\n[![GoDoc](https://godoc.org/github.com/chop-dbhi/sql-agent?status.svg)](https://godoc.org/github.com/chop-dbhi/sql-agent)\n\nSQL Agent is an HTTP service for executing ad-hoc queries on remote databases. The motivation for this service is to be part of a data monitoring process or system in which the query results will be evaluated against previous snapshots of the results.\n\nThe supported databases are:\n\n- PostgreSQL\n- MySQL, MariaDB\n- Oracle\n- Microsoft SQL Server\n- SQLite\n- Snowflake\n- Presto\n\nIn addition to the service, this repo also defines a `sqlagent` package for using in other Go programs.\n\n## Install\n\nAt the moment, it is recommended to run the service using Docker because there are no pre-built binaries yet.\n\n```\ndocker run -d -p 5000:5000 dbhi/sql-agent\n```\n\n## Usage\n\nTo execute a query, simply send a POST request with a payload containing the driver name of the database, connection information to with, and the SQL statement with optional parameters. The service will connect to the database, execute the query and return the results as a JSON-encoded array of maps (see [details](#Details) below).\n\n**Request**\n\n`POST`\n\nHeaders:\n  - `'Accept'` - required\n    - `application/json`\n    - `application/x-ldjson`\n    - `text/csv`\n\n```json\n{\n    \"driver\": \"postgres\",\n    \"connection\": {\n        \"host\": \"localhost\",\n        \"user\": \"postgres\"\n    },\n    \"sql\": \"SELECT name FROM users WHERE zipcode = :zipcode\",\n    \"params\": {\n        \"zipcode\": 18019\n    }\n}\n```\n\n**Response**\n\n```json\n[\n    {\n        \"name\": \"George\"\n    },\n    ...\n]\n```\n\n### Connection Options\n\nThe core option names are standardized for ease of use.\n\n- `host` - The host of the database.\n- `port` - The port of the database.\n- `user` - The user to connect with.\n- `password` - The password to authenticate with.\n- `database` - The name of the database to connect to. For SQLite, this will be a filesystem path. For Oracle, this would be the SID.\n\nOther options that are supplied are passed query options if they are known, otherwise they are they ignored.\n\nAlternatively, the `dsn` parameter can be specified which will used directly when [opening a connection](https://golang.org/pkg/database/sql/#Open).\n\n### Ping Connection\n\nTo validate the connection, send a POST with the `?ping` query parameter present and it will test the connection only.\n\n## Details\n\n- Only `SELECT` statements are supported.\n- Statements using parameters must use the `:param` syntax and must have a corresponding entry in the `params` map.\n\n### Constraints\n\n- Columns must be uniquely named, otherwise the conversion into a map will include only one of the values.\n\n## Library\n\nThe SQL Agent library does not include any drivers by default. To add them include them like so:\n\n```go\npackage main\n\nimport (\n\t_ \"github.com/alexbrainman/odbc\"\n\t_ \"github.com/denisenkom/go-mssqldb\"\n\t_ \"github.com/go-sql-driver/mysql\"\n\t_ \"github.com/lib/pq\"\n\t_ \"github.com/mattn/go-oci8\"\n\t_ \"github.com/mattn/go-sqlite3\"\n)\n\nfunc main() {\n    //...\n}\n```\n\n## Help\n\n### Install Oracle client libraries\n\n#### General\n\nIn order to install the [go-oci8](https://github.com/mattn/go-oci8) driver, you must install Oracle's client libraries.\n\nDownload the **instantclient-basic** and **instantclient-sdk** package from [Oracle's website](http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html) and uncompress to the same directory. Make sure that you selected the platform and architecture.\n\nThe installations instructions are listed at the bottom of the page with the download links.\n\nInstall `pkg-config`.\n\nCreate `oci8.pc` file in your `$PKG_CONFIG_PATH` (such as `/usr/local/lib/pkgconfig`) and add the below contents:\n\n```\nprefix=/usr/local/lib/instantclient_11_2\nlibdir=${prefix}\nincludedir=${prefix}/sdk/include/\n\nName: OCI\nDescription: Oracle database engine\nVersion: 11.2\nLibs: -L${libdir} -lclntsh\nLibs.private:\nCflags: -I${includedir}\n```\n\nChange the `prefix` to path to location of the Oracle libraries.\n\n#### OS X specific Help\n\nAssuming the `instantclient_11_2` folder is located in `/usr/loca/lib`, link the following files:\n\n```bash\nln /usr/local/lib/instantclient_11_2/libclntsh.dylib /usr/local/lib/libclntsh.dylib\nln /usr/local/lib/instantclient_11_2/libocci.dylib.* /usr/local/lib/libocci.dylib.*\nln /usr/local/lib/instantclient_11_2/libociei.dylib /usr/local/lib/libociei.dylib\nln /usr/local/lib/instantclient_11_2/libnnz11.dylib /usr/local/lib/libnnz11.dylib\n```\n\nInstall `pkg-config` via [Homebrew](http://brew.sh/), `brew install pkg-config`.\n","funding_links":[],"categories":["postgresql"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchop-dbhi%2Fsql-agent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchop-dbhi%2Fsql-agent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchop-dbhi%2Fsql-agent/lists"}