{"id":15518063,"url":"https://github.com/iamrajiv/neon-db-query-executor","last_synced_at":"2026-05-02T13:32:58.598Z","repository":{"id":163910510,"uuid":"639355534","full_name":"iamrajiv/neon-db-query-executor","owner":"iamrajiv","description":" The SQL Query Executor for Neon Database is a lightweight Go-based application that allows you to execute SQL queries stored in files against a Neon database. It provides a simple and efficient way to run SQL queries and print the results.","archived":false,"fork":false,"pushed_at":"2023-05-17T07:52:51.000Z","size":22220,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-28T19:50:59.501Z","etag":null,"topics":["go","neondatabase","postgresql","serverless","sql"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iamrajiv.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-11T09:54:16.000Z","updated_at":"2024-04-02T20:16:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"54bf635c-9128-4a64-bbf2-7664f4dc9897","html_url":"https://github.com/iamrajiv/neon-db-query-executor","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/iamrajiv/neon-db-query-executor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamrajiv%2Fneon-db-query-executor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamrajiv%2Fneon-db-query-executor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamrajiv%2Fneon-db-query-executor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamrajiv%2Fneon-db-query-executor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iamrajiv","download_url":"https://codeload.github.com/iamrajiv/neon-db-query-executor/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamrajiv%2Fneon-db-query-executor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32536576,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-02T12:25:33.646Z","status":"ssl_error","status_checked_at":"2026-05-02T12:24:51.733Z","response_time":132,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["go","neondatabase","postgresql","serverless","sql"],"created_at":"2024-10-02T10:14:50.043Z","updated_at":"2026-05-02T13:32:58.568Z","avatar_url":"https://github.com/iamrajiv.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\u003cimg src=\"https://neon.tech/_next/static/chunks/src/images/logo-black.4cffa5b1beb857a5.svg\" height=\"auto\" width=\"400\" /\u003e\n\u003cbr /\u003e\n\u003ch1\u003eNeon DB Query Executor\u003c/h1\u003e\n\u003cp\u003e\nSimple Go application to execute SQL queries against a Neon database\n\u003c/p\u003e\n\u003ca href=\"https://github.com/iamrajiv/neon-db-query-executor/network/members\"\u003e\u003cimg src=\"https://img.shields.io/github/forks/iamrajiv/neon-db-query-executor?color=0969da\u0026style=for-the-badge\" height=\"auto\" width=\"auto\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/iamrajiv/neon-db-query-executor/stargazers\"\u003e\u003cimg src=\"https://img.shields.io/github/stars/iamrajiv/neon-db-query-executor?color=0969da\u0026style=for-the-badge\" height=\"auto\" width=\"auto\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/iamrajiv/neon-db-query-executor/blob/main/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/github/license/iamrajiv/neon-db-query-executor?color=0969da\u0026style=for-the-badge\" height=\"auto\" width=\"auto\" /\u003e\u003c/a\u003e\n\u003c/div\u003e\n\n## About\n\nThe SQL Query Executor for Neon Database is a lightweight Go-based application that allows you to execute SQL queries stored in files against a Neon database. It provides a simple and efficient way to run SQL queries and print the results.\n\n[Neon](https://neon.tech/) is a fully managed serverless PostgreSQL. Neon separates storage and computing to offer modern developer features such as serverless, branching, bottomless storage, and more. Learn more about Neon [here](https://neon.tech/docs/introduction).\n\nThe Neon DB Query Executor has the following features:\n\n- **Query Execution**\n  - Execute SQL queries stored in files against a Neon database.\n  - Support for executing multiple queries in a single file.\n- **Database Connectivity**\n  - Connect to a Neon database using Go's **`database/sql`** package.\n  - Configuration of database connection details via environment variables.\n  - Secure connection establishment with SSL/TLS support (**`sslmode=verify-full`**).\n- **Comment Handling**\n  - Handle comments in SQL files for additional information or explanations.\n  - Support for both single-line comments (**`- Comment`**) and multi-line comments (**`/* Comment */`**).\n  - Remove comments from the SQL file before query execution.\n- **Skip Command Exclusion**\n  - Exclude specific SQL commands from being displayed in the results.\n  - Skip commands such as **`CREATE`**, **`ALTER`**, **`DROP`**, **`INSERT`**, etc., that do not produce output results.\n  - Enhance result clarity by focusing on queries that generate result sets.\n- **Result Presentation**\n  - Print query results in a tabular format for easy viewing and analysis.\n  - Utilize the **`tablewriter`** package to render formatted tables.\n  - Display column names as table headers for clear representation.\n- **Execution Time Tracking**\n  - Calculate and display the execution time for each query to measure performance.\n  - Track the elapsed time from query execution start to completion.\n  - Print the execution time in seconds with precision.\n- **Total Execution Time**\n  - Show the total execution time for all queries in the file.\n  - Accumulate the execution times of individual queries to calculate the total time taken.\n\nThese features collectively enable the SQL Query Executor for Neon Database to provide a comprehensive solution for executing SQL queries against a Neon database. It offers flexibility in query execution, result presentation, comment handling, and execution time tracking. The skip command exclusion feature further enhances output clarity by excluding non-result-producing commands.\n\nThe folder structure of the project is as follows:\n\n```shell\n.\n├── .env\n├── LICENSE\n├── README.md\n├── assets\n│   └── neon-db-query-executor.svg\n├── go.mod\n├── go.sum\n├── main.go\n└── queries.sql\n```\n\n## Usage\n\n1. To set up a project in Neon, follow the instructions [here](https://neon.tech/docs/get-started-with-neon/setting-up-a-project).\n2. Configure the database connection details in a `.env` file.\n3. Write your SQL queries in `queries.sql` file.\n4. Run the application using `go run main.go`.\n\n#### Instructions for writing environment variables\n\nTo run the project locally, create a `.env` file and add the following environment variables:\n\n- **`DB_USER`**: Username for the Neon database.\n- **`DB_PASSWORD`**: Password for the Neon database.\n- **`DB_NAME`**: Name of the Neon database. When creating a project, you can choose any name for the database, so make sure to update this variable accordingly.\n- **`DB_ENDPOINT_ID`**: ID of the Neon database endpoint. The endpoint ID will change for every new branch you create.\n- **`DB_PROXY_HOST`**: Host for the Neon database proxy. When creating a new project, you will be asked to choose a region from a dropdown list of available regions.\n- **`DB_HOST`**: Leave this as it is. It will be automatically set based on the values of **`DB_ENDPOINT_ID`** and **`DB_PROXY_HOST`**. #**`verify-full`**\n- **`DB_SSLMODE`**: Set the SSL mode for the database connection. By default, it is set to `verify-full`.\n\nTo get the values for the above environment variables, follow the instructions [here](https://neon.tech/docs/get-started-with-neon/setting-up-a-project#step-3-connect-to-your-neon-database).\n\nOnce the Neon project is successfully created, connection details are generated for accessing the default `neondb` database. These connection details can be saved or retrieved later from the connection details widget on the Neon dashboard. They provide the necessary environment variables for connecting to the database.\n\nFor direct connection, the connection details look like this:\n\n```shell\npsql 'postgresql://\u003cDB_USER\u003e:\u003cDB_PASSWORD\u003e@\u003cDB_HOST\u003e:/\u003cDB_NAME\u003e'\n```\n\nFor example:\n\n```shell\npsql 'postgresql://test:123@ep-test.us-east-2.aws.neon.tech/neondb'\n```\n\nSo, here `DB_USER` is `test`, `DB_PASSWORD` is `123`, `DB_ENDPOINT_ID` is `ep-test`, `DB_PROXY_HOST` is `us-east-2.aws.neon.tech`, and `DB_NAME` is `neondb`.\n\nSome applications open numerous connections, with most eventually becoming inactive. This behavior can often be attributed to database driver limitations, to running many instances of an application, or to applications with serverless functions. With regular PostgreSQL, new connections are rejected when reaching the `max_connections` limit. To overcome this limitation, Neon supports connection pooling using [PgBouncer](https://www.pgbouncer.org/), allowing Neon to support up to 10000 concurrent connections.\n\nEnabling connection pooling in Neon requires adding a `-pooler` suffix to the compute endpoint ID, which is part of the hostname. Connection requests that specify the `-pooler` suffix use a pooled connection.\n\nAdd the `-pooler` suffix to the endpoint ID, as shown:\n\n```shell\npsql 'postgresql://test:123@ep-test-pooler.us-east-2.aws.neon.tech/neondb'\n```\n\nSo, here `DB_USER` is `test`, `DB_PASSWORD` is `123`, `DB_ENDPOINT_ID` is `ep-test-pooler`, `DB_PROXY_HOST` is `us-east-2.aws.neon.tech`, and `DB_NAME` is `neondb`.\n\n#### Instructions for writing SQL queries\n\n1. All SQL queries should be written in the **`queries.sql`** file.\n2. The **`queries.sql`** file should be in the same directory as the **`main.go`** file.\n3. Each SQL query should be on a separate line and should end with a semicolon **`;`**.\n4. Make sure there are no empty lines or extra spaces before or after each SQL query.\n5. The Go program can handle SQL queries with empty lines and white spaces, single-line comments, and multi-line comments, but it's best to write queries in a proper format without unnecessary empty lines or extra spaces.\n\n#### Demonstration\n\nBefore the demonstration, I set up the new project and configured the database connection details in a `.env` file.\n\nI wrote sample queries in the `queries.sql` file. Something like this:\n\n```sql\n-- Create a table\nCREATE TABLE playing_with_neon (id SERIAL PRIMARY KEY, name TEXT NOT NULL, value REAL);\n\n-- Insert some data\nINSERT INTO playing_with_neon (name, value) SELECT 'Data ' || generate_series, random() FROM generate_series(1, 10);\n\n-- Query the table\nSELECT * FROM playing_with_neon;\n\n-- Drop the table\nDROP TABLE playing_with_neon;\n\n```\n\nWhen I execute the `go run main.go` command to run the application, I receive the following output:\n\n```shell\n➜  neon-db-query-executor git:(main) ✗ go run main.go\nQuery: -- Create a table\nCREATE TABLE playing_with_neon (id SERIAL PRIMARY KEY, name TEXT NOT NULL, value REAL)\nTime Taken: 1.836177 seconds\n\nQuery: -- Insert some data\nINSERT INTO playing_with_neon (name, value) SELECT 'Data ' || generate_series, random() FROM generate_series(1, 10)\nTime Taken: 0.251565 seconds\n\n+--------------+--------------+--------------+\n|      ID      |     NAME     |    VALUE     |\n+--------------+--------------+--------------+\n| 0xc000015590 | 0xc0000155b0 | 0xc0000155c0 |\n| 0xc0000155f0 | 0xc000015610 | 0xc000015620 |\n| 0xc000015650 | 0xc000015670 | 0xc000015680 |\n| 0xc0000156b0 | 0xc0000156d0 | 0xc0000156e0 |\n| 0xc000015710 | 0xc000015730 | 0xc000015740 |\n| 0xc000015770 | 0xc000015790 | 0xc0000157a0 |\n| 0xc0000157d0 | 0xc0000157f0 | 0xc000015800 |\n| 0xc000015830 | 0xc000015850 | 0xc000015860 |\n| 0xc000015890 | 0xc0000158b0 | 0xc0000158c0 |\n+--------------+--------------+--------------+\nQuery: -- Query the table\nSELECT * FROM playing_with_neon\nTime Taken: 0.244171 seconds\n\nQuery: -- Drop the table\nDROP TABLE playing_with_neon\nTime Taken: 0.244211 seconds\n\nTotal Time Taken: 2.576124 seconds\n```\n\n## License\n\n[MIT](https://github.com/iamrajiv/neon-db-query-executor/blob/main/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiamrajiv%2Fneon-db-query-executor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiamrajiv%2Fneon-db-query-executor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiamrajiv%2Fneon-db-query-executor/lists"}