Skip to content

Commit 735c104

Browse files
committed
Add configurable request timeout for NDJSON loader
Adds --request-timeout CLI flag to configure the mssql request timeout, with a default of 300000ms (5 minutes). This allows large NDJSON files to be loaded without timing out during bulk insert operations. Also supports MSSQL_REQUEST_TIMEOUT environment variable.
1 parent ae50509 commit 735c104

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

src/load.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ function getDryRunDatabaseConfig(commandOptions: Record<string, unknown>): {
2323
password: string;
2424
database: string;
2525
trustServerCertificate: boolean | undefined;
26+
requestTimeout: number | undefined;
2627
} {
2728
return {
2829
host: (commandOptions.host as string | undefined) ?? "localhost",
@@ -33,6 +34,7 @@ function getDryRunDatabaseConfig(commandOptions: Record<string, unknown>): {
3334
trustServerCertificate: commandOptions.trustServerCertificate as
3435
| boolean
3536
| undefined,
37+
requestTimeout: commandOptions.requestTimeout as number | undefined,
3638
};
3739
}
3840

@@ -58,6 +60,7 @@ function buildLoaderOptions(
5860
trustServerCertificate: commandOptions.trustServerCertificate as
5961
| boolean
6062
| undefined,
63+
requestTimeout: commandOptions.requestTimeout as number | undefined,
6164
});
6265

6366
return {
@@ -119,6 +122,12 @@ export function createLoadCommand(): Command {
119122
.option("--password <password>", "Database password")
120123
.option("--database <database>", "Database name")
121124
.option("--trust-server-certificate", "Trust server certificate", false)
125+
.option(
126+
"--request-timeout <ms>",
127+
"Request timeout in milliseconds",
128+
parseInt,
129+
300000,
130+
)
122131
.option(
123132
"--pattern <pattern>",
124133
"File naming pattern (default: {ResourceType}.ndjson)",

src/loader/connection.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export async function createConnectionPool(
2323
user: config.user,
2424
password: config.password,
2525
database: config.database,
26+
requestTimeout: config.requestTimeout,
2627
options: {
2728
trustServerCertificate: config.trustServerCertificate ?? false,
2829
// Enable multiple active result sets for parallel operations.
@@ -103,12 +104,19 @@ export function getDatabaseConfigFromEnv(
103104
overrides?.trustServerCertificate ??
104105
process.env.MSSQL_TRUST_SERVER_CERTIFICATE === "true";
105106

107+
const requestTimeout =
108+
overrides?.requestTimeout ??
109+
(process.env.MSSQL_REQUEST_TIMEOUT
110+
? parseInt(process.env.MSSQL_REQUEST_TIMEOUT, 10)
111+
: undefined);
112+
106113
return {
107114
host,
108115
port,
109116
user,
110117
password,
111118
database,
112119
trustServerCertificate,
120+
requestTimeout,
113121
};
114122
}

src/loader/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export interface DatabaseConfig {
2020
database: string;
2121
/** Whether to trust the server certificate. */
2222
trustServerCertificate?: boolean;
23+
/** Request timeout in milliseconds (default: 300000). */
24+
requestTimeout?: number;
2325
}
2426

2527
/**

0 commit comments

Comments
 (0)