( options: MssqlClientConfig )
| 121 | * @since 1.0.0 |
| 122 | */ |
| 123 | export const make = ( |
| 124 | options: MssqlClientConfig |
| 125 | ): Effect.Effect<MssqlClient, SqlError, Scope.Scope | Reactivity.Reactivity> => |
| 126 | Effect.gen(function*() { |
| 127 | const parameterTypes = options.parameterTypes ?? defaultParameterTypes |
| 128 | const compiler = makeCompiler(options.transformQueryNames) |
| 129 | |
| 130 | const transformRows = options.transformResultNames ? |
| 131 | Statement.defaultTransforms( |
| 132 | options.transformResultNames |
| 133 | ).array : |
| 134 | undefined |
| 135 | const spanAttributes: ReadonlyArray<[string, unknown]> = [ |
| 136 | ...(options.spanAttributes ? Object.entries(options.spanAttributes) : []), |
| 137 | [ATTR_DB_SYSTEM_NAME, "microsoft.sql_server"], |
| 138 | [ATTR_DB_NAMESPACE, options.database ?? "master"], |
| 139 | [ATTR_SERVER_ADDRESS, options.server], |
| 140 | [ATTR_SERVER_PORT, options.port ?? 1433] |
| 141 | ] |
| 142 | |
| 143 | // eslint-disable-next-line prefer-const |
| 144 | let pool: Pool.Pool<MssqlConnection, SqlError> |
| 145 | |
| 146 | const makeConnection = Effect.gen(function*() { |
| 147 | const conn = new Tedious.Connection({ |
| 148 | options: { |
| 149 | port: options.port, |
| 150 | database: options.database, |
| 151 | trustServerCertificate: options.trustServer ?? true, |
| 152 | connectTimeout: options.connectTimeout |
| 153 | ? Duration.toMillis(Duration.decode(options.connectTimeout)) |
| 154 | : undefined, |
| 155 | rowCollectionOnRequestCompletion: true, |
| 156 | useColumnNames: false, |
| 157 | instanceName: options.instanceName, |
| 158 | encrypt: options.encrypt ?? false |
| 159 | } as ConnectionOptions, |
| 160 | server: options.server, |
| 161 | authentication: { |
| 162 | type: (options.authType as any) ?? "default", |
| 163 | options: { |
| 164 | userName: options.username, |
| 165 | password: options.password |
| 166 | ? Redacted.value(options.password) |
| 167 | : undefined |
| 168 | } |
| 169 | } |
| 170 | }) |
| 171 | |
| 172 | yield* Effect.addFinalizer(() => Effect.sync(() => conn.close())) |
| 173 | |
| 174 | yield* Effect.async<void, SqlError>((resume) => { |
| 175 | conn.connect((cause) => { |
| 176 | if (cause) { |
| 177 | resume(Effect.fail(new SqlError({ cause, message: "Failed to connect" }))) |
| 178 | } else { |
| 179 | resume(Effect.void) |
| 180 | } |
no test coverage detected