( options: MssqlClientConfig )
| 256 | |
| 257 | let clientIdCounter = 0 |
| 258 | |
| 259 | /** |
| 260 | * Creates a scoped Microsoft SQL Server client backed by a connection pool, with transaction and stored procedure support. Streaming queries are not implemented. |
| 261 | * |
| 262 | * @category constructors |
| 263 | * @since 4.0.0 |
| 264 | */ |
| 265 | export const make = ( |
| 266 | options: MssqlClientConfig |
| 267 | ): Effect.Effect<MssqlClient, SqlError, Scope.Scope | Reactivity.Reactivity> => |
| 268 | Effect.gen(function*() { |
| 269 | const parameterTypes = options.parameterTypes ?? defaultParameterTypes |
| 270 | const compiler = makeCompiler(options.transformQueryNames) |
| 271 | |
| 272 | const transformRows = options.transformResultNames ? |
| 273 | Statement.defaultTransforms( |
| 274 | options.transformResultNames |
| 275 | ).array : |
| 276 | undefined |
| 277 | const spanAttributes: ReadonlyArray<[string, unknown]> = [ |
| 278 | ...(options.spanAttributes ? Object.entries(options.spanAttributes) : []), |
| 279 | [ATTR_DB_SYSTEM_NAME, "microsoft.sql_server"], |
| 280 | [ATTR_DB_NAMESPACE, options.database ?? "master"], |
| 281 | [ATTR_SERVER_ADDRESS, options.server], |
| 282 | [ATTR_SERVER_PORT, options.port ?? 1433] |
| 283 | ] |
| 284 | |
| 285 | // oxlint-disable-next-line prefer-const |
| 286 | let pool: Pool.Pool<MssqlConnection, SqlError> |
| 287 | |
| 288 | const makeConnection = Effect.gen(function*() { |
| 289 | const conn = new Tedious.Connection({ |
| 290 | options: { |
| 291 | port: options.port, |
| 292 | database: options.database, |
| 293 | trustServerCertificate: options.trustServer ?? false, |
| 294 | multiSubnetFailover: options.multiSubnetFailover, |
| 295 | connectTimeout: options.connectTimeout |
| 296 | ? Duration.toMillis(Duration.fromInputUnsafe(options.connectTimeout)) |
| 297 | : undefined, |
| 298 | rowCollectionOnRequestCompletion: true, |
| 299 | useColumnNames: false, |
| 300 | instanceName: options.instanceName, |
| 301 | encrypt: options.encrypt ?? true, |
| 302 | cancelTimeout: options.cancelTimeout |
| 303 | ? Duration.toMillis(Duration.fromInputUnsafe(options.cancelTimeout)) |
| 304 | : undefined, |
| 305 | connectionRetryInterval: options.connectionRetryInterval |
| 306 | ? Duration.toMillis(Duration.fromInputUnsafe(options.connectionRetryInterval)) |
| 307 | : undefined, |
| 308 | maxRetriesOnTransientErrors: options.maxRetriesOnTransientErrors |
| 309 | } as ConnectionOptions, |
| 310 | server: options.server, |
| 311 | authentication: { |
| 312 | type: (options.authType as any) ?? "default", |
| 313 | options: { |
| 314 | userName: options.username, |
| 315 | password: options.password |
no test coverage detected
searching dependent graphs…