@spinajs/orm-mssql
v3.0.29
Published
orm mssql integration
Readme
@spinajs/orm-mssql
The Microsoft SQL Server dialect driver for @spinajs/orm, built on
@spinajs/orm-sql.
Install
npm install @spinajs/orm @spinajs/orm-mssqlUsage
import { DI } from '@spinajs/di';
import { Orm } from '@spinajs/orm';
import { MsSqlOrmDriver } from '@spinajs/orm-mssql';
DI.register(MsSqlOrmDriver).as('orm-driver-mssql');
await DI.resolve(Orm);// configuration
{
db: {
DefaultConnection: 'mssql',
Connections: [
{
Name: 'mssql',
Driver: 'orm-driver-mssql',
Host: '127.0.0.1',
Port: 1433,
User: 'sa',
Password: 'Str0ng!Passw0rd',
Database: 'app',
Options: { Schema: 'dbo', Encrypt: false, TrustServerCertificate: true },
},
],
},
}What is distinctive
AliasSeparatordefaults to#, not$—$begins a pseudo-column in T-SQL.- Backticks are stripped from every statement before it is sent, since T-SQL quotes with
[brackets]. - Three-part table names —
[database].[schema].[table], viaOptions.Schema. OFFSET ... FETCH NEXTinstead ofLIMIT. A query withoutorderBy()getsORDER BY (SELECT NULL), since T-SQL requires anORDER BYbeforeOFFSET.DELETE TOP (n)for limited deletes.INSERT IGNOREandINSERT OR REPLACEthrow —InsertBehaviour.InsertOrIgnoreandInsertOrReplaceare unsupported; upserts are aMERGE.- No native
SET,ENUMorJSON: they areNVARCHARcolumns,whereInSet/whereNotInSetuseCHARINDEX, and@Json()is required for JSON columns. - DDL is transactional, unlike MySQL —
Migration.Transaction.Mode = PerMigrationgives a genuinely atomic migration.
Documentation
Full documentation lives in docs/orm-mssql/.
| | Page | | --- | --- | | 01 | Connection and configuration | | 02 | Executing statements | | 03 | Transactions | | 04 | Inserts and upserts | | 05 | Query dialect | | 06 | Schema dialect | | 07 | Value conversion | | 08 | Extending the driver |
Development
npm test # mssql.test.ts needs a SQL Server on localhost
npm run build