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