npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

restmssql

v0.2.0

Published

Zero-code REST API server for SQL Server with OData support

Readme

RestMSSQL

CI

Zero-code REST API server for SQL Server. Point it at a database — it introspects the schema and generates a full OData-compatible REST API automatically. No code required.

Quick Start

npm install

# Using individual flags
npx tsx src/index.ts \
  --host localhost \
  --database mydb \
  --user sa \
  --password "YourP@ssword" \
  --trust-server-certificate

# Or using a connection string
npx tsx src/index.ts \
  --connection "Server=localhost;Database=mydb;User Id=sa;Password=YourP@ssword;TrustServerCertificate=true"

# API:     http://localhost:3000/api
# Swagger: http://localhost:3000/swagger

CLI Usage

After installing globally with npm install -g restmssql, the restmssql command is available:

# Show help
restmssql --help

# Show version
restmssql --version

# Show project info
restmssql --about

# Start the API server
restmssql --database mydb --user sa --password "YourP@ssword" --trust-server-certificate

# Use a connection string
restmssql --connection "Server=localhost;Database=mydb;User Id=sa;Password=YourP@ssword"

# Expose multiple schemas in read-write mode on a custom port
restmssql --database mydb --user sa --password "YourP@ssword" \
  --schemas dbo,sales,hr \
  --no-readonly \
  --server-port 8080

# Listen on all interfaces (for Docker/remote access)
restmssql --database mydb --user sa --password "YourP@ssword" \
  --listen-host 0.0.0.0

# Exclude specific tables
restmssql --database mydb --user sa --password "YourP@ssword" \
  --exclude-tables AuditLog,TempData

# Custom pagination
restmssql --database mydb --user sa --password "YourP@ssword" \
  --default-page-size 50 --max-page-size 500

# Debug logging
restmssql --database mydb --user sa --password "YourP@ssword" --log-level debug

Features

  • Auto-generated endpoints for all tables, views, and stored procedures
  • OData query support$filter, $select, $orderby, $top, $skip, $expand, $count
  • JSON and XML responses via Accept header
  • Swagger UI at /swagger with auto-generated OpenAPI spec
  • Read-only by default — enable writes with --no-readonly
  • Multi-schema support — expose specific schemas with --schemas dbo,sales
  • Composite primary keysGET /api/Table/Key1=val1,Key2=val2
  • Stored procedure execution via POST /rpc/<name>
  • Relationship expansion — auto-detects foreign keys for $expand with nested query options

API Endpoints

| Method | URL | Description | | -------- | ------------------- | -------------------------------------- | | GET | /api | Service document (lists all resources) | | GET | /api/<Table> | List rows with OData query options | | GET | /api/<Table>/:id | Get single row by primary key | | POST | /api/<Table> | Create row (requires --no-readonly) | | PATCH | /api/<Table>/:id | Update row (requires --no-readonly) | | PUT | /api/<Table>/:id | Replace row (requires --no-readonly) | | DELETE | /api/<Table>/:id | Delete row (requires --no-readonly) | | POST | /rpc/<Procedure> | Execute stored procedure | | GET | /api/$metadata | OData CSDL metadata (XML) | | GET | /api/openapi.json | OpenAPI 3.0 spec | | GET | /swagger | Swagger UI |

Non-dbo schemas use dotted names: /api/sales.Orders

OData Query Examples

# Filter
GET /api/Products?$filter=Price gt 100 and InStock eq true

# Select specific columns
GET /api/Products?$select=Name,Price

# Order and paginate
GET /api/Products?$orderby=Price desc&$top=10&$skip=20

# Expand related entities (with nested options)
GET /api/Products?$expand=Categories($select=Name)
GET /api/Orders?$expand=OrderItems($top=5;$orderby=UnitPrice desc)

# Count
GET /api/Products?$count=true

# Combine
GET /api/Products?$filter=contains(Name,'phone')&$select=Name,Price&$orderby=Price desc&$top=5

# String functions
GET /api/Products?$filter=startswith(Name,'Lap')
GET /api/Products?$filter=tolower(Name) eq 'laptop'

# Null checks
GET /api/Products?$filter=Description eq null

# Composite primary key
GET /api/StockLevels/WarehouseId=1,ProductId=2

# Stored procedure
POST /rpc/GetProductsByCategory
Content-Type: application/json
{"CategoryId": 1}

# XML response
curl -H "Accept: application/xml" http://localhost:3000/api/Products

Configuration

Precedence: CLI flags > environment variables > config file > defaults.

CLI Flags

--connection <string>        Connection string (Server=...;Database=...;User Id=...;Password=...)
--host <host>                SQL Server host (default: localhost)
--port <port>                SQL Server port (default: 1433)
--database <database>        Database name (required)
--user <user>                Database user
--password <password>        Database password
--encrypt                    Encrypt connection (default: true)
--trust-server-certificate   Trust server certificate
--server-port <port>         HTTP server port (default: 3000)
--no-readonly                Enable write operations
--no-cors                    Disable CORS
--schemas <schemas>          Comma-separated schemas (default: dbo)
--exclude-tables <tables>    Comma-separated tables to exclude
--default-page-size <size>   Default page size (default: 100)
--max-page-size <size>       Maximum page size (default: 1000)
--log-level <level>          fatal|error|warn|info|debug|trace (default: info)

Environment Variables

MSSQLREST_HOST=localhost
MSSQLREST_DATABASE=mydb
MSSQLREST_USER=sa
MSSQLREST_PASSWORD=secret
MSSQLREST_SERVER_PORT=3000
MSSQLREST_READONLY=false
MSSQLREST_SCHEMAS=dbo,sales

Config File

Create .mssqlrestrc.json or mssqlrest.config.js:

{
  "host": "localhost",
  "database": "mydb",
  "user": "sa",
  "schemas": ["dbo", "sales"],
  "readonly": true
}

Development

# Quick start with Docker SQL Server + API
./dev.sh

# Or manually
npm run docker:up
npm run dev -- --database mssqlrest_test --user sa --password "YourStr0ngP@ssword!" --trust-server-certificate --schemas dbo,sales,hr

# Tests
npm run test:unit
npm run test:integration    # requires Docker

# Lint, format, typecheck
npm run lint
npm run format
npm run typecheck

Releasing

This project uses Conventional Commits and automated versioning.

npm run release             # auto-detect bump from commits
git push --follow-tags      # triggers GitHub Release

See CONTRIBUTING.md for commit format, branching, and development details.

Architecture

Request -> Content Negotiation -> OData Parser -> Query Builder -> SQL Server
                                                                       |
Response <- JSON/XML Formatter <- ----------------------------- Result Set

Schema introspection queries INFORMATION_SCHEMA and sys.* catalog views on startup to discover tables, views, columns, primary keys, foreign keys, and stored procedures. Routes are dynamically generated from the discovered schema.

Security: All user input is parameterized. Identifiers are validated against the introspected schema and bracket-quoted. LIKE wildcards are escaped. Results are always paginated. Security headers are set on all responses.

License

MIT