sql-schema-reader is a JavaScript/TypeScript library designed to programmatically extract detailed schema information from SQL Server databases. It leverages the `Tedious.js` driver for database connectivity. The package, currently at version 3.4.1, focuses on providing programmatic access to metadata such as table names, comprehensive column definitions (including nullability, types, lengths, primary/foreign keys), stored procedures, scalar functions, and table-valued functions. Its release cadence appears stable, with `3.x` being the current major version. Key differentiators include its comprehensive schema introspection capabilities specifically tailored for SQL Server, allowing developers to retrieve definitions, columns, and relationships with ease, contrasting with more generic ORM schema tools or .NET specific solutions.
npm install sql-schema-readerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to connect to a SQL Server database, retrieve a list of all table names, detailed information for the first detected table, and lists of stored procedure and table-valued function names. It includes basic error handling for common connection issues.
Consult the official `sql-schema-reader` and `tedious.js` release notes and changelogs for specific migration instructions for your target version. Update your code to match new API signatures and configuration requirements.
Ensure your Node.js environment is at version 18.17 or higher to guarantee compatibility with `tedious` and `sql-schema-reader`.
Double-check your `config` object for accuracy. Verify network connectivity to the SQL Server and ensure the provided `username` has sufficient permissions (e.g., `VIEW DEFINITION`) to access schema metadata in the specified `database`.
Always use `await` when calling `sql-schema-reader` methods within an `async` function, or chain `.then()` and `.catch()` to handle the Promise resolution.
Verify that the `username` and `password` fields in your `config` object exactly match a valid SQL Server login with appropriate database permissions.
Ensure the `server` address is correct, the SQL Server instance is running, the port is open (default 1433), and no firewalls are blocking the connection from your application's host.
If using ESM, ensure `import schemaReader from 'sql-schema-reader';` and call methods as `schemaReader.tableNames()`. If using CommonJS, `const schemaReader = require('sql-schema-reader');` is correct.Check the exact spelling and casing of the object name. Ensure the object exists in the target `database` and `schema`. Verify the database user has `VIEW DEFINITION` permission on the schema and objects.