@samveys/mssql
Dari packages/mssql/README.md di repository framework.
Halaman ini belum diterjemahkan. Kamu sedang membaca versi bahasa Inggris.
SQL Server driver for @samveys/database. It talks TDS through mssql (over tedious, pure JavaScript), which is imported on first connect, so an app that never uses SQL Server never loads it.
import { createDatabaseManager, defineDatabaseConfig } from '@samveys/database'
import { mssql } from '@samveys/mssql'
const db = createDatabaseManager(
defineDatabaseConfig({
default: 'main',
connections: { main: mssql({ host: '127.0.0.1', user: 'sa', password: process.env.MSSQL_PASSWORD ?? '', database: 'app' }) },
}),
)
const rows = await db.from('users').where('id', 1).orderBy('id').limit(10).get()
console.log(rows.length)
await db.close()Dialect
- Identifiers are bracket-quoted (
[users]); bindings are@p1, @p2, …with an explicit SQL type per value. - Pagination is
order by … offset @p rows fetch next @p rows only; a query withoutorderBy()getsorder by (select null). insertusesOUTPUT inserted.*, so the generated rows come back likeRETURNING.- Values:
bit↔ boolean,bigint↔number | bigint(every digit kept),date↔Temporal.PlainDate,datetime2↔Temporal.PlainDateTime,datetimeoffset↔Temporal.Instant, microseconds kept. - Savepoints are
save transaction/rollback transaction. DDL is transactional. - Cancellation sends a TDS attention (
request.cancel()), and the connection stays pooled. - Errors are
SVS_E071with the SQL Server error number inmeta.engineCode(2627 unique, 547 foreign key, 515 not null).
Conformance
SVS_REQUIRE_DOCKER=1 node --no-warnings --test packages/mssql/test/conformance.test.ts starts a throwaway container, runs the conformance cases, and removes the container. On x64 the image is mcr.microsoft.com/mssql/server:2022-latest. On arm64 it is mcr.microsoft.com/azure-sql-edge:latest, because the amd64 SQL Server image cannot start under QEMU. SVS_MSSQL_IMAGE overrides the image. The migrations area is skipped: the schema builder has no SQL Server catalog queries yet (ADR 0014).