plugin-data-source-mssql
v2.0.2
Published
External MSSQL data source support for NocoBase.
Downloads
295
Readme
plugin-data-source-mssql
External MSSQL (Microsoft SQL Server) data source plugin for NocoBase 2.x.
Features
🔌 External Data Source Integration
- Connect to external Microsoft SQL Server databases as a NocoBase data source
- Extends
SequelizeDataSource— fully integrated with the core persistence pipeline - Collections are persisted across app restarts via
dataSourcesCollectionsmetadata table - Support for multiple schemas and table prefix filtering
📊 Collection Management
- Automatic Introspection: Discover all tables from the external database via
readTables() - Selective Loading: Choose specific tables to import via
loadTables() - Field Type Mapping: MSSQL types automatically mapped to NocoBase field types
- Primary Key Detection: Auto-detects PKs via Sequelize + fallback
sys.indexesquery
⚡ Performance Optimizations
- Query timeout:
requestTimeoutset to 120s (tedious default was 15s) - Connection pool:
max: 10,min: 2warm connections,acquire: 60s - Simple pagination: Skips expensive
COUNT(*)on large tables — usesLIMIT+1instead - SET NOCOUNT ON: Reduces per-statement overhead
- Cursor-based pagination:
MssqlSmartCursorBuilderfor efficient large dataset queries (avoidsOFFSET/FETCHdegradation) - All timeouts and pool settings are user-overridable via data source configuration
🗄️ Data Type Mapping
| MSSQL Type | NocoBase Type | UI Component |
|------------|---------------|--------------|
| int, bigint, smallint, tinyint | integer / bigInt | InputNumber |
| decimal, numeric, money | decimal | InputNumber |
| float, real | float | InputNumber |
| varchar, nvarchar, char, nchar | string | Input |
| text, ntext | text | Input.TextArea |
| bit | boolean | Checkbox |
| date | dateOnly | DatePicker |
| time | time | TimePicker |
| datetime, datetime2, smalldatetime | datetimeNoTz | DatePicker |
| datetimeoffset | datetimeTz | DatePicker |
| uniqueidentifier | uuid | Input |
🕐 DateTime Handling
- Automatic conversion of JavaScript
Dateobjects to MSSQL-compatible format beforeFind/beforeCounthooks transform date values in WHERE clauses- Preserves Sequelize operator symbols (
Op.and,Op.like, etc.) usingReflect.ownKeys()
🔒 Security
- Encrypted connection support (
encryptoption) - Configurable connection pooling
- Secure credential handling
Architecture
plugin-data-source-mssql/
├── src/server/
│ ├── plugin.ts # Plugin registration + destroy middleware
│ ├── data-source/
│ │ ├── MssqlExternalDataSource.ts # Main class (extends SequelizeDataSource)
│ │ ├── MssqlIntrospector.ts # MSSQL-specific DatabaseIntrospector
│ │ ├── MssqlCollectionManager.ts # Collection manager with MSSQL repo
│ │ ├── MssqlRepository.ts # Repository with cursor pagination
│ │ └── MssqlSmartCursorBuilder.ts # Cursor-based query builder
│ ├── controllers/
│ │ └── ExternalMssqlController.ts # testConnection API
│ └── dialects/
│ └── mssql-dialect.ts # MSSQL dialect registration
├── src/client/
│ └── ... # Configuration UI components
└── scripts/
└── copy-tedious.js # Embeds tedious + deps into dist/Configuration
interface MssqlDataSourceOptions {
host: string; // Server hostname
port?: number; // Port (default: 1433)
database: string; // Database name
username: string; // SQL Server username
password: string; // Password
schema?: string; // Default schema (default: 'dbo')
encrypt?: boolean; // Use encrypted connection
tablePrefix?: string; // Table name prefix filter
dialectOptions?: { // Additional Tedious driver options
options?: {
trustServerCertificate?: boolean;
enableArithAbort?: boolean;
requestTimeout?: number; // Query timeout ms (default: 120000)
connectTimeout?: number; // Connection timeout ms (default: 30000)
};
};
pool?: { // Connection pool settings
max?: number; // Max connections (default: 10)
min?: number; // Min connections (default: 2)
acquire?: number; // Acquire timeout ms (default: 60000)
idle?: number; // Idle timeout ms (default: 10000)
};
}API Endpoints
| Endpoint | Description |
|----------|-------------|
| POST /api/external-mssql:testConnection | Test MSSQL connection |
| GET /api/dataSources.collections:list | List loaded collections |
| Standard CRUD via data source routing | list, get, create, update, destroy |
Requirements
- NocoBase >= 2.0.0
- Microsoft SQL Server 2012 or later
- Node.js >= 18
Installation
# From tgz file
yarn pm add ./plugin-data-source-mssql-2.0.1.tgz
# Enable the plugin
yarn pm enable plugin-data-source-mssqlChangelog
2.0.1
- Fix: Filter not working on MSSQL collections (Sequelize Op symbols dropped by
Object.entries) - Perf: Increased
requestTimeoutto 120s (was 15s tedious default) - Perf: Connection pool tuned (max: 10, min: 2)
- Perf:
simplePaginateenabled by default — skipsCOUNT(*)on large tables - Perf:
SET NOCOUNT ONhook for reduced overhead
2.0.0
- Refactored to extend
SequelizeDataSourcefor core persistence pipeline integration - Added
MssqlIntrospectorfor MSSQL-specific field type mapping - Collections now persist across app restarts
- Updated peerDependencies to NocoBase 2.x
- License changed to MIT
License
MIT
