SafeQuery 0.1.1

There is a newer version of this package available.
See the version list below for details.
dotnet tool install --global SafeQuery --version 0.1.1
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local SafeQuery --version 0.1.1
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=SafeQuery&version=0.1.1
                    
nuke :add-package SafeQuery --version 0.1.1
                    

SafeQuery

build NuGet NuGet downloads

A small .NET CLI that runs read-only SQL against a SQL Server database and prints the result as a Markdown table. It also generates a Mermaid/SVG diagram of the database schema.

It was built so AI coding agents (and humans in a hurry) can look at real data without being able to change it.

Safety note: SafeQuery rejects anything that isn't a single SELECT/WITH statement and blocks write keywords (INSERT, UPDATE, DELETE, EXEC, INTO, ...). This is a keyword filter, not a security boundary. Always connect with a database login that only has read permission.

Install

dotnet tool install --global SafeQuery

Configure

SafeQuery looks for the connection string in this order:

  1. ~/.safequery/settings.json, using the entry for the current directory or the nearest parent up to the git root (outside a git repo, the current directory only)
  2. The ConnectionStrings__DefaultConnection environment variable
  3. An interactive prompt (with an example connection string), whose answer is saved to ~/.safequery/settings.json under the git root

Each repo gets its own connection, so different repos can point at different databases.

{
  "Repositories": {
    "/Users/me/Github/MyApp": "Server=...;Database=...;User Id=...;Password=...;"
  }
}

If SQL is piped in on stdin there is no terminal to prompt on, so run safequery once interactively first (or set the env var).

Usage

safequery "select top 10 * from dbo.company"   # inline query
safequery -f query.sql                         # from a file
type query.sql | safequery                     # piped stdin

safequery --create-diagram                     # writes ./InternalDocuments/database-schema.md and .svg
safequery --create-diagram docs/schema.md      # custom path

Writes are rejected every time, including inside a transaction.

License

Apache-2.0. See LICENSE.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last Updated
0.3.1 89 10/25/2026
0.1.1 95 10/23/2026
0.1.0 91 10/23/2026
0.0.1 96 10/23/2026