@phonemyatt/squn
@phonemyatt/squn
Enumerations
ErrorCode
Defined in: src/errors/codes.ts:8
Every error code in the library. Grouped by domain, prefixed SQUN_.
Codes are string literals so they survive serialisation (JSON logs, structured error responses) without losing meaning. A const enum is used so TypeScript inlines the values at compile time — no runtime object is emitted.
Enumeration Members
ADAPTER_DRIVER_ERROR
ADAPTER_DRIVER_ERROR: "SQUN_ADPT_002";Defined in: src/errors/codes.ts:43
ADAPTER_NOT_SUPPORTED
ADAPTER_NOT_SUPPORTED: "SQUN_ADPT_001";Defined in: src/errors/codes.ts:42
AUTH_INVALID_CREDENTIALS
AUTH_INVALID_CREDENTIALS: "SQUN_AUTH_002";Defined in: src/errors/codes.ts:69
AUTH_MISSING
AUTH_MISSING: "SQUN_AUTH_001";Defined in: src/errors/codes.ts:68
AUTH_PROVIDER_FAILED
AUTH_PROVIDER_FAILED: "SQUN_AUTH_005";Defined in: src/errors/codes.ts:72
AUTH_TOKEN_EXPIRED
AUTH_TOKEN_EXPIRED: "SQUN_AUTH_004";Defined in: src/errors/codes.ts:71
AUTH_UNSUPPORTED_TYPE
AUTH_UNSUPPORTED_TYPE: "SQUN_AUTH_003";Defined in: src/errors/codes.ts:70
CONFIG_ENV_CONFLICT
CONFIG_ENV_CONFLICT: "SQUN_CFG_005";Defined in: src/errors/codes.ts:65
CONFIG_INVALID_VALUE
CONFIG_INVALID_VALUE: "SQUN_CFG_002";Defined in: src/errors/codes.ts:62
CONFIG_MISSING
CONFIG_MISSING: "SQUN_CFG_001";Defined in: src/errors/codes.ts:61
CONFIG_PRODUCTION_GUARD
CONFIG_PRODUCTION_GUARD: "SQUN_CFG_003";Defined in: src/errors/codes.ts:63
CONFIG_URL_MALFORMED
CONFIG_URL_MALFORMED: "SQUN_CFG_004";Defined in: src/errors/codes.ts:64
CONN_FAILOVER_EXHAUSTED
CONN_FAILOVER_EXHAUSTED: "SQUN_CONN_004";Defined in: src/errors/codes.ts:13
CONN_GROUP_NO_WRITE
CONN_GROUP_NO_WRITE: "SQUN_CONN_003";Defined in: src/errors/codes.ts:12
CONN_MULTI_INVALID
CONN_MULTI_INVALID: "SQUN_CONN_002";Defined in: src/errors/codes.ts:11
CONN_TENANT_NOT_FOUND
CONN_TENANT_NOT_FOUND: "SQUN_CONN_005";Defined in: src/errors/codes.ts:14
CONN_UNKNOWN
CONN_UNKNOWN: "SQUN_CONN_001";Defined in: src/errors/codes.ts:10
INJECTION_DETECTED
INJECTION_DETECTED: "SQUN_SEC_001";Defined in: src/errors/codes.ts:52
INTERNAL_ERROR
INTERNAL_ERROR: "SQUN_INTERNAL_001";Defined in: src/errors/codes.ts:75
INVALID_IDENTIFIER
INVALID_IDENTIFIER: "SQUN_SEC_002";Defined in: src/errors/codes.ts:53
MULTI_STATEMENT_BLOCKED
MULTI_STATEMENT_BLOCKED: "SQUN_SEC_005";Defined in: src/errors/codes.ts:56
MULTIPLE_ROWS_FOUND
MULTIPLE_ROWS_FOUND: "SQUN_QUERY_004";Defined in: src/errors/codes.ts:20
NO_ROWS_FOUND
NO_ROWS_FOUND: "SQUN_QUERY_003";Defined in: src/errors/codes.ts:19
NULL_VIOLATION
NULL_VIOLATION: "SQUN_MAP_001";Defined in: src/errors/codes.ts:23
PARAM_EXTRA
PARAM_EXTRA: "SQUN_VAL_002";Defined in: src/errors/codes.ts:29
PARAM_MISSING
PARAM_MISSING: "SQUN_VAL_001";Defined in: src/errors/codes.ts:28
PLACEHOLDER_MISMATCH
PLACEHOLDER_MISMATCH: "SQUN_SEC_006";Defined in: src/errors/codes.ts:57
POOL_QUEUE_FULL
POOL_QUEUE_FULL: "SQUN_POOL_002";Defined in: src/errors/codes.ts:39
QUERY_EXECUTION_FAILED
QUERY_EXECUTION_FAILED: "SQUN_QUERY_001";Defined in: src/errors/codes.ts:17
QUERY_TIMEOUT
QUERY_TIMEOUT: "SQUN_QUERY_002";Defined in: src/errors/codes.ts:18
RAW_SQL_BLOCKED
RAW_SQL_BLOCKED: "SQUN_SEC_003";Defined in: src/errors/codes.ts:54
READONLY_DDL_BLOCKED
READONLY_DDL_BLOCKED: "SQUN_READONLY_004";Defined in: src/errors/codes.ts:49
READONLY_EXECUTE_BLOCKED
READONLY_EXECUTE_BLOCKED: "SQUN_READONLY_003";Defined in: src/errors/codes.ts:48
READONLY_TX_WRITE
READONLY_TX_WRITE: "SQUN_READONLY_002";Defined in: src/errors/codes.ts:47
READONLY_WRITE_BLOCKED
READONLY_WRITE_BLOCKED: "SQUN_READONLY_001";Defined in: src/errors/codes.ts:46
SQL_VALIDATION_FAILED
SQL_VALIDATION_FAILED: "SQUN_SEC_004";Defined in: src/errors/codes.ts:55
TVP_EMPTY
TVP_EMPTY: "SQUN_VAL_004";Defined in: src/errors/codes.ts:31
TVP_SCHEMA_MISMATCH
TVP_SCHEMA_MISMATCH: "SQUN_VAL_003";Defined in: src/errors/codes.ts:30
TX_ALREADY_CLOSED
TX_ALREADY_CLOSED: "SQUN_TX_003";Defined in: src/errors/codes.ts:36
TX_COMMIT_FAILED
TX_COMMIT_FAILED: "SQUN_TX_001";Defined in: src/errors/codes.ts:34
TX_ROLLBACK_FAILED
TX_ROLLBACK_FAILED: "SQUN_TX_002";Defined in: src/errors/codes.ts:35
TYPE_CONVERSION_FAILED
TYPE_CONVERSION_FAILED: "SQUN_MAP_003";Defined in: src/errors/codes.ts:25
UNKNOWN_COLUMN
UNKNOWN_COLUMN: "SQUN_MAP_002";Defined in: src/errors/codes.ts:24
UNRESOLVED_TVP_SENTINEL
UNRESOLVED_TVP_SENTINEL: "SQUN_SEC_007";Defined in: src/errors/codes.ts:58
EventCode
Defined in: src/logging/logger.ts:5
Lifecycle event codes — used in debug/info/warn log entries with no associated error.
Enumeration Members
CONN_CLOSED
CONN_CLOSED: "SQUN_EVT_004";Defined in: src/logging/logger.ts:9
CONN_OPENED
CONN_OPENED: "SQUN_EVT_003";Defined in: src/logging/logger.ts:8
POOL_ACQUIRED
POOL_ACQUIRED: "SQUN_EVT_010";Defined in: src/logging/logger.ts:15
POOL_RELEASED
POOL_RELEASED: "SQUN_EVT_011";Defined in: src/logging/logger.ts:16
QUERY_END
QUERY_END: "SQUN_EVT_002";Defined in: src/logging/logger.ts:7
QUERY_START
QUERY_START: "SQUN_EVT_001";Defined in: src/logging/logger.ts:6
RAW_SQL_USED
RAW_SQL_USED: "SQUN_EVT_009";Defined in: src/logging/logger.ts:14
SLOW_QUERY
SLOW_QUERY: "SQUN_EVT_008";Defined in: src/logging/logger.ts:13
TVP_MATERIALISED
TVP_MATERIALISED: "SQUN_EVT_012";Defined in: src/logging/logger.ts:17
TX_COMMIT
TX_COMMIT: "SQUN_EVT_006";Defined in: src/logging/logger.ts:11
TX_ROLLBACK
TX_ROLLBACK: "SQUN_EVT_007";Defined in: src/logging/logger.ts:12
TX_START
TX_START: "SQUN_EVT_005";Defined in: src/logging/logger.ts:10
IsolationLevel
Defined in: src/transaction/isolation.ts:1
Enumeration Members
READ_COMMITTED
READ_COMMITTED: "READ COMMITTED";Defined in: src/transaction/isolation.ts:3
READ_UNCOMMITTED
READ_UNCOMMITTED: "READ UNCOMMITTED";Defined in: src/transaction/isolation.ts:2
REPEATABLE_READ
REPEATABLE_READ: "REPEATABLE READ";Defined in: src/transaction/isolation.ts:4
SERIALIZABLE
SERIALIZABLE: "SERIALIZABLE";Defined in: src/transaction/isolation.ts:5
SNAPSHOT
SNAPSHOT: "SNAPSHOT";Defined in: src/transaction/isolation.ts:6
Classes
AdapterError
Defined in: src/errors/types.ts:9
Base class for every error thrown by Squn.
Subclasses set a narrower code domain but never override the shape — every SqunError carries a code, structured context, a trace ID for log correlation, a timestamp, and an optional cause (the original driver error).
Extends
Constructors
Constructor
new AdapterError(
code,
message,
context,
cause?): AdapterError;Defined in: src/errors/base.ts:18
Parameters
| Parameter | Type |
|---|---|
code | ErrorCode |
message | string |
context | ErrorContext |
cause? | unknown |
Returns
Inherited from
Properties
| Property | Modifier | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|---|
cause? | readonly | unknown | The cause of the error. | SqunError.cause | src/errors/base.ts:16 |
code | readonly | ErrorCode | - | SqunError.code | src/errors/base.ts:12 |
context | readonly | ErrorContext | - | SqunError.context | src/errors/base.ts:13 |
message | public | string | - | SqunError.message | node_modules/typescript/lib/lib.es5.d.ts:1077 |
name | public | string | - | SqunError.name | node_modules/typescript/lib/lib.es5.d.ts:1076 |
stack? | public | string | - | SqunError.stack | node_modules/typescript/lib/lib.es5.d.ts:1078 |
timestamp | readonly | Date | - | SqunError.timestamp | src/errors/base.ts:15 |
traceId | readonly | string | - | SqunError.traceId | src/errors/base.ts:14 |
stackTraceLimit | static | number | The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)). The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | SqunError.stackTraceLimit | node_modules/@types/node/globals.d.ts:67 |
Methods
toJSON()
toJSON(): Record<string, unknown>;Defined in: src/errors/base.ts:31
Returns
Record<string, unknown>
Inherited from
captureStackTrace()
Call Signature
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/@types/node/globals.d.ts:51
Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.
The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.
The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:
function a() {
b();
}
function b() {
c();
}
function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;
// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}
a();Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
Call Signature
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/bun-types/globals.d.ts:1042
Create .stack property on a target object
Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
isError()
Call Signature
static isError(error): error is Error;Defined in: node_modules/typescript/lib/lib.esnext.error.d.ts:23
Indicates whether the argument provided is a built-in Error instance or not.
Parameters
| Parameter | Type |
|---|---|
error | unknown |
Returns
error is Error
Inherited from
Call Signature
static isError(value): value is Error;Defined in: node_modules/bun-types/globals.d.ts:1037
Check if a value is an instance of Error
Parameters
| Parameter | Type | Description |
|---|---|---|
value | unknown | The value to check |
Returns
value is Error
True if the value is an instance of Error, false otherwise
Inherited from
prepareStackTrace()
static prepareStackTrace(err, stackTraces): any;Defined in: node_modules/@types/node/globals.d.ts:55
Parameters
| Parameter | Type |
|---|---|
err | Error |
stackTraces | CallSite[] |
Returns
any
See
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Inherited from
AtomicNestingError
Defined in: src/transaction/atomic.ts:9
AtomicNestingError — a TransactionError with code TX_NESTING_FORBIDDEN.
Extends
Constructors
Constructor
new AtomicNestingError(
code,
message,
context,
cause?): AtomicNestingError;Defined in: src/errors/base.ts:18
Parameters
| Parameter | Type |
|---|---|
code | ErrorCode |
message | string |
context | ErrorContext |
cause? | unknown |
Returns
Inherited from
Properties
| Property | Modifier | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|---|
cause? | readonly | unknown | The cause of the error. | TransactionError.cause | src/errors/base.ts:16 |
code | readonly | ErrorCode | - | TransactionError.code | src/errors/base.ts:12 |
context | readonly | ErrorContext | - | TransactionError.context | src/errors/base.ts:13 |
message | public | string | - | TransactionError.message | node_modules/typescript/lib/lib.es5.d.ts:1077 |
name | public | string | - | TransactionError.name | node_modules/typescript/lib/lib.es5.d.ts:1076 |
stack? | public | string | - | TransactionError.stack | node_modules/typescript/lib/lib.es5.d.ts:1078 |
timestamp | readonly | Date | - | TransactionError.timestamp | src/errors/base.ts:15 |
traceId | readonly | string | - | TransactionError.traceId | src/errors/base.ts:14 |
stackTraceLimit | static | number | The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)). The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | TransactionError.stackTraceLimit | node_modules/@types/node/globals.d.ts:67 |
Methods
toJSON()
toJSON(): Record<string, unknown>;Defined in: src/errors/base.ts:31
Returns
Record<string, unknown>
Inherited from
captureStackTrace()
Call Signature
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/@types/node/globals.d.ts:51
Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.
The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.
The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:
function a() {
b();
}
function b() {
c();
}
function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;
// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}
a();Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
TransactionError.captureStackTrace
Call Signature
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/bun-types/globals.d.ts:1042
Create .stack property on a target object
Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
TransactionError.captureStackTrace
isError()
Call Signature
static isError(error): error is Error;Defined in: node_modules/typescript/lib/lib.esnext.error.d.ts:23
Indicates whether the argument provided is a built-in Error instance or not.
Parameters
| Parameter | Type |
|---|---|
error | unknown |
Returns
error is Error
Inherited from
Call Signature
static isError(value): value is Error;Defined in: node_modules/bun-types/globals.d.ts:1037
Check if a value is an instance of Error
Parameters
| Parameter | Type | Description |
|---|---|---|
value | unknown | The value to check |
Returns
value is Error
True if the value is an instance of Error, false otherwise
Inherited from
prepareStackTrace()
static prepareStackTrace(err, stackTraces): any;Defined in: node_modules/@types/node/globals.d.ts:55
Parameters
| Parameter | Type |
|---|---|
err | Error |
stackTraces | CallSite[] |
Returns
any
See
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Inherited from
TransactionError.prepareStackTrace
AuthError
Defined in: src/errors/types.ts:13
Base class for every error thrown by Squn.
Subclasses set a narrower code domain but never override the shape — every SqunError carries a code, structured context, a trace ID for log correlation, a timestamp, and an optional cause (the original driver error).
Extends
Constructors
Constructor
new AuthError(
code,
message,
context,
cause?): AuthError;Defined in: src/errors/base.ts:18
Parameters
| Parameter | Type |
|---|---|
code | ErrorCode |
message | string |
context | ErrorContext |
cause? | unknown |
Returns
Inherited from
Properties
| Property | Modifier | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|---|
cause? | readonly | unknown | The cause of the error. | SqunError.cause | src/errors/base.ts:16 |
code | readonly | ErrorCode | - | SqunError.code | src/errors/base.ts:12 |
context | readonly | ErrorContext | - | SqunError.context | src/errors/base.ts:13 |
message | public | string | - | SqunError.message | node_modules/typescript/lib/lib.es5.d.ts:1077 |
name | public | string | - | SqunError.name | node_modules/typescript/lib/lib.es5.d.ts:1076 |
stack? | public | string | - | SqunError.stack | node_modules/typescript/lib/lib.es5.d.ts:1078 |
timestamp | readonly | Date | - | SqunError.timestamp | src/errors/base.ts:15 |
traceId | readonly | string | - | SqunError.traceId | src/errors/base.ts:14 |
stackTraceLimit | static | number | The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)). The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | SqunError.stackTraceLimit | node_modules/@types/node/globals.d.ts:67 |
Methods
toJSON()
toJSON(): Record<string, unknown>;Defined in: src/errors/base.ts:31
Returns
Record<string, unknown>
Inherited from
captureStackTrace()
Call Signature
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/@types/node/globals.d.ts:51
Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.
The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.
The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:
function a() {
b();
}
function b() {
c();
}
function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;
// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}
a();Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
Call Signature
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/bun-types/globals.d.ts:1042
Create .stack property on a target object
Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
isError()
Call Signature
static isError(error): error is Error;Defined in: node_modules/typescript/lib/lib.esnext.error.d.ts:23
Indicates whether the argument provided is a built-in Error instance or not.
Parameters
| Parameter | Type |
|---|---|
error | unknown |
Returns
error is Error
Inherited from
Call Signature
static isError(value): value is Error;Defined in: node_modules/bun-types/globals.d.ts:1037
Check if a value is an instance of Error
Parameters
| Parameter | Type | Description |
|---|---|---|
value | unknown | The value to check |
Returns
value is Error
True if the value is an instance of Error, false otherwise
Inherited from
prepareStackTrace()
static prepareStackTrace(err, stackTraces): any;Defined in: node_modules/@types/node/globals.d.ts:55
Parameters
| Parameter | Type |
|---|---|
err | Error |
stackTraces | CallSite[] |
Returns
any
See
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Inherited from
ConnectionError
Defined in: src/errors/types.ts:3
Base class for every error thrown by Squn.
Subclasses set a narrower code domain but never override the shape — every SqunError carries a code, structured context, a trace ID for log correlation, a timestamp, and an optional cause (the original driver error).
Extends
Constructors
Constructor
new ConnectionError(
code,
message,
context,
cause?): ConnectionError;Defined in: src/errors/base.ts:18
Parameters
| Parameter | Type |
|---|---|
code | ErrorCode |
message | string |
context | ErrorContext |
cause? | unknown |
Returns
Inherited from
Properties
| Property | Modifier | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|---|
cause? | readonly | unknown | The cause of the error. | SqunError.cause | src/errors/base.ts:16 |
code | readonly | ErrorCode | - | SqunError.code | src/errors/base.ts:12 |
context | readonly | ErrorContext | - | SqunError.context | src/errors/base.ts:13 |
message | public | string | - | SqunError.message | node_modules/typescript/lib/lib.es5.d.ts:1077 |
name | public | string | - | SqunError.name | node_modules/typescript/lib/lib.es5.d.ts:1076 |
stack? | public | string | - | SqunError.stack | node_modules/typescript/lib/lib.es5.d.ts:1078 |
timestamp | readonly | Date | - | SqunError.timestamp | src/errors/base.ts:15 |
traceId | readonly | string | - | SqunError.traceId | src/errors/base.ts:14 |
stackTraceLimit | static | number | The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)). The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | SqunError.stackTraceLimit | node_modules/@types/node/globals.d.ts:67 |
Methods
toJSON()
toJSON(): Record<string, unknown>;Defined in: src/errors/base.ts:31
Returns
Record<string, unknown>
Inherited from
captureStackTrace()
Call Signature
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/@types/node/globals.d.ts:51
Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.
The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.
The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:
function a() {
b();
}
function b() {
c();
}
function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;
// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}
a();Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
Call Signature
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/bun-types/globals.d.ts:1042
Create .stack property on a target object
Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
isError()
Call Signature
static isError(error): error is Error;Defined in: node_modules/typescript/lib/lib.esnext.error.d.ts:23
Indicates whether the argument provided is a built-in Error instance or not.
Parameters
| Parameter | Type |
|---|---|
error | unknown |
Returns
error is Error
Inherited from
Call Signature
static isError(value): value is Error;Defined in: node_modules/bun-types/globals.d.ts:1037
Check if a value is an instance of Error
Parameters
| Parameter | Type | Description |
|---|---|---|
value | unknown | The value to check |
Returns
value is Error
True if the value is an instance of Error, false otherwise
Inherited from
prepareStackTrace()
static prepareStackTrace(err, stackTraces): any;Defined in: node_modules/@types/node/globals.d.ts:55
Parameters
| Parameter | Type |
|---|---|
err | Error |
stackTraces | CallSite[] |
Returns
any
See
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Inherited from
ConnectionGroup
Defined in: src/connections/group.ts:11
Connection group with read/write routing. Reads are load-balanced across replicas. Writes and transactions always go to the write connection.
Type Parameters
| Type Parameter | Default type |
|---|---|
Names extends string | string |
Constructors
Constructor
new ConnectionGroup<Names>(registry, config): ConnectionGroup<Names>;Defined in: src/connections/group.ts:17
Parameters
| Parameter | Type |
|---|---|
registry | ConnectionRegistry<Names> |
config | GroupConfig |
Returns
ConnectionGroup<Names>
Methods
getRead()
getRead(): IDbAdapter;Defined in: src/connections/group.ts:32
Returns a read adapter based on the configured readMode.
Returns
getWrite()
getWrite(): IDbAdapter;Defined in: src/connections/group.ts:27
Returns the write adapter. Transactions always use this.
Returns
ConnectionPool
Defined in: src/pool/pool.ts:33
Connection pool for MSSQL. Bun.SQL (PG/MySQL) manages its own pool internally.
Constructors
Constructor
new ConnectionPool(config?): ConnectionPool;Defined in: src/pool/pool.ts:46
Parameters
| Parameter | Type |
|---|---|
config | PoolConfig |
Returns
Methods
acquire()
acquire(): Promise<PooledConnection>;Defined in: src/pool/pool.ts:70
Acquires a connection from the pool.
Returns
Promise<PooledConnection>
drain()
drain(options?): Promise<void>;Defined in: src/pool/pool.ts:160
Gracefully drains the pool — stops new acquires, waits for in-flight, closes all.
Parameters
| Parameter | Type |
|---|---|
options? | { timeoutMs?: number; } |
options.timeoutMs? | number |
Returns
Promise<void>
poolStats()
poolStats(): PoolStatsSnapshot;Defined in: src/pool/pool.ts:200
Returns a snapshot of current pool metrics.
Returns
release()
release(conn): void;Defined in: src/pool/pool.ts:131
Releases a connection back to the pool.
Parameters
| Parameter | Type |
|---|---|
conn | PooledConnection |
Returns
void
ConnectionRegistry
Defined in: src/connections/registry.ts:8
Holds all named Database instances. get() throws CONN_UNKNOWN if name not found.
Type Parameters
| Type Parameter | Default type |
|---|---|
Names extends string | string |
Constructors
Constructor
new ConnectionRegistry<Names>(connections, defaultName): ConnectionRegistry<Names>;Defined in: src/connections/registry.ts:12
Parameters
| Parameter | Type |
|---|---|
connections | Record<Names, IDbAdapter> |
defaultName | Names |
Returns
ConnectionRegistry<Names>
Accessors
default
Get Signature
get default(): Names;Defined in: src/connections/registry.ts:79
Returns
Names
Methods
get()
get(name?): IDbAdapter;Defined in: src/connections/registry.ts:29
Parameters
| Parameter | Type |
|---|---|
name? | Names |
Returns
has()
has(name): boolean;Defined in: src/connections/registry.ts:50
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
boolean
names()
names(): string[];Defined in: src/connections/registry.ts:46
Returns
string[]
ping()
ping(name): Promise<void>;Defined in: src/connections/registry.ts:54
Parameters
| Parameter | Type |
|---|---|
name | Names |
Returns
Promise<void>
pingAll()
pingAll(): Promise<void>;Defined in: src/connections/registry.ts:59
Returns
Promise<void>
Cursor
Defined in: src/async/cursor.ts:11
AsyncIterableIterator<T> backed by either a native server cursor (when adapter.hasCursorSupport() is true, future work) or a full-fetch-then-slice fallback for all current adapters.
Consumers MUST call close() in a finally block to release resources.
Type Parameters
| Type Parameter |
|---|
T |
Implements
AsyncIterableIterator<T>
Constructors
Constructor
new Cursor<T>(
adapter,
fragment,
_batchSize): Cursor<T>;Defined in: src/async/cursor.ts:21
Parameters
| Parameter | Type |
|---|---|
adapter | IDbAdapter |
fragment | SqlFragment |
_batchSize | number |
Returns
Cursor<T>
Methods
[asyncDispose]()
asyncDispose: Promise<void>;Defined in: src/async/cursor.ts:52
Returns
Promise<void>
[asyncIterator]()
asyncIterator: AsyncIterableIterator<T>;Defined in: src/async/cursor.ts:56
Returns
AsyncIterableIterator<T>
Implementation of
AsyncIterableIterator.[asyncIterator]close()
close(): Promise<void>;Defined in: src/async/cursor.ts:47
Returns
Promise<void>
next()
next(): Promise<IteratorResult<T, any>>;Defined in: src/async/cursor.ts:26
Returns
Promise<IteratorResult<T, any>>
Implementation of
AsyncIterableIterator.nextFailoverGroup
Defined in: src/connections/failover.ts:17
Failover group. When primary is unreachable, promotes first healthy standby.
Important caveats:
- In-flight transactions are lost on failover — they cannot be replayed.
- Replication lag creates a data loss window — reads from the new primary may return stale data until the standby catches up.
- Split-brain is not automatically prevented — if the original primary recovers while a standby has been promoted, both may accept writes. Use external fencing (e.g. pg_rewind, STONITH) to prevent this.
Type Parameters
| Type Parameter | Default type |
|---|---|
Names extends string | string |
Constructors
Constructor
new FailoverGroup<Names>(
registry,
primaryName,
standbyNames): FailoverGroup<Names>;Defined in: src/connections/failover.ts:22
Parameters
| Parameter | Type |
|---|---|
registry | ConnectionRegistry<Names> |
primaryName | Names |
standbyNames | readonly Names[] |
Returns
FailoverGroup<Names>
Accessors
active
Get Signature
get active(): Names;Defined in: src/connections/failover.ts:62
Returns
Names
isOnPrimary
Get Signature
get isOnPrimary(): boolean;Defined in: src/connections/failover.ts:58
Whether the active connection is still the original primary.
Returns
boolean
Methods
failover()
failover(): Promise<Names>;Defined in: src/connections/failover.ts:38
Attempts to promote the first healthy standby. Throws if all unreachable.
Returns
Promise<Names>
getActive()
getActive(): IDbAdapter;Defined in: src/connections/failover.ts:33
Returns the currently active adapter (primary or promoted standby).
Returns
MapperRegistry
Defined in: src/mapping/mapper-registry.ts:9
Class → mapper registry. Instantiate your own for isolated test environments.
Constructors
Constructor
new MapperRegistry(): MapperRegistry;Returns
Methods
clear()
clear(): void;Defined in: src/mapping/mapper-registry.ts:24
Returns
void
get()
get<T>(cls): MapperFn<T> | undefined;Defined in: src/mapping/mapper-registry.ts:16
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
cls | Constructor<T> |
Returns
MapperFn<T> | undefined
has()
has(cls): boolean;Defined in: src/mapping/mapper-registry.ts:20
Parameters
| Parameter | Type |
|---|---|
cls | Constructor<unknown> |
Returns
boolean
register()
register<T>(cls, mapper): void;Defined in: src/mapping/mapper-registry.ts:12
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
cls | Constructor<T> |
mapper | MapperFn<T> |
Returns
void
MappingError
Defined in: src/errors/types.ts:5
Base class for every error thrown by Squn.
Subclasses set a narrower code domain but never override the shape — every SqunError carries a code, structured context, a trace ID for log correlation, a timestamp, and an optional cause (the original driver error).
Extends
Constructors
Constructor
new MappingError(
code,
message,
context,
cause?): MappingError;Defined in: src/errors/base.ts:18
Parameters
| Parameter | Type |
|---|---|
code | ErrorCode |
message | string |
context | ErrorContext |
cause? | unknown |
Returns
Inherited from
Properties
| Property | Modifier | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|---|
cause? | readonly | unknown | The cause of the error. | SqunError.cause | src/errors/base.ts:16 |
code | readonly | ErrorCode | - | SqunError.code | src/errors/base.ts:12 |
context | readonly | ErrorContext | - | SqunError.context | src/errors/base.ts:13 |
message | public | string | - | SqunError.message | node_modules/typescript/lib/lib.es5.d.ts:1077 |
name | public | string | - | SqunError.name | node_modules/typescript/lib/lib.es5.d.ts:1076 |
stack? | public | string | - | SqunError.stack | node_modules/typescript/lib/lib.es5.d.ts:1078 |
timestamp | readonly | Date | - | SqunError.timestamp | src/errors/base.ts:15 |
traceId | readonly | string | - | SqunError.traceId | src/errors/base.ts:14 |
stackTraceLimit | static | number | The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)). The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | SqunError.stackTraceLimit | node_modules/@types/node/globals.d.ts:67 |
Methods
toJSON()
toJSON(): Record<string, unknown>;Defined in: src/errors/base.ts:31
Returns
Record<string, unknown>
Inherited from
captureStackTrace()
Call Signature
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/@types/node/globals.d.ts:51
Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.
The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.
The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:
function a() {
b();
}
function b() {
c();
}
function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;
// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}
a();Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
Call Signature
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/bun-types/globals.d.ts:1042
Create .stack property on a target object
Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
isError()
Call Signature
static isError(error): error is Error;Defined in: node_modules/typescript/lib/lib.esnext.error.d.ts:23
Indicates whether the argument provided is a built-in Error instance or not.
Parameters
| Parameter | Type |
|---|---|
error | unknown |
Returns
error is Error
Inherited from
Call Signature
static isError(value): value is Error;Defined in: node_modules/bun-types/globals.d.ts:1037
Check if a value is an instance of Error
Parameters
| Parameter | Type | Description |
|---|---|---|
value | unknown | The value to check |
Returns
value is Error
True if the value is an instance of Error, false otherwise
Inherited from
prepareStackTrace()
static prepareStackTrace(err, stackTraces): any;Defined in: node_modules/@types/node/globals.d.ts:55
Parameters
| Parameter | Type |
|---|---|
err | Error |
stackTraces | CallSite[] |
Returns
any
See
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Inherited from
MssqlAdapter
Defined in: src/adapters/mssql.ts:73
Database adapter contract — all database-specific behaviour lives here.
Implements
Constructors
Constructor
new MssqlAdapter(options): MssqlAdapter;Defined in: src/adapters/mssql.ts:78
Parameters
| Parameter | Type |
|---|---|
options | MssqlAdapterOptions |
Returns
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
type | readonly | "mssql" | src/adapters/mssql.ts:74 |
Methods
beginTransaction()
beginTransaction(): Promise<IDbTransaction>;Defined in: src/adapters/mssql.ts:154
Returns
Promise<IDbTransaction>
Implementation of
close()
close(): Promise<void>;Defined in: src/adapters/mssql.ts:312
Returns
Promise<void>
Implementation of
execute()
execute(sql, params): Promise<{
rowsAffected: number;
}>;Defined in: src/adapters/mssql.ts:102
Parameters
| Parameter | Type |
|---|---|
sql | string |
params | unknown[] |
Returns
Promise<{ rowsAffected: number; }>
Implementation of
executeBatch()
executeBatch(
sql,
rows,
paramNames,
strategy?): Promise<{
rowsAffected: number;
}>;Defined in: src/adapters/mssql.ts:257
Executes the same prepared statement once per row using native batch/pipeline. paramNames maps column names to positional params in sql.
Parameters
| Parameter | Type |
|---|---|
sql | string |
rows | readonly Record<string, unknown>[] |
paramNames | readonly string[] |
strategy? | "prepared-loop" | "copy" | "bulk-load" |
Returns
Promise<{ rowsAffected: number; }>
Implementation of
hasCursorSupport()
hasCursorSupport(): boolean;Defined in: src/adapters/mssql.ts:294
Returns true if the adapter supports server-side cursors for streaming.
Returns
boolean
Implementation of
materializeTvp()
materializeTvp(_tvp, _index): Promise<TvpMaterialised>;Defined in: src/adapters/mssql.ts:328
Parameters
| Parameter | Type |
|---|---|
_tvp | TvpValue |
_index | number |
Returns
Promise<TvpMaterialised>
Implementation of
ping()
ping(): Promise<void>;Defined in: src/adapters/mssql.ts:298
Returns
Promise<void>
Implementation of
query()
query(sql, params): Promise<Row[]>;Defined in: src/adapters/mssql.ts:120
Parameters
| Parameter | Type |
|---|---|
sql | string |
params | unknown[] |
Returns
Promise<Row[]>
Implementation of
queryMultiple()
queryMultiple(sql, params): Promise<Row[][]>;Defined in: src/adapters/mssql.ts:137
Parameters
| Parameter | Type |
|---|---|
sql | string |
params | unknown[] |
Returns
Promise<Row[][]>
Implementation of
MysqlAdapter
Defined in: src/adapters/mysql.ts:16
Database adapter contract — all database-specific behaviour lives here.
Implements
Constructors
Constructor
new MysqlAdapter(options?): MysqlAdapter;Defined in: src/adapters/mysql.ts:21
Parameters
| Parameter | Type |
|---|---|
options | MysqlAdapterOptions |
Returns
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
type | readonly | "mysql" | src/adapters/mysql.ts:17 |
Methods
beginTransaction()
beginTransaction(): Promise<IDbTransaction>;Defined in: src/adapters/mysql.ts:93
Opens a dedicated single-connection SQL instance for the transaction. We cannot use sql.reserve() here: Bun.SQL MySQL leaves the pool connection in a mid-read state after any DML, causing the next query on the same pool to hang. A private SQL(max:1) instance is isolated and closed on commit/rollback.
Returns
Promise<IDbTransaction>
Implementation of
close()
close(): Promise<void>;Defined in: src/adapters/mysql.ts:254
Returns
Promise<void>
Implementation of
execute()
execute(sql, params): Promise<{
rowsAffected: number;
}>;Defined in: src/adapters/mysql.ts:42
Parameters
| Parameter | Type |
|---|---|
sql | string |
params | unknown[] |
Returns
Promise<{ rowsAffected: number; }>
Implementation of
executeBatch()
executeBatch(
sql,
rows,
paramNames,
_strategy?): Promise<{
rowsAffected: number;
}>;Defined in: src/adapters/mysql.ts:213
Executes the same prepared statement once per row using native batch/pipeline. paramNames maps column names to positional params in sql.
Parameters
| Parameter | Type |
|---|---|
sql | string |
rows | readonly Record<string, unknown>[] |
paramNames | readonly string[] |
_strategy? | "prepared-loop" | "copy" | "bulk-load" |
Returns
Promise<{ rowsAffected: number; }>
Implementation of
hasCursorSupport()
hasCursorSupport(): boolean;Defined in: src/adapters/mysql.ts:237
Returns true if the adapter supports server-side cursors for streaming.
Returns
boolean
Implementation of
materializeTvp()
materializeTvp(_tvp, _index): Promise<TvpMaterialised>;Defined in: src/adapters/mysql.ts:267
Parameters
| Parameter | Type |
|---|---|
_tvp | TvpValue |
_index | number |
Returns
Promise<TvpMaterialised>
Implementation of
ping()
ping(): Promise<void>;Defined in: src/adapters/mysql.ts:241
Returns
Promise<void>
Implementation of
query()
query(sql, params): Promise<Row[]>;Defined in: src/adapters/mysql.ts:59
Parameters
| Parameter | Type |
|---|---|
sql | string |
params | unknown[] |
Returns
Promise<Row[]>
Implementation of
queryMultiple()
queryMultiple(sql, params): Promise<Row[][]>;Defined in: src/adapters/mysql.ts:73
Parameters
| Parameter | Type |
|---|---|
sql | string |
params | unknown[] |
Returns
Promise<Row[][]>
Implementation of
ParamBuffer
Defined in: src/cache/param-buffer.ts:8
Pre-allocated reusable array for param binding. Fills values in-place — no new Array() per query call. Grows automatically when the param count exceeds current capacity.
Constructors
Constructor
new ParamBuffer(initialCapacity?): ParamBuffer;Defined in: src/cache/param-buffer.ts:12
Parameters
| Parameter | Type | Default value |
|---|---|---|
initialCapacity | number | DEFAULT_CAPACITY |
Returns
Accessors
capacity
Get Signature
get capacity(): number;Defined in: src/cache/param-buffer.ts:48
Current allocated capacity.
Returns
number
length
Get Signature
get length(): number;Defined in: src/cache/param-buffer.ts:43
Current number of values in the buffer.
Returns
number
Methods
push()
push(value): number;Defined in: src/cache/param-buffer.ts:27
Appends a value and returns its index. Grows the buffer if needed.
Parameters
| Parameter | Type |
|---|---|
value | unknown |
Returns
number
reset()
reset(): void;Defined in: src/cache/param-buffer.ts:18
Resets the buffer for a new query without re-allocating.
Returns
void
toArray()
toArray(): readonly unknown[];Defined in: src/cache/param-buffer.ts:38
Returns a view of the filled portion. The returned array is reused — do not hold a reference.
Returns
readonly unknown[]
PooledConnection
Defined in: src/pool/connection.ts:7
Wraps a single database connection with lifecycle state tracking. State machine: CREATED → IDLE → ACQUIRED → IDLE → … → DEAD
Constructors
Constructor
new PooledConnection(id): PooledConnection;Defined in: src/pool/connection.ts:16
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
id | readonly | string | src/pool/connection.ts:14 |
Accessors
acquiredAt
Get Signature
get acquiredAt(): number | null;Defined in: src/pool/connection.ts:38
Returns
number | null
ageMs
Get Signature
get ageMs(): number;Defined in: src/pool/connection.ts:73
Age in milliseconds since creation.
Returns
number
createdAt
Get Signature
get createdAt(): number;Defined in: src/pool/connection.ts:30
Returns
number
idleMs
Get Signature
get idleMs(): number;Defined in: src/pool/connection.ts:78
Time in milliseconds since last acquired (or since creation if never acquired).
Returns
number
lastUsedAt
Get Signature
get lastUsedAt(): number;Defined in: src/pool/connection.ts:34
Returns
number
state
Get Signature
get state(): ConnectionState;Defined in: src/pool/connection.ts:22
Returns
ConnectionState
useCount
Get Signature
get useCount(): number;Defined in: src/pool/connection.ts:26
Returns
number
Methods
markAcquired()
markAcquired(): void;Defined in: src/pool/connection.ts:49
Transition to ACQUIRED — valid from IDLE.
Returns
void
markDead()
markDead(): void;Defined in: src/pool/connection.ts:57
Transition to DEAD — valid from any state.
Returns
void
markIdle()
markIdle(): void;Defined in: src/pool/connection.ts:43
Transition to IDLE — valid from CREATED or ACQUIRED.
Returns
void
shouldRecycle()
shouldRecycle(maxAgeMs, maxUseCount): boolean;Defined in: src/pool/connection.ts:62
Whether this connection should be recycled based on age or use count.
Parameters
| Parameter | Type |
|---|---|
maxAgeMs | number | undefined |
maxUseCount | number | undefined |
Returns
boolean
PoolStats
Defined in: src/pool/stats.ts:21
Tracks rolling averages for pool performance metrics. Uses exponential moving average for constant memory usage.
Constructors
Constructor
new PoolStats(alpha?): PoolStats;Defined in: src/pool/stats.ts:30
Parameters
| Parameter | Type | Default value |
|---|---|---|
alpha | number | 0.1 |
Returns
Methods
recordAcquire()
recordAcquire(durationMs): void;Defined in: src/pool/stats.ts:34
Parameters
| Parameter | Type |
|---|---|
durationMs | number |
Returns
void
recordCreated()
recordCreated(): void;Defined in: src/pool/stats.ts:47
Returns
void
recordDestroyed()
recordDestroyed(): void;Defined in: src/pool/stats.ts:51
Returns
void
recordIdle()
recordIdle(durationMs): void;Defined in: src/pool/stats.ts:39
Parameters
| Parameter | Type |
|---|---|
durationMs | number |
Returns
void
recordUse()
recordUse(durationMs): void;Defined in: src/pool/stats.ts:43
Parameters
| Parameter | Type |
|---|---|
durationMs | number |
Returns
void
snapshot()
snapshot(
idle,
acquired,
waiting,
min,
max): PoolStatsSnapshot;Defined in: src/pool/stats.ts:55
Parameters
| Parameter | Type |
|---|---|
idle | number |
acquired | number |
waiting | number |
min | number |
max | number |
Returns
PostgresAdapter
Defined in: src/adapters/postgres.ts:18
Database adapter contract — all database-specific behaviour lives here.
Implements
Constructors
Constructor
new PostgresAdapter(options?): PostgresAdapter;Defined in: src/adapters/postgres.ts:23
Parameters
| Parameter | Type |
|---|---|
options | PostgresAdapterOptions |
Returns
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
tvpCopyThreshold | readonly | number | src/adapters/postgres.ts:21 |
type | readonly | "postgres" | src/adapters/postgres.ts:19 |
Methods
beginTransaction()
beginTransaction(): Promise<IDbTransaction>;Defined in: src/adapters/postgres.ts:93
Uses Bun.SQL's sql.reserve() to pin a single connection from the pool. Raw BEGIN/COMMIT via unsafe() is rejected by Bun when pool max > 1 because queries could land on different connections.
The reserved connection is released when commit() or rollback() is called.
Returns
Promise<IDbTransaction>
Implementation of
close()
close(): Promise<void>;Defined in: src/adapters/postgres.ts:254
Returns
Promise<void>
Implementation of
execute()
execute(sql, params): Promise<{
rowsAffected: number;
}>;Defined in: src/adapters/postgres.ts:44
Parameters
| Parameter | Type |
|---|---|
sql | string |
params | unknown[] |
Returns
Promise<{ rowsAffected: number; }>
Implementation of
executeBatch()
executeBatch(
sql,
rows,
paramNames,
_strategy?): Promise<{
rowsAffected: number;
}>;Defined in: src/adapters/postgres.ts:213
Executes the same prepared statement once per row using native batch/pipeline. paramNames maps column names to positional params in sql.
Parameters
| Parameter | Type |
|---|---|
sql | string |
rows | readonly Record<string, unknown>[] |
paramNames | readonly string[] |
_strategy? | "prepared-loop" | "copy" | "bulk-load" |
Returns
Promise<{ rowsAffected: number; }>
Implementation of
hasCursorSupport()
hasCursorSupport(): boolean;Defined in: src/adapters/postgres.ts:237
Returns true if the adapter supports server-side cursors for streaming.
Returns
boolean
Implementation of
materializeTvp()
materializeTvp(_tvp, _index): Promise<TvpMaterialised>;Defined in: src/adapters/postgres.ts:267
Parameters
| Parameter | Type |
|---|---|
_tvp | TvpValue |
_index | number |
Returns
Promise<TvpMaterialised>
Implementation of
ping()
ping(): Promise<void>;Defined in: src/adapters/postgres.ts:241
Returns
Promise<void>
Implementation of
query()
query(sql, params): Promise<Row[]>;Defined in: src/adapters/postgres.ts:58
Parameters
| Parameter | Type |
|---|---|
sql | string |
params | unknown[] |
Returns
Promise<Row[]>
Implementation of
queryMultiple()
queryMultiple(sql, params): Promise<Row[][]>;Defined in: src/adapters/postgres.ts:72
Parameters
| Parameter | Type |
|---|---|
sql | string |
params | unknown[] |
Returns
Promise<Row[][]>
Implementation of
PreparedQuery
Defined in: src/api/prepared.ts:34
A prepared query. The SQL is parsed, validated, and normalised once. Each invocation only fills the ParamBuffer and calls the adapter.
For queries (SELECT): returns T[]. For single-row: use .first() or .single(). For writes: use .execute().
Type Parameters
| Type Parameter | Default type |
|---|---|
T | - |
P extends Record<string, unknown> | Record<string, never> |
Constructors
Constructor
new PreparedQuery<T, P>(
adapter,
fragment,
paramNames): PreparedQuery<T, P>;Defined in: src/api/prepared.ts:38
Parameters
| Parameter | Type |
|---|---|
adapter | IDbAdapter |
fragment | SqlFragment |
paramNames | readonly string[] |
Returns
PreparedQuery<T, P>
Accessors
paramNames
Get Signature
get paramNames(): readonly string[];Defined in: src/api/prepared.ts:134
The ordered param names.
Returns
readonly string[]
rawSql
Get Signature
get rawSql(): string;Defined in: src/api/prepared.ts:129
The raw SQL text sent to the adapter.
Returns
string
sql
Get Signature
get sql(): string;Defined in: src/api/prepared.ts:124
The normalised SQL text — useful for logging and debugging.
Returns
string
Methods
all()
all(params): Promise<T[]>;Defined in: src/api/prepared.ts:62
Execute as a query — returns T[].
Parameters
| Parameter | Type |
|---|---|
params | P |
Returns
Promise<T[]>
execute()
execute(params): Promise<{
rowsAffected: number;
}>;Defined in: src/api/prepared.ts:118
Execute as a write — returns { rowsAffected }.
Parameters
| Parameter | Type |
|---|---|
params | P |
Returns
Promise<{ rowsAffected: number; }>
first()
first(params): Promise<T | null>;Defined in: src/api/prepared.ts:69
Execute and return T | null — first row or null.
Parameters
| Parameter | Type |
|---|---|
params | P |
Returns
Promise<T | null>
scalar()
scalar(params): Promise<T>;Defined in: src/api/prepared.ts:97
Execute and return the first column of the first row.
Parameters
| Parameter | Type |
|---|---|
params | P |
Returns
Promise<T>
single()
single(params): Promise<T>;Defined in: src/api/prepared.ts:77
Execute and return exactly one T — throws on 0 or >1 rows.
Parameters
| Parameter | Type |
|---|---|
params | P |
Returns
Promise<T>
QueryBuilder
Defined in: src/api/query-builder.ts:14
Lazy, immutable, composable query builder. Nothing executes until db.run(q) is called. Each method returns a new builder — never mutates.
Type Parameters
| Type Parameter | Default type |
|---|---|
Names extends string | never |
Constructors
Constructor
new QueryBuilder<Names>(
tableName,
selectCols?,
whereClauses?,
orderClauses?,
limit?,
offset?,
connectionName?,
isReadonly?): QueryBuilder<Names>;Defined in: src/api/query-builder.ts:24
Parameters
| Parameter | Type | Default value |
|---|---|---|
tableName | string | undefined |
selectCols | readonly string[] | [] |
whereClauses | readonly SqlFragment[] | [] |
orderClauses | readonly string[] | [] |
limit | number | null | null |
offset | number | null | null |
connectionName | Names | null | null |
isReadonly | boolean | false |
Returns
QueryBuilder<Names>
Accessors
connectionName
Get Signature
get connectionName(): Names | null;Defined in: src/api/query-builder.ts:166
Returns
Names | null
isReadonly
Get Signature
get isReadonly(): boolean;Defined in: src/api/query-builder.ts:170
Returns
boolean
tableName
Get Signature
get tableName(): string;Defined in: src/api/query-builder.ts:174
Returns
string
Methods
build()
build(): SqlFragment;Defined in: src/api/query-builder.ts:129
Builds the SqlFragment for execution.
Returns
connection()
connection<N>(name): QueryBuilder<N>;Defined in: src/api/query-builder.ts:102
Type Parameters
| Type Parameter |
|---|
N extends string |
Parameters
| Parameter | Type |
|---|---|
name | N |
Returns
QueryBuilder<N>
orderBy()
orderBy(column, direction?): QueryBuilder<Names>;Defined in: src/api/query-builder.ts:75
Parameters
| Parameter | Type | Default value |
|---|---|---|
column | string | undefined |
direction | "ASC" | "DESC" | "ASC" |
Returns
QueryBuilder<Names>
paginate()
paginate(options): QueryBuilder<Names>;Defined in: src/api/query-builder.ts:88
Parameters
| Parameter | Type |
|---|---|
options | PaginateOptions |
Returns
QueryBuilder<Names>
readonly()
readonly(): QueryBuilder<Names>;Defined in: src/api/query-builder.ts:115
Returns
QueryBuilder<Names>
select()
select(...cols): QueryBuilder<Names>;Defined in: src/api/query-builder.ts:44
Parameters
| Parameter | Type |
|---|---|
...cols | string[] |
Returns
QueryBuilder<Names>
where()
where(clause): QueryBuilder<Names>;Defined in: src/api/query-builder.ts:57
Parameters
| Parameter | Type |
|---|---|
clause | SqlFragment |
Returns
QueryBuilder<Names>
whereIf()
whereIf(condition, clause): QueryBuilder<Names>;Defined in: src/api/query-builder.ts:70
Parameters
| Parameter | Type |
|---|---|
condition | boolean |
clause | SqlFragment |
Returns
QueryBuilder<Names>
QueryCache
Defined in: src/cache/query-cache.ts:20
LRU query cache keyed on Bun.hash() of normalised SQL text. Entries are held via WeakRef so the GC can reclaim them under memory pressure. Supports TTL, max-age, LRU eviction, and a background reaper.
Constructors
Constructor
new QueryCache(config?): QueryCache;Defined in: src/cache/query-cache.ts:27
Parameters
| Parameter | Type |
|---|---|
config | CacheConfig |
Returns
Accessors
size
Get Signature
get size(): number;Defined in: src/cache/query-cache.ts:107
Current number of entries (including potentially GC'd WeakRefs).
Returns
number
Methods
clear()
clear(): void;Defined in: src/cache/query-cache.ts:112
Removes all entries and stops the background reaper.
Returns
void
get()
get(sql): CompiledQuery | undefined;Defined in: src/cache/query-cache.ts:43
Returns the cached CompiledQuery or undefined on miss / expiry / GC reclaim.
Parameters
| Parameter | Type |
|---|---|
sql | string |
Returns
CompiledQuery | undefined
set()
set(sql, compiled): void;Defined in: src/cache/query-cache.ts:80
Stores a CompiledQuery. Evicts the LRU entry if the cache is full.
Parameters
| Parameter | Type |
|---|---|
sql | string |
compiled | CompiledQuery |
Returns
void
QueryError
Defined in: src/errors/types.ts:4
Base class for every error thrown by Squn.
Subclasses set a narrower code domain but never override the shape — every SqunError carries a code, structured context, a trace ID for log correlation, a timestamp, and an optional cause (the original driver error).
Extends
Constructors
Constructor
new QueryError(
code,
message,
context,
cause?): QueryError;Defined in: src/errors/base.ts:18
Parameters
| Parameter | Type |
|---|---|
code | ErrorCode |
message | string |
context | ErrorContext |
cause? | unknown |
Returns
Inherited from
Properties
| Property | Modifier | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|---|
cause? | readonly | unknown | The cause of the error. | SqunError.cause | src/errors/base.ts:16 |
code | readonly | ErrorCode | - | SqunError.code | src/errors/base.ts:12 |
context | readonly | ErrorContext | - | SqunError.context | src/errors/base.ts:13 |
message | public | string | - | SqunError.message | node_modules/typescript/lib/lib.es5.d.ts:1077 |
name | public | string | - | SqunError.name | node_modules/typescript/lib/lib.es5.d.ts:1076 |
stack? | public | string | - | SqunError.stack | node_modules/typescript/lib/lib.es5.d.ts:1078 |
timestamp | readonly | Date | - | SqunError.timestamp | src/errors/base.ts:15 |
traceId | readonly | string | - | SqunError.traceId | src/errors/base.ts:14 |
stackTraceLimit | static | number | The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)). The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | SqunError.stackTraceLimit | node_modules/@types/node/globals.d.ts:67 |
Methods
toJSON()
toJSON(): Record<string, unknown>;Defined in: src/errors/base.ts:31
Returns
Record<string, unknown>
Inherited from
captureStackTrace()
Call Signature
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/@types/node/globals.d.ts:51
Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.
The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.
The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:
function a() {
b();
}
function b() {
c();
}
function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;
// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}
a();Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
Call Signature
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/bun-types/globals.d.ts:1042
Create .stack property on a target object
Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
isError()
Call Signature
static isError(error): error is Error;Defined in: node_modules/typescript/lib/lib.esnext.error.d.ts:23
Indicates whether the argument provided is a built-in Error instance or not.
Parameters
| Parameter | Type |
|---|---|
error | unknown |
Returns
error is Error
Inherited from
Call Signature
static isError(value): value is Error;Defined in: node_modules/bun-types/globals.d.ts:1037
Check if a value is an instance of Error
Parameters
| Parameter | Type | Description |
|---|---|---|
value | unknown | The value to check |
Returns
value is Error
True if the value is an instance of Error, false otherwise
Inherited from
prepareStackTrace()
static prepareStackTrace(err, stackTraces): any;Defined in: node_modules/@types/node/globals.d.ts:55
Parameters
| Parameter | Type |
|---|---|
err | Error |
stackTraces | CallSite[] |
Returns
any
See
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Inherited from
ReadonlyViolationError
Defined in: src/errors/types.ts:10
Base class for every error thrown by Squn.
Subclasses set a narrower code domain but never override the shape — every SqunError carries a code, structured context, a trace ID for log correlation, a timestamp, and an optional cause (the original driver error).
Extends
Constructors
Constructor
new ReadonlyViolationError(
code,
message,
context,
cause?): ReadonlyViolationError;Defined in: src/errors/base.ts:18
Parameters
| Parameter | Type |
|---|---|
code | ErrorCode |
message | string |
context | ErrorContext |
cause? | unknown |
Returns
Inherited from
Properties
| Property | Modifier | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|---|
cause? | readonly | unknown | The cause of the error. | SqunError.cause | src/errors/base.ts:16 |
code | readonly | ErrorCode | - | SqunError.code | src/errors/base.ts:12 |
context | readonly | ErrorContext | - | SqunError.context | src/errors/base.ts:13 |
message | public | string | - | SqunError.message | node_modules/typescript/lib/lib.es5.d.ts:1077 |
name | public | string | - | SqunError.name | node_modules/typescript/lib/lib.es5.d.ts:1076 |
stack? | public | string | - | SqunError.stack | node_modules/typescript/lib/lib.es5.d.ts:1078 |
timestamp | readonly | Date | - | SqunError.timestamp | src/errors/base.ts:15 |
traceId | readonly | string | - | SqunError.traceId | src/errors/base.ts:14 |
stackTraceLimit | static | number | The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)). The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | SqunError.stackTraceLimit | node_modules/@types/node/globals.d.ts:67 |
Methods
toJSON()
toJSON(): Record<string, unknown>;Defined in: src/errors/base.ts:31
Returns
Record<string, unknown>
Inherited from
captureStackTrace()
Call Signature
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/@types/node/globals.d.ts:51
Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.
The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.
The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:
function a() {
b();
}
function b() {
c();
}
function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;
// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}
a();Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
Call Signature
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/bun-types/globals.d.ts:1042
Create .stack property on a target object
Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
isError()
Call Signature
static isError(error): error is Error;Defined in: node_modules/typescript/lib/lib.esnext.error.d.ts:23
Indicates whether the argument provided is a built-in Error instance or not.
Parameters
| Parameter | Type |
|---|---|
error | unknown |
Returns
error is Error
Inherited from
Call Signature
static isError(value): value is Error;Defined in: node_modules/bun-types/globals.d.ts:1037
Check if a value is an instance of Error
Parameters
| Parameter | Type | Description |
|---|---|---|
value | unknown | The value to check |
Returns
value is Error
True if the value is an instance of Error, false otherwise
Inherited from
prepareStackTrace()
static prepareStackTrace(err, stackTraces): any;Defined in: node_modules/@types/node/globals.d.ts:55
Parameters
| Parameter | Type |
|---|---|
err | Error |
stackTraces | CallSite[] |
Returns
any
See
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Inherited from
Savepoint
Defined in: src/transaction/savepoint.ts:8
Savepoint within a transaction. Names use format: squn_sp_{txId}_{depth}.
Constructors
Constructor
new Savepoint(
tx,
txId,
depth): Savepoint;Defined in: src/transaction/savepoint.ts:11
Parameters
| Parameter | Type |
|---|---|
tx | IDbTransaction |
txId | string |
depth | number |
Returns
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
name | readonly | string | src/transaction/savepoint.ts:9 |
Methods
create()
create(): Promise<void>;Defined in: src/transaction/savepoint.ts:21
Creates the savepoint on the database.
Returns
Promise<void>
release()
release(): Promise<void>;Defined in: src/transaction/savepoint.ts:49
Releases this savepoint.
Returns
Promise<void>
rollback()
rollback(): Promise<void>;Defined in: src/transaction/savepoint.ts:35
Rolls back to this savepoint.
Returns
Promise<void>
SecurityError
Defined in: src/errors/types.ts:11
Base class for every error thrown by Squn.
Subclasses set a narrower code domain but never override the shape — every SqunError carries a code, structured context, a trace ID for log correlation, a timestamp, and an optional cause (the original driver error).
Extends
Constructors
Constructor
new SecurityError(
code,
message,
context,
cause?): SecurityError;Defined in: src/errors/base.ts:18
Parameters
| Parameter | Type |
|---|---|
code | ErrorCode |
message | string |
context | ErrorContext |
cause? | unknown |
Returns
Inherited from
Properties
| Property | Modifier | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|---|
cause? | readonly | unknown | The cause of the error. | SqunError.cause | src/errors/base.ts:16 |
code | readonly | ErrorCode | - | SqunError.code | src/errors/base.ts:12 |
context | readonly | ErrorContext | - | SqunError.context | src/errors/base.ts:13 |
message | public | string | - | SqunError.message | node_modules/typescript/lib/lib.es5.d.ts:1077 |
name | public | string | - | SqunError.name | node_modules/typescript/lib/lib.es5.d.ts:1076 |
stack? | public | string | - | SqunError.stack | node_modules/typescript/lib/lib.es5.d.ts:1078 |
timestamp | readonly | Date | - | SqunError.timestamp | src/errors/base.ts:15 |
traceId | readonly | string | - | SqunError.traceId | src/errors/base.ts:14 |
stackTraceLimit | static | number | The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)). The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | SqunError.stackTraceLimit | node_modules/@types/node/globals.d.ts:67 |
Methods
toJSON()
toJSON(): Record<string, unknown>;Defined in: src/errors/base.ts:31
Returns
Record<string, unknown>
Inherited from
captureStackTrace()
Call Signature
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/@types/node/globals.d.ts:51
Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.
The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.
The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:
function a() {
b();
}
function b() {
c();
}
function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;
// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}
a();Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
Call Signature
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/bun-types/globals.d.ts:1042
Create .stack property on a target object
Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
isError()
Call Signature
static isError(error): error is Error;Defined in: node_modules/typescript/lib/lib.esnext.error.d.ts:23
Indicates whether the argument provided is a built-in Error instance or not.
Parameters
| Parameter | Type |
|---|---|
error | unknown |
Returns
error is Error
Inherited from
Call Signature
static isError(value): value is Error;Defined in: node_modules/bun-types/globals.d.ts:1037
Check if a value is an instance of Error
Parameters
| Parameter | Type | Description |
|---|---|---|
value | unknown | The value to check |
Returns
value is Error
True if the value is an instance of Error, false otherwise
Inherited from
prepareStackTrace()
static prepareStackTrace(err, stackTraces): any;Defined in: node_modules/@types/node/globals.d.ts:55
Parameters
| Parameter | Type |
|---|---|
err | Error |
stackTraces | CallSite[] |
Returns
any
See
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Inherited from
SqliteAdapter
Defined in: src/adapters/sqlite.ts:12
Database adapter contract — all database-specific behaviour lives here.
Implements
Constructors
Constructor
new SqliteAdapter(options?): SqliteAdapter;Defined in: src/adapters/sqlite.ts:16
Parameters
| Parameter | Type |
|---|---|
options | SqliteAdapterOptions |
Returns
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
type | readonly | "sqlite" | src/adapters/sqlite.ts:13 |
Methods
beginTransaction()
beginTransaction(): Promise<IDbTransaction>;Defined in: src/adapters/sqlite.ts:86
Returns
Promise<IDbTransaction>
Implementation of
close()
close(): Promise<void>;Defined in: src/adapters/sqlite.ts:262
Returns
Promise<void>
Implementation of
execute()
execute(sql, params): Promise<{
rowsAffected: number;
}>;Defined in: src/adapters/sqlite.ts:31
Parameters
| Parameter | Type |
|---|---|
sql | string |
params | unknown[] |
Returns
Promise<{ rowsAffected: number; }>
Implementation of
executeBatch()
executeBatch(
sql,
rows,
paramNames,
_strategy?): Promise<{
rowsAffected: number;
}>;Defined in: src/adapters/sqlite.ts:215
Executes the same prepared statement once per row using native batch/pipeline. paramNames maps column names to positional params in sql.
Parameters
| Parameter | Type |
|---|---|
sql | string |
rows | readonly Record<string, unknown>[] |
paramNames | readonly string[] |
_strategy? | "prepared-loop" | "copy" | "bulk-load" |
Returns
Promise<{ rowsAffected: number; }>
Implementation of
hasCursorSupport()
hasCursorSupport(): boolean;Defined in: src/adapters/sqlite.ts:242
Returns true if the adapter supports server-side cursors for streaming.
Returns
boolean
Implementation of
materializeTvp()
materializeTvp(tvp, _index): Promise<TvpMaterialised>;Defined in: src/adapters/sqlite.ts:278
Parameters
| Parameter | Type |
|---|---|
tvp | TvpValue |
_index | number |
Returns
Promise<TvpMaterialised>
Implementation of
ping()
ping(): Promise<void>;Defined in: src/adapters/sqlite.ts:246
Returns
Promise<void>
Implementation of
query()
query(sql, params): Promise<Row[]>;Defined in: src/adapters/sqlite.ts:50
Parameters
| Parameter | Type |
|---|---|
sql | string |
params | unknown[] |
Returns
Promise<Row[]>
Implementation of
queryMultiple()
queryMultiple(sql, params): Promise<Row[][]>;Defined in: src/adapters/sqlite.ts:66
Parameters
| Parameter | Type |
|---|---|
sql | string |
params | unknown[] |
Returns
Promise<Row[][]>
Implementation of
SqunConfigError
Defined in: src/errors/types.ts:12
Base class for every error thrown by Squn.
Subclasses set a narrower code domain but never override the shape — every SqunError carries a code, structured context, a trace ID for log correlation, a timestamp, and an optional cause (the original driver error).
Extends
Constructors
Constructor
new SqunConfigError(
code,
message,
context,
cause?): SqunConfigError;Defined in: src/errors/base.ts:18
Parameters
| Parameter | Type |
|---|---|
code | ErrorCode |
message | string |
context | ErrorContext |
cause? | unknown |
Returns
Inherited from
Properties
| Property | Modifier | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|---|
cause? | readonly | unknown | The cause of the error. | SqunError.cause | src/errors/base.ts:16 |
code | readonly | ErrorCode | - | SqunError.code | src/errors/base.ts:12 |
context | readonly | ErrorContext | - | SqunError.context | src/errors/base.ts:13 |
message | public | string | - | SqunError.message | node_modules/typescript/lib/lib.es5.d.ts:1077 |
name | public | string | - | SqunError.name | node_modules/typescript/lib/lib.es5.d.ts:1076 |
stack? | public | string | - | SqunError.stack | node_modules/typescript/lib/lib.es5.d.ts:1078 |
timestamp | readonly | Date | - | SqunError.timestamp | src/errors/base.ts:15 |
traceId | readonly | string | - | SqunError.traceId | src/errors/base.ts:14 |
stackTraceLimit | static | number | The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)). The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | SqunError.stackTraceLimit | node_modules/@types/node/globals.d.ts:67 |
Methods
toJSON()
toJSON(): Record<string, unknown>;Defined in: src/errors/base.ts:31
Returns
Record<string, unknown>
Inherited from
captureStackTrace()
Call Signature
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/@types/node/globals.d.ts:51
Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.
The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.
The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:
function a() {
b();
}
function b() {
c();
}
function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;
// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}
a();Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
Call Signature
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/bun-types/globals.d.ts:1042
Create .stack property on a target object
Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
isError()
Call Signature
static isError(error): error is Error;Defined in: node_modules/typescript/lib/lib.esnext.error.d.ts:23
Indicates whether the argument provided is a built-in Error instance or not.
Parameters
| Parameter | Type |
|---|---|
error | unknown |
Returns
error is Error
Inherited from
Call Signature
static isError(value): value is Error;Defined in: node_modules/bun-types/globals.d.ts:1037
Check if a value is an instance of Error
Parameters
| Parameter | Type | Description |
|---|---|---|
value | unknown | The value to check |
Returns
value is Error
True if the value is an instance of Error, false otherwise
Inherited from
prepareStackTrace()
static prepareStackTrace(err, stackTraces): any;Defined in: node_modules/@types/node/globals.d.ts:55
Parameters
| Parameter | Type |
|---|---|
err | Error |
stackTraces | CallSite[] |
Returns
any
See
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Inherited from
abstract SqunError
Defined in: src/errors/base.ts:11
Base class for every error thrown by Squn.
Subclasses set a narrower code domain but never override the shape — every SqunError carries a code, structured context, a trace ID for log correlation, a timestamp, and an optional cause (the original driver error).
Extends
Error
Extended by
AdapterErrorAuthErrorConnectionErrorMappingErrorQueryErrorReadonlyViolationErrorSecurityErrorSqunConfigErrorTimeoutErrorTransactionErrorValidationError
Constructors
Constructor
new SqunError(
code,
message,
context,
cause?): SqunError;Defined in: src/errors/base.ts:18
Parameters
| Parameter | Type |
|---|---|
code | ErrorCode |
message | string |
context | ErrorContext |
cause? | unknown |
Returns
Overrides
Error.constructorProperties
| Property | Modifier | Type | Description | Overrides | Inherited from | Defined in |
|---|---|---|---|---|---|---|
cause? | readonly | unknown | The cause of the error. | Error.cause | - | src/errors/base.ts:16 |
code | readonly | ErrorCode | - | - | - | src/errors/base.ts:12 |
context | readonly | ErrorContext | - | - | - | src/errors/base.ts:13 |
message | public | string | - | - | Error.message | node_modules/typescript/lib/lib.es5.d.ts:1077 |
name | public | string | - | - | Error.name | node_modules/typescript/lib/lib.es5.d.ts:1076 |
stack? | public | string | - | - | Error.stack | node_modules/typescript/lib/lib.es5.d.ts:1078 |
timestamp | readonly | Date | - | - | - | src/errors/base.ts:15 |
traceId | readonly | string | - | - | - | src/errors/base.ts:14 |
stackTraceLimit | static | number | The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)). The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | - | Error.stackTraceLimit | node_modules/@types/node/globals.d.ts:67 |
Methods
toJSON()
toJSON(): Record<string, unknown>;Defined in: src/errors/base.ts:31
Returns
Record<string, unknown>
captureStackTrace()
Call Signature
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/@types/node/globals.d.ts:51
Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.
The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.
The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:
function a() {
b();
}
function b() {
c();
}
function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;
// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}
a();Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
Error.captureStackTraceCall Signature
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/bun-types/globals.d.ts:1042
Create .stack property on a target object
Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
Error.captureStackTraceisError()
Call Signature
static isError(error): error is Error;Defined in: node_modules/typescript/lib/lib.esnext.error.d.ts:23
Indicates whether the argument provided is a built-in Error instance or not.
Parameters
| Parameter | Type |
|---|---|
error | unknown |
Returns
error is Error
Inherited from
Error.isErrorCall Signature
static isError(value): value is Error;Defined in: node_modules/bun-types/globals.d.ts:1037
Check if a value is an instance of Error
Parameters
| Parameter | Type | Description |
|---|---|---|
value | unknown | The value to check |
Returns
value is Error
True if the value is an instance of Error, false otherwise
Inherited from
Error.isErrorprepareStackTrace()
static prepareStackTrace(err, stackTraces): any;Defined in: node_modules/@types/node/globals.d.ts:55
Parameters
| Parameter | Type |
|---|---|
err | Error |
stackTraces | CallSite[] |
Returns
any
See
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Inherited from
Error.prepareStackTraceTableType
Defined in: src/core/tvp/table-type.ts:5
Represents a Table-Valued Parameter type definition. Schema maps column names to database type strings (e.g. "nvarchar(100)", "int").
Type Parameters
| Type Parameter |
|---|
Schema extends Record<string, string> |
Constructors
Constructor
new TableType<Schema>(name, schema): TableType<Schema>;Defined in: src/core/tvp/table-type.ts:9
Parameters
| Parameter | Type |
|---|---|
name | string |
schema | Schema |
Returns
TableType<Schema>
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
name | readonly | string | src/core/tvp/table-type.ts:6 |
schema | readonly | Schema | src/core/tvp/table-type.ts:7 |
TimeoutError
Defined in: src/errors/types.ts:8
Base class for every error thrown by Squn.
Subclasses set a narrower code domain but never override the shape — every SqunError carries a code, structured context, a trace ID for log correlation, a timestamp, and an optional cause (the original driver error).
Extends
Constructors
Constructor
new TimeoutError(
code,
message,
context,
cause?): TimeoutError;Defined in: src/errors/base.ts:18
Parameters
| Parameter | Type |
|---|---|
code | ErrorCode |
message | string |
context | ErrorContext |
cause? | unknown |
Returns
Inherited from
Properties
| Property | Modifier | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|---|
cause? | readonly | unknown | The cause of the error. | SqunError.cause | src/errors/base.ts:16 |
code | readonly | ErrorCode | - | SqunError.code | src/errors/base.ts:12 |
context | readonly | ErrorContext | - | SqunError.context | src/errors/base.ts:13 |
message | public | string | - | SqunError.message | node_modules/typescript/lib/lib.es5.d.ts:1077 |
name | public | string | - | SqunError.name | node_modules/typescript/lib/lib.es5.d.ts:1076 |
stack? | public | string | - | SqunError.stack | node_modules/typescript/lib/lib.es5.d.ts:1078 |
timestamp | readonly | Date | - | SqunError.timestamp | src/errors/base.ts:15 |
traceId | readonly | string | - | SqunError.traceId | src/errors/base.ts:14 |
stackTraceLimit | static | number | The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)). The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | SqunError.stackTraceLimit | node_modules/@types/node/globals.d.ts:67 |
Methods
toJSON()
toJSON(): Record<string, unknown>;Defined in: src/errors/base.ts:31
Returns
Record<string, unknown>
Inherited from
captureStackTrace()
Call Signature
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/@types/node/globals.d.ts:51
Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.
The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.
The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:
function a() {
b();
}
function b() {
c();
}
function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;
// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}
a();Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
Call Signature
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/bun-types/globals.d.ts:1042
Create .stack property on a target object
Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
isError()
Call Signature
static isError(error): error is Error;Defined in: node_modules/typescript/lib/lib.esnext.error.d.ts:23
Indicates whether the argument provided is a built-in Error instance or not.
Parameters
| Parameter | Type |
|---|---|
error | unknown |
Returns
error is Error
Inherited from
Call Signature
static isError(value): value is Error;Defined in: node_modules/bun-types/globals.d.ts:1037
Check if a value is an instance of Error
Parameters
| Parameter | Type | Description |
|---|---|---|
value | unknown | The value to check |
Returns
value is Error
True if the value is an instance of Error, false otherwise
Inherited from
prepareStackTrace()
static prepareStackTrace(err, stackTraces): any;Defined in: node_modules/@types/node/globals.d.ts:55
Parameters
| Parameter | Type |
|---|---|
err | Error |
stackTraces | CallSite[] |
Returns
any
See
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Inherited from
Transaction
Defined in: src/transaction/transaction.ts:14
Transaction with state machine: ACTIVE → COMMITTED | ROLLED_BACK | TIMED_OUT | FAILED. Any operation on a non-ACTIVE transaction throws TX_ALREADY_CLOSED immediately.
Constructors
Constructor
new Transaction(tx, id?): Transaction;Defined in: src/transaction/transaction.ts:20
Parameters
| Parameter | Type |
|---|---|
tx | IDbTransaction |
id? | string |
Returns
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
clock | readonly | TransactionClock | src/transaction/transaction.ts:18 |
id | readonly | string | src/transaction/transaction.ts:17 |
Accessors
state
Get Signature
get state(): TransactionState;Defined in: src/transaction/transaction.ts:28
Returns
TransactionState
Methods
[asyncDispose]()
asyncDispose: Promise<void>;Defined in: src/transaction/transaction.ts:90
Returns
Promise<void>
commit()
commit(): Promise<void>;Defined in: src/transaction/transaction.ts:42
Returns
Promise<void>
execute()
execute(sql, params): Promise<{
rowsAffected: number;
}>;Defined in: src/transaction/transaction.ts:37
Parameters
| Parameter | Type |
|---|---|
sql | string |
params | unknown[] |
Returns
Promise<{ rowsAffected: number; }>
markFailed()
markFailed(): void;Defined in: src/transaction/transaction.ts:86
Returns
void
markTimedOut()
markTimedOut(): void;Defined in: src/transaction/transaction.ts:82
Returns
void
query()
query(sql, params): Promise<Row[]>;Defined in: src/transaction/transaction.ts:32
Parameters
| Parameter | Type |
|---|---|
sql | string |
params | unknown[] |
Returns
Promise<Row[]>
rollback()
rollback(): Promise<void>;Defined in: src/transaction/transaction.ts:58
Returns
Promise<void>
savepoint()
savepoint(): Promise<Savepoint>;Defined in: src/transaction/transaction.ts:74
Returns
Promise<Savepoint>
TransactionClock
Defined in: src/async/clock.ts:5
Tracks wall-clock elapsed time for a transaction. Each child query receives at most the remaining budget.
Constructors
Constructor
new TransactionClock(): TransactionClock;Defined in: src/async/clock.ts:8
Returns
Methods
elapsed()
elapsed(): number;Defined in: src/async/clock.ts:13
Milliseconds elapsed since the clock started.
Returns
number
expired()
expired(budgetMs): boolean;Defined in: src/async/clock.ts:27
True if the elapsed time has exceeded the budget.
Parameters
| Parameter | Type |
|---|---|
budgetMs | number |
Returns
boolean
remaining()
remaining(budgetMs): number | null;Defined in: src/async/clock.ts:21
Milliseconds remaining in the budget, or null if no budget applies. Returns 0 (not negative) when the budget is exhausted.
Parameters
| Parameter | Type |
|---|---|
budgetMs | number |
Returns
number | null
TransactionError
Defined in: src/errors/types.ts:7
Base class for every error thrown by Squn.
Subclasses set a narrower code domain but never override the shape — every SqunError carries a code, structured context, a trace ID for log correlation, a timestamp, and an optional cause (the original driver error).
Extends
Extended by
Constructors
Constructor
new TransactionError(
code,
message,
context,
cause?): TransactionError;Defined in: src/errors/base.ts:18
Parameters
| Parameter | Type |
|---|---|
code | ErrorCode |
message | string |
context | ErrorContext |
cause? | unknown |
Returns
Inherited from
Properties
| Property | Modifier | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|---|
cause? | readonly | unknown | The cause of the error. | SqunError.cause | src/errors/base.ts:16 |
code | readonly | ErrorCode | - | SqunError.code | src/errors/base.ts:12 |
context | readonly | ErrorContext | - | SqunError.context | src/errors/base.ts:13 |
message | public | string | - | SqunError.message | node_modules/typescript/lib/lib.es5.d.ts:1077 |
name | public | string | - | SqunError.name | node_modules/typescript/lib/lib.es5.d.ts:1076 |
stack? | public | string | - | SqunError.stack | node_modules/typescript/lib/lib.es5.d.ts:1078 |
timestamp | readonly | Date | - | SqunError.timestamp | src/errors/base.ts:15 |
traceId | readonly | string | - | SqunError.traceId | src/errors/base.ts:14 |
stackTraceLimit | static | number | The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)). The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | SqunError.stackTraceLimit | node_modules/@types/node/globals.d.ts:67 |
Methods
toJSON()
toJSON(): Record<string, unknown>;Defined in: src/errors/base.ts:31
Returns
Record<string, unknown>
Inherited from
captureStackTrace()
Call Signature
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/@types/node/globals.d.ts:51
Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.
The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.
The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:
function a() {
b();
}
function b() {
c();
}
function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;
// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}
a();Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
Call Signature
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/bun-types/globals.d.ts:1042
Create .stack property on a target object
Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
isError()
Call Signature
static isError(error): error is Error;Defined in: node_modules/typescript/lib/lib.esnext.error.d.ts:23
Indicates whether the argument provided is a built-in Error instance or not.
Parameters
| Parameter | Type |
|---|---|
error | unknown |
Returns
error is Error
Inherited from
Call Signature
static isError(value): value is Error;Defined in: node_modules/bun-types/globals.d.ts:1037
Check if a value is an instance of Error
Parameters
| Parameter | Type | Description |
|---|---|---|
value | unknown | The value to check |
Returns
value is Error
True if the value is an instance of Error, false otherwise
Inherited from
prepareStackTrace()
static prepareStackTrace(err, stackTraces): any;Defined in: node_modules/@types/node/globals.d.ts:55
Parameters
| Parameter | Type |
|---|---|
err | Error |
stackTraces | CallSite[] |
Returns
any
See
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Inherited from
TypeHandlerRegistry
Defined in: src/core/type-handler.ts:112
Registers and looks up TypeHandlers by column type string. Built-in handlers cover all standard column types. Unknown types fall back to an identity handler that passes values through unchanged.
Constructors
Constructor
new TypeHandlerRegistry(): TypeHandlerRegistry;Returns
Methods
fromDb()
fromDb(dbType, raw): unknown;Defined in: src/core/type-handler.ts:126
Converts a raw database value to the TypeScript type for the given column type.
Parameters
| Parameter | Type |
|---|---|
dbType | string |
raw | unknown |
Returns
unknown
get()
get(dbType): TypeHandler;Defined in: src/core/type-handler.ts:121
Returns the handler for a column type. Falls back to identity for unknown types.
Parameters
| Parameter | Type |
|---|---|
dbType | string |
Returns
register()
register<T>(dbType, handler): void;Defined in: src/core/type-handler.ts:116
Registers a custom handler for a column type, overriding any built-in.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
dbType | string |
handler | TypeHandler<T> |
Returns
void
toDb()
toDb(dbType, value): unknown;Defined in: src/core/type-handler.ts:132
Converts a TypeScript value to the database type for the given column type.
Parameters
| Parameter | Type |
|---|---|
dbType | string |
value | unknown |
Returns
unknown
ValidationError
Defined in: src/errors/types.ts:6
Base class for every error thrown by Squn.
Subclasses set a narrower code domain but never override the shape — every SqunError carries a code, structured context, a trace ID for log correlation, a timestamp, and an optional cause (the original driver error).
Extends
Constructors
Constructor
new ValidationError(
code,
message,
context,
cause?): ValidationError;Defined in: src/errors/base.ts:18
Parameters
| Parameter | Type |
|---|---|
code | ErrorCode |
message | string |
context | ErrorContext |
cause? | unknown |
Returns
Inherited from
Properties
| Property | Modifier | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|---|
cause? | readonly | unknown | The cause of the error. | SqunError.cause | src/errors/base.ts:16 |
code | readonly | ErrorCode | - | SqunError.code | src/errors/base.ts:12 |
context | readonly | ErrorContext | - | SqunError.context | src/errors/base.ts:13 |
message | public | string | - | SqunError.message | node_modules/typescript/lib/lib.es5.d.ts:1077 |
name | public | string | - | SqunError.name | node_modules/typescript/lib/lib.es5.d.ts:1076 |
stack? | public | string | - | SqunError.stack | node_modules/typescript/lib/lib.es5.d.ts:1078 |
timestamp | readonly | Date | - | SqunError.timestamp | src/errors/base.ts:15 |
traceId | readonly | string | - | SqunError.traceId | src/errors/base.ts:14 |
stackTraceLimit | static | number | The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)). The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. | SqunError.stackTraceLimit | node_modules/@types/node/globals.d.ts:67 |
Methods
toJSON()
toJSON(): Record<string, unknown>;Defined in: src/errors/base.ts:31
Returns
Record<string, unknown>
Inherited from
captureStackTrace()
Call Signature
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/@types/node/globals.d.ts:51
Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack; // Similar to `new Error().stack`The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.
The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.
The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:
function a() {
b();
}
function b() {
c();
}
function c() {
// Create an error without stack trace to avoid calculating the stack trace twice.
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
const error = new Error();
Error.stackTraceLimit = stackTraceLimit;
// Capture the stack trace above function b
Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
throw error;
}
a();Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
Call Signature
static captureStackTrace(targetObject, constructorOpt?): void;Defined in: node_modules/bun-types/globals.d.ts:1042
Create .stack property on a target object
Parameters
| Parameter | Type |
|---|---|
targetObject | object |
constructorOpt? | Function |
Returns
void
Inherited from
isError()
Call Signature
static isError(error): error is Error;Defined in: node_modules/typescript/lib/lib.esnext.error.d.ts:23
Indicates whether the argument provided is a built-in Error instance or not.
Parameters
| Parameter | Type |
|---|---|
error | unknown |
Returns
error is Error
Inherited from
Call Signature
static isError(value): value is Error;Defined in: node_modules/bun-types/globals.d.ts:1037
Check if a value is an instance of Error
Parameters
| Parameter | Type | Description |
|---|---|---|
value | unknown | The value to check |
Returns
value is Error
True if the value is an instance of Error, false otherwise
Inherited from
prepareStackTrace()
static prepareStackTrace(err, stackTraces): any;Defined in: node_modules/@types/node/globals.d.ts:55
Parameters
| Parameter | Type |
|---|---|
err | Error |
stackTraces | CallSite[] |
Returns
any
See
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Inherited from
Interfaces
AtomicBlockOptions
Defined in: src/transaction/atomic.ts:24
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
maxRetries? | readonly | number | src/transaction/atomic.ts:27 |
retryDelayMs? | readonly | number | src/transaction/atomic.ts:28 |
retryOnError? | readonly | boolean | src/transaction/atomic.ts:26 |
timeoutMs? | readonly | number | src/transaction/atomic.ts:25 |
AtomicExecutor
Defined in: src/transaction/atomic.ts:12
The limited API available inside an atomically() callback.
Methods
execute()
execute(fragment): Promise<{
rowsAffected: number;
}>;Defined in: src/transaction/atomic.ts:17
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
Returns
Promise<{ rowsAffected: number; }>
executeBatch()
executeBatch(fragment, rows): Promise<{
rowsAffected: number;
}>;Defined in: src/transaction/atomic.ts:18
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
rows | readonly Record<string, unknown>[] |
Returns
Promise<{ rowsAffected: number; }>
query()
query<T>(fragment): Promise<T[]>;Defined in: src/transaction/atomic.ts:13
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
Returns
Promise<T[]>
queryFirst()
queryFirst<T>(fragment): Promise<T | null>;Defined in: src/transaction/atomic.ts:14
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
Returns
Promise<T | null>
queryScalar()
queryScalar<T>(fragment): Promise<T>;Defined in: src/transaction/atomic.ts:16
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
Returns
Promise<T>
querySingle()
querySingle<T>(fragment): Promise<T>;Defined in: src/transaction/atomic.ts:15
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
Returns
Promise<T>
AzureAdConfig
Defined in: src/config/types.ts:64
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
clientId? | readonly | string | src/config/types.ts:66 |
clientSecret? | readonly | string | src/config/types.ts:67 |
managedIdentity? | readonly | boolean | src/config/types.ts:68 |
tenantId? | readonly | string | src/config/types.ts:65 |
CacheConfig
Defined in: src/config/types.ts:40
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
maxAgeMs? | readonly | number | null | src/config/types.ts:43 |
maxSize? | readonly | number | src/config/types.ts:41 |
reaperIntervalMs? | readonly | number | null | src/config/types.ts:44 |
ttlMs? | readonly | number | null | src/config/types.ts:42 |
ColumnDef
Defined in: src/types/col.ts:9
Column definition builder.
Captures column metadata as a plain object. Generic parameters encode the column's TypeScript type, nullability, and readonly status so that InferModel / InferInsert can read them at the type level.
Type Parameters
| Type Parameter | Default type |
|---|---|
T | unknown |
Nullable extends boolean | boolean |
Readonly extends boolean | boolean |
Properties
| Property | Modifier | Type | Description | Defined in |
|---|---|---|---|---|
__brand | readonly | "ColumnDef" | - | src/types/col.ts:14 |
_type | readonly | Nullable extends true ? T | null : T | Phantom — carries the resolved TS type for inference. | src/types/col.ts:24 |
computedExpr | readonly | string | null | - | src/types/col.ts:21 |
dbMaxLength | readonly | number | "MAX" | null | - | src/types/col.ts:16 |
dbType | readonly | string | - | src/types/col.ts:15 |
isComputed | readonly | boolean | - | src/types/col.ts:20 |
isNullable | readonly | Nullable | - | src/types/col.ts:17 |
isPrimaryKey | readonly | boolean | - | src/types/col.ts:19 |
isReadonly | readonly | Readonly | - | src/types/col.ts:18 |
isUnique | readonly | boolean | - | src/types/col.ts:22 |
CompiledQuery
Defined in: src/cache/query-cache.ts:4
The compiled representation of a query stored in the cache.
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
normalizedSql | readonly | string | src/cache/query-cache.ts:5 |
paramNames | readonly | readonly string[] | src/cache/query-cache.ts:6 |
ConnectionConfig
Defined in: src/config/types.ts:11
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
authType? | readonly | AuthType | src/config/types.ts:19 |
database? | readonly | string | src/config/types.ts:15 |
domain? | readonly | string | src/config/types.ts:20 |
host? | readonly | string | src/config/types.ts:13 |
password? | readonly | string | src/config/types.ts:17 |
port? | readonly | number | src/config/types.ts:14 |
readonly? | readonly | boolean | src/config/types.ts:22 |
ssl? | readonly | boolean | "require" | src/config/types.ts:18 |
upn? | readonly | string | src/config/types.ts:21 |
url? | readonly | string | src/config/types.ts:12 |
user? | readonly | string | src/config/types.ts:16 |
Database
Defined in: src/db.ts:27
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
adapter | readonly | IDbAdapter | src/db.ts:28 |
config | readonly | SqunConfig | src/db.ts:29 |
Methods
atomically()
atomically<T>(fn, options?): Promise<T>;Defined in: src/db.ts:43
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
fn | (q) => Promise<T> |
options? | AtomicBlockOptions |
Returns
Promise<T>
execute()
execute(fragment): Promise<{
rowsAffected: number;
}>;Defined in: src/db.ts:36
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
Returns
Promise<{ rowsAffected: number; }>
executeBatch()
executeBatch(
fragment,
rows,
options?): Promise<{
rowsAffected: number;
}>;Defined in: src/db.ts:37
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
rows | readonly Record<string, unknown>[] |
options? | { strategy?: "prepared-loop" | "copy" | "bulk-load"; } |
options.strategy? | "prepared-loop" | "copy" | "bulk-load" |
Returns
Promise<{ rowsAffected: number; }>
prepare()
prepare<T, P>(fragment, paramNames): PreparedQuery<T, P>;Defined in: src/db.ts:45
Type Parameters
| Type Parameter |
|---|
T |
P extends Record<string, unknown> |
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
paramNames | readonly string[] |
Returns
PreparedQuery<T, P>
query()
query<T>(fragment): Promise<T[]>;Defined in: src/db.ts:31
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
Returns
Promise<T[]>
queryFirst()
queryFirst<T>(fragment): Promise<T | null>;Defined in: src/db.ts:32
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
Returns
Promise<T | null>
queryMultiple()
queryMultiple(fragment): Promise<Row[][]>;Defined in: src/db.ts:35
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
Returns
Promise<Row[][]>
queryScalar()
queryScalar<T>(fragment): Promise<T>;Defined in: src/db.ts:34
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
Returns
Promise<T>
querySingle()
querySingle<T>(fragment): Promise<T>;Defined in: src/db.ts:33
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
Returns
Promise<T>
stream()
stream<T>(fragment, batchSize?): AsyncIterableIterator<T>;Defined in: src/db.ts:42
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
batchSize? | number |
Returns
AsyncIterableIterator<T>
transaction()
transaction(fn): Promise<void>;Defined in: src/db.ts:44
Parameters
| Parameter | Type |
|---|---|
fn | (tx) => Promise<void> |
Returns
Promise<void>
DetectionResult
Defined in: src/sql/injection-detector.ts:5
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
detected | readonly | boolean | src/sql/injection-detector.ts:6 |
pattern | readonly | string | null | src/sql/injection-detector.ts:8 |
severity | readonly | Severity | null | src/sql/injection-detector.ts:7 |
ErrorContext
Defined in: src/errors/context.ts:8
Structured context attached to every SqunError.
All fields are optional — each error subclass populates only the fields relevant to its failure mode. Consumers should never assume a field is present without checking.
Properties
| Property | Modifier | Type | Description | Defined in |
|---|---|---|---|---|
adapter? | readonly | string | Which database adapter was in use ("sqlite" | "postgres" |
column? | readonly | string | Column name relevant to the error. | src/errors/context.ts:25 |
durationMs? | readonly | number | Elapsed wall-clock time in milliseconds when the error occurred. | src/errors/context.ts:34 |
operation? | readonly | string | The high-level operation that failed (e.g. "query", "execute", "commit"). | src/errors/context.ts:10 |
paramKeys? | readonly | readonly string[] | Param key names from the query (values are never logged). | src/errors/context.ts:16 |
registeredNames? | readonly | readonly string[] | Connection names currently registered — aids debugging CONN_UNKNOWN errors. | src/errors/context.ts:43 |
requestedName? | readonly | string | Connection name that was requested but not found in the registry. | src/errors/context.ts:40 |
rowIndex? | readonly | number | Row index within a result set where mapping failed. | src/errors/context.ts:31 |
sql? | readonly | string | Sanitised SQL text — param values are never included. | src/errors/context.ts:13 |
table? | readonly | string | Table name relevant to the error. | src/errors/context.ts:22 |
tvpRowIndex? | readonly | number | Row index within a TVP batch where validation failed. | src/errors/context.ts:28 |
txId? | readonly | string | Transaction identifier — ties the error to a specific transaction scope. | src/errors/context.ts:37 |
ExecuteOptions
Defined in: src/connections/types.ts:33
Type Parameters
| Type Parameter | Default type |
|---|---|
Names extends string | never |
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
connection? | readonly | [Names] extends [never] ? never : Names | src/connections/types.ts:34 |
timeoutMs? | readonly | number | src/connections/types.ts:35 |
GroupConfig
Defined in: src/connections/types.ts:19
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
read | readonly | readonly string[] | src/connections/types.ts:21 |
readMode? | readonly | "round-robin" | "least-load" | "random" | src/connections/types.ts:22 |
write | readonly | string | src/connections/types.ts:20 |
IDbAdapter
Defined in: src/adapters/base.ts:31
Database adapter contract — all database-specific behaviour lives here.
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
type | readonly | AdapterType | src/adapters/base.ts:32 |
Methods
beginTransaction()
beginTransaction(): Promise<IDbTransaction>;Defined in: src/adapters/base.ts:46
Returns
Promise<IDbTransaction>
close()
close(): Promise<void>;Defined in: src/adapters/base.ts:50
Returns
Promise<void>
execute()
execute(sql, params): Promise<{
rowsAffected: number;
}>;Defined in: src/adapters/base.ts:33
Parameters
| Parameter | Type |
|---|---|
sql | string |
params | readonly unknown[] |
Returns
Promise<{ rowsAffected: number; }>
executeBatch()
executeBatch(
sql,
rows,
paramNames,
strategy?): Promise<{
rowsAffected: number;
}>;Defined in: src/adapters/base.ts:40
Executes the same prepared statement once per row using native batch/pipeline. paramNames maps column names to positional params in sql.
Parameters
| Parameter | Type |
|---|---|
sql | string |
rows | readonly Record<string, unknown>[] |
paramNames | readonly string[] |
strategy? | "prepared-loop" | "copy" | "bulk-load" |
Returns
Promise<{ rowsAffected: number; }>
hasCursorSupport()
hasCursorSupport(): boolean;Defined in: src/adapters/base.ts:48
Returns true if the adapter supports server-side cursors for streaming.
Returns
boolean
materializeTvp()
materializeTvp(tvp, index): Promise<TvpMaterialised>;Defined in: src/adapters/base.ts:51
Parameters
| Parameter | Type |
|---|---|
tvp | TvpValue |
index | number |
Returns
Promise<TvpMaterialised>
ping()
ping(): Promise<void>;Defined in: src/adapters/base.ts:49
Returns
Promise<void>
query()
query(sql, params): Promise<Row[]>;Defined in: src/adapters/base.ts:34
Parameters
| Parameter | Type |
|---|---|
sql | string |
params | readonly unknown[] |
Returns
Promise<Row[]>
queryMultiple()
queryMultiple(sql, params): Promise<Row[][]>;Defined in: src/adapters/base.ts:35
Parameters
| Parameter | Type |
|---|---|
sql | string |
params | readonly unknown[] |
Returns
Promise<Row[][]>
IDbTransaction
Defined in: src/adapters/base.ts:20
Transaction handle returned by beginTransaction().
Methods
commit()
commit(): Promise<void>;Defined in: src/adapters/base.ts:23
Returns
Promise<void>
execute()
execute(sql, params): Promise<{
rowsAffected: number;
}>;Defined in: src/adapters/base.ts:21
Parameters
| Parameter | Type |
|---|---|
sql | string |
params | readonly unknown[] |
Returns
Promise<{ rowsAffected: number; }>
query()
query(sql, params): Promise<Row[]>;Defined in: src/adapters/base.ts:22
Parameters
| Parameter | Type |
|---|---|
sql | string |
params | readonly unknown[] |
Returns
Promise<Row[]>
releaseSavepoint()
releaseSavepoint(name): Promise<void>;Defined in: src/adapters/base.ts:26
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
Promise<void>
rollback()
rollback(): Promise<void>;Defined in: src/adapters/base.ts:24
Returns
Promise<void>
rollbackToSavepoint()
rollbackToSavepoint(name): Promise<void>;Defined in: src/adapters/base.ts:27
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
Promise<void>
savepoint()
savepoint(name): Promise<void>;Defined in: src/adapters/base.ts:25
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
Promise<void>
LogConfig
Defined in: src/config/types.ts:58
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
level? | readonly | "debug" | "info" | "warn" | "error" | "fatal" | src/config/types.ts:60 |
logger? | readonly | SqunLogger | src/config/types.ts:59 |
slowQueryMs? | readonly | number | src/config/types.ts:61 |
LogEntry
Defined in: src/logging/logger.ts:21
Structured log entry emitted by every logging call in the library.
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
cause? | readonly | string | src/logging/logger.ts:29 |
code | readonly | ErrorCode | EventCode | src/logging/logger.ts:25 |
context | readonly | ErrorContext | src/logging/logger.ts:27 |
durationMs? | readonly | number | src/logging/logger.ts:30 |
level | readonly | "debug" | "info" | "warn" | "error" | "fatal" | src/logging/logger.ts:22 |
message | readonly | string | src/logging/logger.ts:26 |
rowCount? | readonly | number | src/logging/logger.ts:31 |
stack? | readonly | string | src/logging/logger.ts:28 |
timestamp | readonly | string | src/logging/logger.ts:23 |
traceId | readonly | string | src/logging/logger.ts:24 |
MultiAtomicOptions
Defined in: src/connections/types.ts:44
Type Parameters
| Type Parameter | Default type |
|---|---|
Names extends string | never |
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
connection? | readonly | [Names] extends [never] ? never : Names | src/connections/types.ts:45 |
maxRetries? | readonly | number | src/connections/types.ts:48 |
retryDelayMs? | readonly | number | src/connections/types.ts:49 |
retryOnError? | readonly | boolean | src/connections/types.ts:47 |
timeoutMs? | readonly | number | src/connections/types.ts:46 |
MultiDatabase
Defined in: src/db.ts:125
Type Parameters
| Type Parameter | Default type |
|---|---|
Names extends string | string |
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
config | readonly | SqunConfig | src/db.ts:127 |
registry | readonly | ConnectionRegistry<Names> | src/db.ts:126 |
Methods
atomically()
atomically<T>(fn, options?): Promise<T>;Defined in: src/db.ts:146
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
fn | (q) => Promise<T> |
options? | MultiAtomicOptions<Names> |
Returns
Promise<T>
concurrent()
concurrent<T>(...queries): Promise<{ [K in string | number | symbol]: Awaited<T[K]> }>;Defined in: src/db.ts:154
Type Parameters
| Type Parameter |
|---|
T extends readonly Promise<unknown>[] |
Parameters
| Parameter | Type |
|---|---|
...queries | T |
Returns
Promise<{ [K in string | number | symbol]: Awaited<T[K]> }>
execute()
execute(fragment, options?): Promise<{
rowsAffected: number;
}>;Defined in: src/db.ts:136
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
options? | ExecuteOptions<Names> |
Returns
Promise<{ rowsAffected: number; }>
executeBatch()
executeBatch(
fragment,
rows,
options?): Promise<{
rowsAffected: number;
}>;Defined in: src/db.ts:140
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
rows | readonly Record<string, unknown>[] |
options? | ExecuteOptions<Names> & object |
Returns
Promise<{ rowsAffected: number; }>
prepare()
prepare<T, P>(
fragment,
paramNames,
options?): PreparedQuery<T, P>;Defined in: src/db.ts:157
Type Parameters
| Type Parameter |
|---|
T |
P extends Record<string, unknown> |
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
paramNames | readonly string[] |
options? | { connection?: Names; } |
options.connection? | Names |
Returns
PreparedQuery<T, P>
query()
query<T>(fragment, options?): Promise<T[]>;Defined in: src/db.ts:132
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
options? | QueryOptions<Names> |
Returns
Promise<T[]>
queryFirst()
queryFirst<T>(fragment, options?): Promise<T | null>;Defined in: src/db.ts:133
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
options? | QueryOptions<Names> |
Returns
Promise<T | null>
queryScalar()
queryScalar<T>(fragment, options?): Promise<T>;Defined in: src/db.ts:135
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
options? | QueryOptions<Names> |
Returns
Promise<T>
querySingle()
querySingle<T>(fragment, options?): Promise<T>;Defined in: src/db.ts:134
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
options? | QueryOptions<Names> |
Returns
Promise<T>
stream()
stream<T>(fragment, options?): AsyncIterableIterator<T>;Defined in: src/db.ts:145
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
options? | StreamOptions<Names> |
Returns
AsyncIterableIterator<T>
transaction()
transaction(fn, options?): Promise<void>;Defined in: src/db.ts:150
Parameters
| Parameter | Type |
|---|---|
fn | (tx) => Promise<void> |
options? | { connection?: Names; } |
options.connection? | Names |
Returns
Promise<void>
use()
use(name): ScopedDb<Names>;Defined in: src/db.ts:130
Returns a ScopedDb with the named adapter pre-resolved — no connection option needed.
Parameters
| Parameter | Type |
|---|---|
name | Names |
Returns
ScopedDb<Names>
MultiDbConfig
Defined in: src/connections/types.ts:12
Config for createConnections().
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
connections | readonly | MultiConnectionMap | src/connections/types.ts:13 |
default | readonly | string | src/connections/types.ts:14 |
groups? | readonly | Record<string, GroupConfig> | src/connections/types.ts:16 |
overrides? | readonly | Record<string, Partial<SqunConfig>> | src/connections/types.ts:15 |
PoolConfig
Defined in: src/config/types.ts:25
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
max? | readonly | number | src/config/types.ts:27 |
maxConnectionAgeMs? | readonly | number | src/config/types.ts:28 |
maxQueueSize? | readonly | number | src/config/types.ts:30 |
maxUseCount? | readonly | number | src/config/types.ts:29 |
min? | readonly | number | src/config/types.ts:26 |
PoolStatsSnapshot
Defined in: src/pool/stats.ts:2
Snapshot of pool metrics at a point in time.
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
acquired | readonly | number | src/pool/stats.ts:5 |
avgAcquireMs | readonly | number | src/pool/stats.ts:12 |
avgIdleMs | readonly | number | src/pool/stats.ts:13 |
avgUseMs | readonly | number | src/pool/stats.ts:14 |
idle | readonly | number | src/pool/stats.ts:4 |
max | readonly | number | src/pool/stats.ts:8 |
min | readonly | number | src/pool/stats.ts:7 |
total | readonly | number | src/pool/stats.ts:3 |
totalAcquired | readonly | number | src/pool/stats.ts:11 |
totalCreated | readonly | number | src/pool/stats.ts:9 |
totalDestroyed | readonly | number | src/pool/stats.ts:10 |
waiting | readonly | number | src/pool/stats.ts:6 |
QueryOptions
Defined in: src/connections/types.ts:26
Query options — connection field uses Names union or never for single-db.
Type Parameters
| Type Parameter | Default type |
|---|---|
Names extends string | never |
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
cache? | readonly | boolean | src/connections/types.ts:29 |
connection? | readonly | [Names] extends [never] ? never : Names | src/connections/types.ts:27 |
strict? | readonly | boolean | src/connections/types.ts:30 |
timeoutMs? | readonly | number | src/connections/types.ts:28 |
ScopedDb
Defined in: src/connections/types.ts:53
A scoped Database bound to a specific named connection via .use().
Type Parameters
| Type Parameter | Default type |
|---|---|
Names extends string | never |
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
connectionName | readonly | Names | src/connections/types.ts:54 |
Methods
atomically()
atomically<T>(fn, options?): Promise<T>;Defined in: src/connections/types.ts:67
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
fn | (q) => Promise<T> |
options? | AtomicBlockOptions |
Returns
Promise<T>
execute()
execute(fragment): Promise<{
rowsAffected: number;
}>;Defined in: src/connections/types.ts:60
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
Returns
Promise<{ rowsAffected: number; }>
executeBatch()
executeBatch(
fragment,
rows,
options?): Promise<{
rowsAffected: number;
}>;Defined in: src/connections/types.ts:61
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
rows | readonly Record<string, unknown>[] |
options? | { strategy?: "prepared-loop" | "copy" | "bulk-load"; } |
options.strategy? | "prepared-loop" | "copy" | "bulk-load" |
Returns
Promise<{ rowsAffected: number; }>
prepare()
prepare<T, P>(fragment, paramNames): PreparedQuery<T, P>;Defined in: src/connections/types.ts:69
Type Parameters
| Type Parameter |
|---|
T |
P extends Record<string, unknown> |
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
paramNames | readonly string[] |
Returns
PreparedQuery<T, P>
query()
query<T>(fragment): Promise<T[]>;Defined in: src/connections/types.ts:56
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
Returns
Promise<T[]>
queryFirst()
queryFirst<T>(fragment): Promise<T | null>;Defined in: src/connections/types.ts:57
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
Returns
Promise<T | null>
queryScalar()
queryScalar<T>(fragment): Promise<T>;Defined in: src/connections/types.ts:59
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
Returns
Promise<T>
querySingle()
querySingle<T>(fragment): Promise<T>;Defined in: src/connections/types.ts:58
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
Returns
Promise<T>
stream()
stream<T>(fragment, batchSize?): AsyncIterableIterator<T>;Defined in: src/connections/types.ts:66
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
batchSize? | number |
Returns
AsyncIterableIterator<T>
transaction()
transaction(fn): Promise<void>;Defined in: src/connections/types.ts:68
Parameters
| Parameter | Type |
|---|---|
fn | (tx) => Promise<void> |
Returns
Promise<void>
SecurityConfig
Defined in: src/config/types.ts:47
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
detectInjection? | readonly | boolean | src/config/types.ts:48 |
format? | readonly | object | src/config/types.ts:52 |
format.normalizeKeywords? | readonly | boolean | src/config/types.ts:53 |
format.normalizeWhitespace? | readonly | boolean | src/config/types.ts:54 |
strictRaw? | readonly | boolean | src/config/types.ts:49 |
validateSql? | readonly | boolean | src/config/types.ts:50 |
warnOnRawString? | readonly | boolean | src/config/types.ts:51 |
SqlFragment
Defined in: src/sql/fragment.ts:9
The return type of the sql tagged template and all composition helpers.
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
__isSql | readonly | true | src/sql/fragment.ts:13 |
params | readonly | readonly unknown[] | src/sql/fragment.ts:11 |
text | readonly | string | src/sql/fragment.ts:10 |
tvpValues | readonly | readonly TvpValue[] | src/sql/fragment.ts:12 |
SqunConfig
Defined in: src/config/types.ts:71
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
azure? | readonly | AzureAdConfig | src/config/types.ts:79 |
cache? | readonly | CacheConfig | src/config/types.ts:76 |
connection? | readonly | ConnectionConfig | src/config/types.ts:73 |
deadlockRetries? | readonly | number | src/config/types.ts:83 |
env? | readonly | Environment | src/config/types.ts:72 |
errorVerbosity? | readonly | ErrorVerbosity | src/config/types.ts:80 |
log? | readonly | LogConfig | src/config/types.ts:78 |
maskSensitive? | readonly | boolean | src/config/types.ts:81 |
pool? | readonly | PoolConfig | src/config/types.ts:74 |
security? | readonly | SecurityConfig | src/config/types.ts:77 |
strict? | readonly | boolean | src/config/types.ts:82 |
timeout? | readonly | TimeoutConfig | src/config/types.ts:75 |
tvpCopyThreshold? | readonly | number | src/config/types.ts:84 |
SqunLogger
Defined in: src/logging/logger.ts:35
Logger contract — every built-in logger and user-provided logger must satisfy this.
Methods
debug()
debug(entry): void;Defined in: src/logging/logger.ts:36
Parameters
| Parameter | Type |
|---|---|
entry | LogEntry |
Returns
void
error()
error(entry): void;Defined in: src/logging/logger.ts:39
Parameters
| Parameter | Type |
|---|---|
entry | LogEntry |
Returns
void
fatal()
fatal(entry): void;Defined in: src/logging/logger.ts:40
Parameters
| Parameter | Type |
|---|---|
entry | LogEntry |
Returns
void
info()
info(entry): void;Defined in: src/logging/logger.ts:37
Parameters
| Parameter | Type |
|---|---|
entry | LogEntry |
Returns
void
warn()
warn(entry): void;Defined in: src/logging/logger.ts:38
Parameters
| Parameter | Type |
|---|---|
entry | LogEntry |
Returns
void
StreamOptions
Defined in: src/connections/types.ts:38
Type Parameters
| Type Parameter | Default type |
|---|---|
Names extends string | never |
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
batchSize? | readonly | number | src/connections/types.ts:41 |
connection? | readonly | [Names] extends [never] ? never : Names | src/connections/types.ts:39 |
timeoutMs? | readonly | number | src/connections/types.ts:40 |
TableDefinition
Defined in: src/types/table.ts:7
The shape returned by defineTable() — carries table name and column map at the type level.
Type Parameters
| Type Parameter | Default type |
|---|---|
Name extends string | string |
Columns extends ColumnMap | ColumnMap |
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
__brand | readonly | "TableDefinition" | src/types/table.ts:11 |
columnNames | readonly | readonly keyof Columns & string[] | src/types/table.ts:14 |
columns | readonly | Columns | src/types/table.ts:13 |
tableName | readonly | Name | src/types/table.ts:12 |
TimeoutConfig
Defined in: src/config/types.ts:33
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
acquire? | readonly | number | src/config/types.ts:37 |
connect? | readonly | number | src/config/types.ts:36 |
query? | readonly | number | src/config/types.ts:34 |
transaction? | readonly | number | src/config/types.ts:35 |
TvpMaterialised
Defined in: src/adapters/base.ts:6
Materialised TVP result — replaces a TVP_N sentinel in final SQL.
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
cleanup | readonly | () => Promise<void> | src/adapters/base.ts:9 |
extraParams | readonly | readonly unknown[] | src/adapters/base.ts:8 |
sqlExpression | readonly | string | src/adapters/base.ts:7 |
TvpValue
Defined in: src/sql/fragment.ts:2
TVP value extracted from a SqlFragment by the sql tag.
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
__isTvp | readonly | true | src/sql/fragment.ts:3 |
rows | readonly | readonly Record<string, unknown>[] | src/sql/fragment.ts:5 |
tableType | readonly | unknown | src/sql/fragment.ts:4 |
TypeHandler
Defined in: src/core/type-handler.ts:2
Converts values between database driver types and TypeScript types.
Type Parameters
| Type Parameter | Default type |
|---|---|
T | unknown |
Methods
fromDb()
fromDb(raw): T;Defined in: src/core/type-handler.ts:3
Parameters
| Parameter | Type |
|---|---|
raw | unknown |
Returns
T
toDb()
toDb(value): unknown;Defined in: src/core/type-handler.ts:4
Parameters
| Parameter | Type |
|---|---|
value | T |
Returns
unknown
Type Aliases
AdapterType
type AdapterType = "sqlite" | "postgres" | "mysql" | "mssql";Defined in: src/config/types.ts:5
AuthConfig
type AuthConfig =
| UserPassAuth
| WindowsAuth
| WindowsUpnAuth
| ConnectionStringAuth
| AzureAdAuth;Defined in: src/auth/types.ts:32
AuthType
type AuthType =
| "userpass"
| "windows"
| "windows-upn"
| "connection-string"
| "azure-ad";Defined in: src/config/types.ts:7
ColumnMap
type ColumnMap = Record<string, ColumnDef>;Defined in: src/types/table.ts:4
A map of column names to their ColumnDef definitions.
ColumnValue
type ColumnValue = string | number | boolean | null | Date | Buffer | unknown[];Defined in: src/types/primitives.ts:8
The resolved database type for a single column value.
Environment
type Environment = "development" | "production" | "test";Defined in: src/config/types.ts:3
InferInsert
type InferInsert<T> = { [K in MutableKeys<T>]: T["columns"][K]["_type"] };Defined in: src/types/infer.ts:60
Insert shape — primaryKey and readonly columns excluded.
Type Parameters
| Type Parameter |
|---|
T extends HasColumnDefs |
InferModel
type InferModel<T> = { [K in keyof T["columns"] & string]: T["columns"][K]["_type"] };Defined in: src/types/infer.ts:55
Full row type with nullability — every column included.
Type Parameters
| Type Parameter |
|---|
T extends HasColumns |
InferReadonlyModel
type InferReadonlyModel<T> = { [K in ReadonlyKeys<T>]: T["columns"][K]["_type"] };Defined in: src/types/infer.ts:70
Only the fields marked readonly.
Type Parameters
| Type Parameter |
|---|
T extends HasColumnDefs |
InferSelect
type InferSelect<T, K> = { [P in K]: T["columns"][P]["_type"] };Defined in: src/types/infer.ts:75
Narrowed shape — only the selected column keys.
Type Parameters
| Type Parameter |
|---|
T extends HasColumns |
K extends keyof T["columns"] & string |
InferTableType
type InferTableType<T> = { [K in keyof T["columns"] & string]: T["columns"][K]["_type"] };Defined in: src/types/infer.ts:84
TypeScript type from a TableType TVP definition. TableType shares the same column structure as TableDefinition, so this utility extracts the model shape identically.
Type Parameters
| Type Parameter |
|---|
T extends HasColumns |
InferUpdate
type InferUpdate<T> = { [K in MutableKeys<T>]?: T["columns"][K]["_type"] };Defined in: src/types/infer.ts:65
Update shape — readonly columns excluded, all remaining fields optional.
Type Parameters
| Type Parameter |
|---|
T extends HasColumnDefs |
IsNullable
type IsNullable<T, K> = T["columns"][K] extends ColumnDef<infer _T, true, infer _R> ? true : false;Defined in: src/types/infer.ts:49
true if column K is nullable, false otherwise.
Type Parameters
| Type Parameter |
|---|
T extends HasColumnDefs |
K extends keyof T["columns"] |
MultiConnectionMap
type MultiConnectionMap = Record<string, IDbAdapter>;Defined in: src/connections/types.ts:9
Map of named connections.
MutableKeys
type MutableKeys<T> = { [K in keyof T["columns"] & string]: T["columns"][K] extends ColumnDef<infer _T, infer _N, true> ? never : K }[keyof T["columns"] & string];Defined in: src/types/infer.ts:42
Union of column names where isReadonly is false (writable).
Type Parameters
| Type Parameter |
|---|
T extends HasColumnDefs |
NotNullKeys
type NotNullKeys<T> = { [K in keyof T["columns"] & string]: T["columns"][K] extends ColumnDef<infer _T, true, infer _R> ? never : K }[keyof T["columns"] & string];Defined in: src/types/infer.ts:28
Union of column names where isNullable is false.
Type Parameters
| Type Parameter |
|---|
T extends HasColumnDefs |
NullableKeys
type NullableKeys<T> = { [K in keyof T["columns"] & string]: T["columns"][K] extends ColumnDef<infer _T, true, infer _R> ? K : never }[keyof T["columns"] & string];Defined in: src/types/infer.ts:21
Union of column names where isNullable is true.
Type Parameters
| Type Parameter |
|---|
T extends HasColumnDefs |
Params
type Params = Record<string, unknown>;Defined in: src/types/primitives.ts:5
A plain parameter object passed to executeBatch rows.
ReadonlyKeys
type ReadonlyKeys<T> = { [K in keyof T["columns"] & string]: T["columns"][K] extends ColumnDef<infer _T, infer _N, true> ? K : never }[keyof T["columns"] & string];Defined in: src/types/infer.ts:35
Union of column names where isReadonly is true.
Type Parameters
| Type Parameter |
|---|
T extends HasColumnDefs |
Row
type Row = Record<string, unknown>;Defined in: src/types/primitives.ts:2
A raw row returned by the database driver before any mapping.
RowMapper
type RowMapper<T> = (row) => T;Defined in: src/core/type-mapper.ts:8
A compiled function that maps a raw Row to a typed T.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
row | Row |
Returns
T
Severity
type Severity = "critical" | "high" | "medium" | "low";Defined in: src/sql/injection-detector.ts:3
TenantResolver
type TenantResolver<Names> = (tenantId) => Names;Defined in: src/connections/tenant-resolver.ts:4
A function that resolves a tenant ID to a connection name.
Type Parameters
| Type Parameter | Default type |
|---|---|
Names extends string | string |
Parameters
| Parameter | Type |
|---|---|
tenantId | string |
Returns
Names
Variables
col
const col: object;Defined in: src/types/col.ts:75
Column builder entry points — one per database type.
Type Declaration
| Name | Type | Defined in |
|---|---|---|
array() | <T>() => ColumnBuilder<T[], false, false> & ColumnDef<T[], false, false> | src/types/col.ts:92 |
bigint() | () => ColumnBuilder<number, false, false> & ColumnDef<number, false, false> | src/types/col.ts:77 |
blob() | () => ColumnBuilder<Buffer<ArrayBufferLike>, false, false> & ColumnDef<Buffer<ArrayBufferLike>, false, false> | src/types/col.ts:90 |
boolean() | () => ColumnBuilder<boolean, false, false> & ColumnDef<boolean, false, false> | src/types/col.ts:81 |
char() | (len) => ColumnBuilder<string, false, false> & ColumnDef<string, false, false> | src/types/col.ts:85 |
date() | () => ColumnBuilder<Date, false, false> & ColumnDef<Date, false, false> | src/types/col.ts:87 |
datetime() | () => ColumnBuilder<Date, false, false> & ColumnDef<Date, false, false> | src/types/col.ts:86 |
decimal() | (p?, _s?) => ColumnBuilder<number, false, false> & ColumnDef<number, false, false> | src/types/col.ts:80 |
float() | () => ColumnBuilder<number, false, false> & ColumnDef<number, false, false> | src/types/col.ts:79 |
int() | () => ColumnBuilder<number, false, false> & ColumnDef<number, false, false> | src/types/col.ts:76 |
json() | <T>() => ColumnBuilder<T, false, false> & ColumnDef<T, false, false> | src/types/col.ts:91 |
nvarchar() | (len) => ColumnBuilder<string, false, false> & ColumnDef<string, false, false> | src/types/col.ts:83 |
smallint() | () => ColumnBuilder<number, false, false> & ColumnDef<number, false, false> | src/types/col.ts:78 |
text() | () => ColumnBuilder<string, false, false> & ColumnDef<string, false, false> | src/types/col.ts:82 |
time() | () => ColumnBuilder<string, false, false> & ColumnDef<string, false, false> | src/types/col.ts:88 |
uuid() | () => ColumnBuilder<string, false, false> & ColumnDef<string, false, false> | src/types/col.ts:89 |
varchar() | (len) => ColumnBuilder<string, false, false> & ColumnDef<string, false, false> | src/types/col.ts:84 |
consoleLogger
const consoleLogger: SqunLogger;Defined in: src/logging/console-logger.ts:71
Development logger — colorised, human-readable, pretty-printed.
jsonLogger
const jsonLogger: SqunLogger;Defined in: src/logging/json-logger.ts:56
Production logger — structured JSON, one object per line, pino-compatible.
noopLogger
const noopLogger: SqunLogger;Defined in: src/logging/noop-logger.ts:6
Silent logger — does nothing. Used in test environments.
SQUN_ENV_VARS
const SQUN_ENV_VARS: object;Defined in: src/config/env-vars.ts:5
Every SQUN_* environment variable name used by the library. No magic strings — all env var access goes through this constant.
Type Declaration
| Name | Type | Default value | Defined in |
|---|---|---|---|
AZURE_CLIENT_ID | "SQUN_AZURE_CLIENT_ID" | "SQUN_AZURE_CLIENT_ID" | src/config/env-vars.ts:43 |
AZURE_CLIENT_SECRET | "SQUN_AZURE_CLIENT_SECRET" | "SQUN_AZURE_CLIENT_SECRET" | src/config/env-vars.ts:44 |
AZURE_MANAGED_IDENTITY | "SQUN_AZURE_MANAGED_IDENTITY" | "SQUN_AZURE_MANAGED_IDENTITY" | src/config/env-vars.ts:45 |
AZURE_TENANT_ID | "SQUN_AZURE_TENANT_ID" | "SQUN_AZURE_TENANT_ID" | src/config/env-vars.ts:42 |
CACHE_MAX_AGE_MS | "SQUN_CACHE_MAX_AGE_MS" | "SQUN_CACHE_MAX_AGE_MS" | src/config/env-vars.ts:64 |
CACHE_MAX_SIZE | "SQUN_CACHE_MAX_SIZE" | "SQUN_CACHE_MAX_SIZE" | src/config/env-vars.ts:62 |
CACHE_REAPER_MS | "SQUN_CACHE_REAPER_MS" | "SQUN_CACHE_REAPER_MS" | src/config/env-vars.ts:65 |
CACHE_TTL_MS | "SQUN_CACHE_TTL_MS" | "SQUN_CACHE_TTL_MS" | src/config/env-vars.ts:63 |
CONN_PREFIX | "SQUN_CONN_" | "SQUN_CONN_" | src/config/env-vars.ts:69 |
DEFAULT_CONNECTION | "SQUN_DEFAULT_CONNECTION" | "SQUN_DEFAULT_CONNECTION" | src/config/env-vars.ts:68 |
ENV | "SQUN_ENV" | "SQUN_ENV" | src/config/env-vars.ts:7 |
LOG_LEVEL | "SQUN_LOG_LEVEL" | "SQUN_LOG_LEVEL" | src/config/env-vars.ts:58 |
LOG_SLOW_QUERY_MS | "SQUN_LOG_SLOW_QUERY_MS" | "SQUN_LOG_SLOW_QUERY_MS" | src/config/env-vars.ts:59 |
MSSQL_AUTH_TYPE | "SQUN_MSSQL_AUTH_TYPE" | "SQUN_MSSQL_AUTH_TYPE" | src/config/env-vars.ts:34 |
MSSQL_DATABASE | "SQUN_MSSQL_DATABASE" | "SQUN_MSSQL_DATABASE" | src/config/env-vars.ts:31 |
MSSQL_DOMAIN | "SQUN_MSSQL_DOMAIN" | "SQUN_MSSQL_DOMAIN" | src/config/env-vars.ts:35 |
MSSQL_HOST | "SQUN_MSSQL_HOST" | "SQUN_MSSQL_HOST" | src/config/env-vars.ts:29 |
MSSQL_PASSWORD | "SQUN_MSSQL_PASSWORD" | "SQUN_MSSQL_PASSWORD" | src/config/env-vars.ts:33 |
MSSQL_PORT | "SQUN_MSSQL_PORT" | "SQUN_MSSQL_PORT" | src/config/env-vars.ts:30 |
MSSQL_UPN | "SQUN_MSSQL_UPN" | "SQUN_MSSQL_UPN" | src/config/env-vars.ts:36 |
MSSQL_URL | "SQUN_MSSQL_URL" | "SQUN_MSSQL_URL" | src/config/env-vars.ts:28 |
MSSQL_USER | "SQUN_MSSQL_USER" | "SQUN_MSSQL_USER" | src/config/env-vars.ts:32 |
MYSQL_DATABASE | "SQUN_MYSQL_DATABASE" | "SQUN_MYSQL_DATABASE" | src/config/env-vars.ts:23 |
MYSQL_HOST | "SQUN_MYSQL_HOST" | "SQUN_MYSQL_HOST" | src/config/env-vars.ts:21 |
MYSQL_PASSWORD | "SQUN_MYSQL_PASSWORD" | "SQUN_MYSQL_PASSWORD" | src/config/env-vars.ts:25 |
MYSQL_PORT | "SQUN_MYSQL_PORT" | "SQUN_MYSQL_PORT" | src/config/env-vars.ts:22 |
MYSQL_URL | "SQUN_MYSQL_URL" | "SQUN_MYSQL_URL" | src/config/env-vars.ts:20 |
MYSQL_USER | "SQUN_MYSQL_USER" | "SQUN_MYSQL_USER" | src/config/env-vars.ts:24 |
PG_DATABASE | "SQUN_PG_DATABASE" | "SQUN_PG_DATABASE" | src/config/env-vars.ts:13 |
PG_HOST | "SQUN_PG_HOST" | "SQUN_PG_HOST" | src/config/env-vars.ts:11 |
PG_PASSWORD | "SQUN_PG_PASSWORD" | "SQUN_PG_PASSWORD" | src/config/env-vars.ts:15 |
PG_PORT | "SQUN_PG_PORT" | "SQUN_PG_PORT" | src/config/env-vars.ts:12 |
PG_SSL | "SQUN_PG_SSL" | "SQUN_PG_SSL" | src/config/env-vars.ts:16 |
PG_TVP_COPY_THRESHOLD | "SQUN_PG_TVP_COPY_THRESHOLD" | "SQUN_PG_TVP_COPY_THRESHOLD" | src/config/env-vars.ts:17 |
PG_URL | "SQUN_PG_URL" | "SQUN_PG_URL" | src/config/env-vars.ts:10 |
PG_USER | "SQUN_PG_USER" | "SQUN_PG_USER" | src/config/env-vars.ts:14 |
POOL_MAX | "SQUN_POOL_MAX" | "SQUN_POOL_MAX" | src/config/env-vars.ts:49 |
POOL_MIN | "SQUN_POOL_MIN" | "SQUN_POOL_MIN" | src/config/env-vars.ts:48 |
SQLITE_FILE | "SQUN_SQLITE_FILE" | "SQUN_SQLITE_FILE" | src/config/env-vars.ts:39 |
TIMEOUT_ACQUIRE | "SQUN_TIMEOUT_ACQUIRE" | "SQUN_TIMEOUT_ACQUIRE" | src/config/env-vars.ts:55 |
TIMEOUT_CONNECT | "SQUN_TIMEOUT_CONNECT" | "SQUN_TIMEOUT_CONNECT" | src/config/env-vars.ts:54 |
TIMEOUT_QUERY | "SQUN_TIMEOUT_QUERY" | "SQUN_TIMEOUT_QUERY" | src/config/env-vars.ts:52 |
TIMEOUT_TX | "SQUN_TIMEOUT_TX" | "SQUN_TIMEOUT_TX" | src/config/env-vars.ts:53 |
Functions
assertWritable()
function assertWritable(
connection,
operation,
sql?): boolean;Defined in: src/readonly/guard.ts:19
Throws ReadonlyViolationError if a write operation is attempted on a readonly connection. Called before any SQL is sent to the adapter.
In "strict" mode (default): throws immediately. In "warn" mode: returns false to signal a warning should be logged, but allows the write.
Parameters
| Parameter | Type |
|---|---|
connection | ReadonlyConnection |
operation | string |
sql? | string |
Returns
boolean
compileMapper()
function compileMapper<T>(
schema,
registry?,
strict?): RowMapper<T>;Defined in: src/core/type-mapper.ts:30
Compiles a mapper function from a table schema at defineTable() time. All branching is resolved once during compilation — per-row mapping has zero runtime type inspection.
In strict mode (default), throws MappingError for null on notNull columns and for unknown columns in the result. In lenient mode, warns and continues.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Default value |
|---|---|---|
schema | SchemaLike | undefined |
registry | TypeHandlerRegistry | ... |
strict | boolean | true |
Returns
RowMapper<T>
concurrent()
function concurrent<T>(...queries): Promise<T>;Defined in: src/async/concurrent.ts:6
Runs multiple promises concurrently and returns a typed tuple of results. Wraps Promise.all with correct TypeScript tuple inference so callers get typed results per position rather than (T1 | T2 | ...)[].
Type Parameters
| Type Parameter |
|---|
T extends readonly unknown[] |
Parameters
| Parameter | Type |
|---|---|
...queries | { [K in string | number | symbol]: Promise<T[K]> } |
Returns
Promise<T>
createConnection()
function createConnection(adapter, userConfig?): Database;Defined in: src/db.ts:56
Single connection entry point. Calls validateProductionConfig() synchronously — app never starts in invalid state.
Parameters
| Parameter | Type |
|---|---|
adapter | IDbAdapter |
userConfig | Partial<SqunConfig> |
Returns
createConnections()
function createConnections<Config, Names>(multiConfig): MultiDatabase<Names>;Defined in: src/db.ts:209
Multi-connection entry point. Infers Names = keyof Config["connections"] & string. Validates all connections together at startup.
Type Parameters
| Type Parameter | Default type |
|---|---|
Config extends MultiDbConfig | - |
Names extends string | keyof Config["connections"] & string |
Parameters
| Parameter | Type |
|---|---|
multiConfig | Config |
Returns
MultiDatabase<Names>
createRouter()
function createRouter(config): RouterResult;Defined in: src/readonly/router.ts:28
Convenience wrapper — one writable primary, one read replica. Returns the config shape that createConnections() expects. Not a separate code path — just builds the standard multi-connection config.
Parameters
| Parameter | Type |
|---|---|
config | RouterConfig |
Returns
RouterResult
defineMapper()
function defineMapper<T>(
cls,
schema,
factoryOrOptions?): MapperFn<T>;Defined in: src/mapping/define-mapper.ts:26
Registers a class mapper globally. Any subsequent queryAs(cls, ...) resolves it.
- No factory argument + strategy "property" (default): property injection
- No factory argument + strategy "constructor": constructor args in column order
- No factory argument + strategy "static": calls cls.fromDb(row)
- Factory function provided: uses it directly
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
cls | Constructor<T> |
schema | SchemaLike |
factoryOrOptions? | DefineMapperOptions | ((row) => T) |
Returns
MapperFn<T>
defineTable()
function defineTable<Name, Columns>(tableName, columns): TableDefinition<Name, Columns>;Defined in: src/types/table.ts:24
Defines a table schema for use with Squn's type system.
The returned definition is used by InferModel, InferInsert, InferUpdate, and all query methods that accept a table reference. It carries the table name and the full column map at the type level.
Type Parameters
| Type Parameter |
|---|
Name extends string |
Columns extends ColumnMap |
Parameters
| Parameter | Type |
|---|---|
tableName | Name |
columns | Columns |
Returns
TableDefinition<Name, Columns>
detectInjection()
function detectInjection(text): DetectionResult;Defined in: src/sql/injection-detector.ts:52
Checks text against all SQUN_REGEX injection patterns. Returns the first match found (ordered by severity: critical → low).
Parameters
| Parameter | Type |
|---|---|
text | string |
Returns
Email()
function Email(_target, context): void;Defined in: src/mapping/decorators/validate.ts:33
Validates that a string property matches an email format.
Parameters
| Parameter | Type |
|---|---|
_target | undefined |
context | ClassFieldDecoratorContext |
Returns
void
Entity()
function Entity(schema): <T>(target, _context) => T;Defined in: src/mapping/decorators/entity.ts:15
@Entity(schema) decorator — registers the class with propertyInjection strategy. Equivalent to defineMapper(cls, schema) with strategy: "property". Requires TC39 stage 3 decorators (TypeScript 5.0+ with target: "ESNext").
Parameters
| Parameter | Type |
|---|---|
schema | SchemaLike |
Returns
<T>(target, _context) => T
execProc()
function execProc<T, OutputParams>(
adapter,
procName,
params?): Promise<{
output: OutputParams;
rows: T[];
}>;Defined in: src/api/proc.ts:18
Stored procedure with OUTPUT params.
Type Parameters
| Type Parameter |
|---|
T |
OutputParams extends Record<string, unknown> |
Parameters
| Parameter | Type |
|---|---|
adapter | IDbAdapter |
procName | string |
params? | Record<string, unknown> |
Returns
Promise<{ output: OutputParams; rows: T[]; }>
execute()
function execute(adapter, fragment): Promise<{
rowsAffected: number;
}>;Defined in: src/api/execute.ts:6
Returns { rowsAffected }.
Parameters
| Parameter | Type |
|---|---|
adapter | IDbAdapter |
fragment | SqlFragment |
Returns
Promise<{ rowsAffected: number; }>
executeBatch()
function executeBatch(
adapter,
fragment,
rows,
options?): Promise<{
rowsAffected: number;
}>;Defined in: src/api/execute.ts:14
Single prepared statement executed once per row via adapter-native batch.
Parameters
| Parameter | Type |
|---|---|
adapter | IDbAdapter |
fragment | SqlFragment |
rows | readonly Record<string, unknown>[] |
options? | { strategy?: "prepared-loop" | "copy" | "bulk-load"; } |
options.strategy? | "prepared-loop" | "copy" | "bulk-load" |
Returns
Promise<{ rowsAffected: number; }>
formatSql()
function formatSql(sql): string;Defined in: src/sql/formatter.ts:72
Normalises SQL for cache keys and log output.
- Collapses whitespace to single spaces
- Uppercases SQL keywords
- Trims leading/trailing whitespace
Parameters
| Parameter | Type |
|---|---|
sql | string |
Returns
string
forTenant()
function forTenant<Names>(
registry,
resolver,
tenantId): Names;Defined in: src/connections/tenant-resolver.ts:10
Resolves a tenant ID to an adapter via the registry. The resolver function is called per-query — it can use caching internally.
Type Parameters
| Type Parameter |
|---|
Names extends string |
Parameters
| Parameter | Type |
|---|---|
registry | ConnectionRegistry<Names> |
resolver | TenantResolver<Names> |
tenantId | string |
Returns
Names
getValidationRules()
function getValidationRules(target): Map<string, ValidationRule[]>;Defined in: src/mapping/decorators/validate.ts:69
Retrieves all validation rules for a class instance's prototype.
Parameters
| Parameter | Type |
|---|---|
target | object |
Returns
Map<string, ValidationRule[]>
insert()
function insert(
adapter,
tableName,
columnNames,
data): Promise<{
rowsAffected: number;
}>;Defined in: src/api/execute.ts:26
Typed insert — data checked against InferInsert at the type level.
Parameters
| Parameter | Type |
|---|---|
adapter | IDbAdapter |
tableName | string |
columnNames | readonly string[] |
data | Record<string, unknown> |
Returns
Promise<{ rowsAffected: number; }>
isDeadlock()
function isDeadlock(err, adapterType): boolean;Defined in: src/transaction/deadlock.ts:10
Detects whether an error is a deadlock for the given adapter. MSSQL: error 1205, PostgreSQL: code 40P01, MySQL: 1213, SQLite: SQLITE_BUSY.
Parameters
| Parameter | Type |
|---|---|
err | SqunError |
adapterType | AdapterType |
Returns
boolean
isSqlFragment()
function isSqlFragment(x): x is SqlFragment;Defined in: src/sql/fragment.ts:17
Type guard for SqlFragment.
Parameters
| Parameter | Type |
|---|---|
x | unknown |
Returns
x is SqlFragment
isTvpValue()
function isTvpValue(x): x is TvpValue;Defined in: src/sql/fragment.ts:22
Type guard for TvpValue.
Parameters
| Parameter | Type |
|---|---|
x | unknown |
Returns
x is TvpValue
maskConnectionString()
function maskConnectionString(s): string;Defined in: src/auth/mask.ts:11
Strips passwords from both URL format and key=value connection strings. Passwords must never appear in any log output.
Parameters
| Parameter | Type |
|---|---|
s | string |
Returns
string
maskUrl()
function maskUrl(url): string;Defined in: src/config/url-validator.ts:35
Masks the password portion of a connection URL for safe logging. postgresql://user:s3cret@host → postgresql://user:****@host
Parameters
| Parameter | Type |
|---|---|
url | string |
Returns
string
Max()
function Max(value): (_target, context) => void;Defined in: src/mapping/decorators/validate.ts:56
Validates that a numeric property is <= the specified maximum.
Parameters
| Parameter | Type |
|---|---|
value | number |
Returns
(_target, context) => void
Min()
function Min(value): (_target, context) => void;Defined in: src/mapping/decorators/validate.ts:43
Validates that a numeric property is >= the specified minimum.
Parameters
| Parameter | Type |
|---|---|
value | number |
Returns
(_target, context) => void
NotNull()
function NotNull(_target, context): void;Defined in: src/mapping/decorators/validate.ts:23
Marks a property as required — validates that the value is not null or undefined.
Parameters
| Parameter | Type |
|---|---|
_target | undefined |
context | ClassFieldDecoratorContext |
Returns
void
prepare()
function prepare<T, P>(
adapter,
fragment,
paramNames): PreparedQuery<T, P>;Defined in: src/api/prepared.ts:158
Creates a PreparedQuery. Call this once at startup or module scope.
The fragment's params are inspected to extract the param name order. At call time, only the ParamBuffer is filled — no parsing, no validation, no hashing, no array spreading.
Type Parameters
| Type Parameter | Default type |
|---|---|
T | - |
P extends Record<string, unknown> | Record<string, never> |
Parameters
| Parameter | Type |
|---|---|
adapter | IDbAdapter |
fragment | SqlFragment |
paramNames | readonly string[] |
Returns
PreparedQuery<T, P>
Example
const findUserById = prepare<User, { id: number }>(
adapter,
sql`SELECT * FROM users WHERE id = ${0}`, // placeholder value, not used
["id"],
);
// Hot path — only param binding + adapter call
const user = await findUserById.first({ id: 42 });query()
function query<T>(adapter, fragment): Promise<T[]>;Defined in: src/api/query.ts:9
Returns T[] — zero or more rows.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
adapter | IDbAdapter |
fragment | SqlFragment |
Returns
Promise<T[]>
queryBuilder()
Call Signature
function queryBuilder(tableName): QueryBuilder<never>;Defined in: src/api/query-builder.ts:180
Creates a query builder for a table.
Parameters
| Parameter | Type |
|---|---|
tableName | string |
Returns
QueryBuilder<never>
Call Signature
function queryBuilder(schema): QueryBuilder<never>;Defined in: src/api/query-builder.ts:181
Creates a query builder for a table.
Parameters
| Parameter | Type |
|---|---|
schema | { tableName: string; } |
schema.tableName | string |
Returns
QueryBuilder<never>
queryFirst()
function queryFirst<T>(adapter, fragment): Promise<T | null>;Defined in: src/api/query.ts:15
Returns T | null — first row or null.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
adapter | IDbAdapter |
fragment | SqlFragment |
Returns
Promise<T | null>
queryMultiple()
function queryMultiple(adapter, fragment): Promise<Row[][]>;Defined in: src/api/query.ts:81
Returns multiple result sets.
Parameters
| Parameter | Type |
|---|---|
adapter | IDbAdapter |
fragment | SqlFragment |
Returns
Promise<Row[][]>
queryProc()
function queryProc<T>(
adapter,
procName,
params?): Promise<T[]>;Defined in: src/api/proc.ts:4
Stored procedure → T[].
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
adapter | IDbAdapter |
procName | string |
params? | Record<string, unknown> |
Returns
Promise<T[]>
queryScalar()
function queryScalar<T>(adapter, fragment): Promise<T>;Defined in: src/api/query.ts:60
Returns T — first column of first row.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
adapter | IDbAdapter |
fragment | SqlFragment |
Returns
Promise<T>
querySingle()
Call Signature
function querySingle<T>(
adapter,
fragment,
strict?): Promise<T>;Defined in: src/api/query.ts:22
Returns T — exactly one row, throws on 0 or >1.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
adapter | IDbAdapter |
fragment | SqlFragment |
strict? | true |
Returns
Promise<T>
Call Signature
function querySingle<T>(
adapter,
fragment,
strict): Promise<T | null>;Defined in: src/api/query.ts:28
Returns T | null — first row or null (no error on empty result). Throws on >1 row.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
adapter | IDbAdapter |
fragment | SqlFragment |
strict | false |
Returns
Promise<T | null>
Readonly()
function Readonly(): <T>(target, _context) => T;Defined in: src/readonly/freeze.ts:8
@Readonly() class decorator — freezes instances after construction. The returned instance is a Readonly<T> at the TypeScript level and Object.freeze()'d at runtime.
Requires TC39 stage 3 decorators (TypeScript 5.0+ with target: "ESNext").
Returns
<T>(target, _context) => T
resolveConfig()
function resolveConfig(userConfig, env?): SqunConfig;Defined in: src/config/resolve.ts:63
Resolves the final SqunConfig by detecting the environment and deep-merging the user's partial config on top of the matching preset.
Parameters
| Parameter | Type |
|---|---|
userConfig | Partial<SqunConfig> |
env? | string |
Returns
resolveConnection()
function resolveConnection<Names>(
registry,
optionsConnection?,
useScope?,
builderConnection?): IDbAdapter;Defined in: src/connections/resolve-connection.ts:10
Resolves the connection to use following the full precedence chain: options.connection → .use() scope → queryBuilder.connection() → default.
Throws ConnectionError(CONN_UNKNOWN) if the name is not found — handled by registry.get().
Type Parameters
| Type Parameter |
|---|
Names extends string |
Parameters
| Parameter | Type |
|---|---|
registry | ConnectionRegistry<Names> |
optionsConnection? | Names |
useScope? | Names |
builderConnection? | Names |
Returns
resolveTimeout()
function resolveTimeout(
callTimeout,
txClock,
globalConfig,
operation): number | null;Defined in: src/async/timeout.ts:20
Resolves the effective timeout for a single database operation.
Precedence chain (PRD 12.2): per-call option → transaction budget remaining → operation global → null
The transaction budget acts as a hard ceiling — even if the call-site requests a longer timeout, it is capped to whatever budget the enclosing transaction has remaining.
Parameters
| Parameter | Type |
|---|---|
callTimeout | number | null | undefined |
txClock | Clock | undefined |
globalConfig | TimeoutConfig |
operation | keyof TimeoutConfig |
Returns
number | null
retryWithDeadlockBackoff()
function retryWithDeadlockBackoff<T>(
fn,
adapterType,
options): Promise<T>;Defined in: src/transaction/deadlock.ts:37
Retries a function on deadlock with exponential backoff + random jitter.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
fn | () => Promise<T> |
adapterType | AdapterType |
options | RetryOptions |
Returns
Promise<T>
runAtomically()
function runAtomically<T>(
adapter,
fn,
options?): Promise<T>;Defined in: src/transaction/atomic.ts:46
Runs a function inside a BEGIN/COMMIT block. Nesting is forbidden — throws AtomicNestingError. retryOnError only retries ConnectionError, never QueryError or MappingError.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
adapter | IDbAdapter |
fn | (executor) => Promise<T> |
options | AtomicBlockOptions |
Returns
Promise<T>
splitAndMap()
function splitAndMap(
rows,
splitOn,
mappers): unknown[];Defined in: src/mapping/nested-mapper.ts:9
Splits JOIN result rows at splitOn column boundaries and maps into nested objects. Deduplicates by the first column (primary key) of each segment. Left join sides become null when the splitOn column value is null.
Parameters
| Parameter | Type |
|---|---|
rows | Row[] |
splitOn | string[] |
mappers | MapperFn<unknown>[] |
Returns
unknown[]
sql()
function sql(strings, ...values): SqlFragment;Defined in: src/sql/tag.ts:23
Tagged template literal for SQL. Three interpolation paths:
- Scalar → appended to params[], placeholder inserted in text
- Nested SqlFragment → text merged inline, params spliced in order, placeholders renumbered
- TvpValue → extracted to tvpValues[], TVP_N sentinel in text
Parameters
| Parameter | Type |
|---|---|
strings | TemplateStringsArray |
...values | unknown[] |
Returns
sqlIdentifier()
function sqlIdentifier(name): SqlFragment;Defined in: src/sql/helpers.ts:103
Validates and double-quotes a SQL identifier. Max 128 chars.
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
sqlIf()
function sqlIf(condition, fragment): SqlFragment;Defined in: src/sql/helpers.ts:8
Includes fragment only if condition is true. Returns empty fragment otherwise.
Parameters
| Parameter | Type |
|---|---|
condition | boolean |
fragment | SqlFragment |
Returns
sqlJoin()
function sqlJoin(fragments, separator?): SqlFragment;Defined in: src/sql/helpers.ts:14
Joins multiple fragments with a separator string.
Parameters
| Parameter | Type | Default value |
|---|---|---|
fragments | readonly SqlFragment[] | undefined |
separator | string | ", " |
Returns
sqlQualifiedIdentifier()
function sqlQualifiedIdentifier(schema, table): SqlFragment;Defined in: src/sql/helpers.ts:128
Validates and double-quotes a qualified identifier: "schema"."table".
Parameters
| Parameter | Type |
|---|---|
schema | string |
table | string |
Returns
sqlRaw()
function sqlRaw(text): SqlFragment;Defined in: src/sql/helpers.ts:42
Raw SQL escape hatch. Injects text directly — no parameterization. Throws SecurityError on critical/high injection patterns.
Parameters
| Parameter | Type |
|---|---|
text | string |
Returns
stream()
function stream<T>(
adapter,
fragment,
batchSize?): AsyncIterableIterator<T>;Defined in: src/api/query.ts:86
AsyncIterableIterator<T> — streaming cursor with configurable batch size.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Default value |
|---|---|---|
adapter | IDbAdapter | undefined |
fragment | SqlFragment | undefined |
batchSize | number | 100 |
Returns
AsyncIterableIterator<T>
tvp()
function tvp<T>(tableType, rows): TvpValue;Defined in: src/core/tvp/tvp-builder.ts:11
Builds a TvpValue from a TableType and rows. Validates every row has exactly the columns defined in tableType.schema. Throws ValidationError(TVP_SCHEMA_MISMATCH) on column mismatch.
Type Parameters
| Type Parameter |
|---|
T extends TableType<Record<string, string>> |
Parameters
| Parameter | Type |
|---|---|
tableType | T |
rows | InferTableType<T>[] |
Returns
TvpValue
update()
function update(
adapter,
tableName,
data,
pkColumn,
pkValue): Promise<{
rowsAffected: number;
}>;Defined in: src/api/execute.ts:40
Typed update — data checked against InferUpdate at the type level.
Parameters
| Parameter | Type |
|---|---|
adapter | IDbAdapter |
tableName | string |
data | Record<string, unknown> |
pkColumn | string |
pkValue | unknown |
Returns
Promise<{ rowsAffected: number; }>
validateAuth()
function validateAuth(config): void;Defined in: src/auth/validate-auth.ts:33
Validates an AuthConfig using the exact regex patterns from PRD section 14. Throws AuthError on any violation.
Parameters
| Parameter | Type |
|---|---|
config | AuthConfig |
Returns
void
validateConfig()
function validateConfig(config): void;Defined in: src/config/validate.ts:9
General config sanity checks that apply regardless of environment. Throws SqunConfigError on invalid values.
Parameters
| Parameter | Type |
|---|---|
config | SqunConfig |
Returns
void
validateProductionConfig()
function validateProductionConfig(
config,
adapter,
connection,
logger): void;Defined in: src/config/validate-production.ts:60
Validates a connection config for production. Throws SqunConfigError listing ALL missing fields in one error. Warns (does not throw) for localhost, disabled SSL, and superuser connections.
Parameters
| Parameter | Type |
|---|---|
config | SqunConfig |
adapter | AdapterType |
connection | ConnectionConfig |
logger | SqunLogger |
Returns
void
validateSql()
function validateSql(fragment, options?): void;Defined in: src/sql/validator.ts:19
Validates a SqlFragment before execution. Checks: placeholder/param count, unbalanced parens, unresolved TVP sentinels, multiple statements, write on readonly.
Parameters
| Parameter | Type |
|---|---|
fragment | SqlFragment |
options | ValidateOptions |
Returns
void
validateUrl()
function validateUrl(url): void;Defined in: src/config/url-validator.ts:11
Validates that a connection URL has a recognisable scheme and structure. Throws SqunConfigError if the URL is malformed.
Parameters
| Parameter | Type |
|---|---|
url | string |
Returns
void
withTenant()
function withTenant<Names>(resolver, tenantId): Names;Defined in: src/connections/tenant-resolver.ts:25
Creates a scoped connection name from a tenant ID. For use with QueryOptions.connection or .use().
Type Parameters
| Type Parameter |
|---|
Names extends string |
Parameters
| Parameter | Type |
|---|---|
resolver | TenantResolver<Names> |
tenantId | string |
Returns
Names
withTimeout()
function withTimeout<T>(
fn,
ms,
operation?): Promise<T>;Defined in: src/async/timeout.ts:46
Runs an async function with a timeout deadline. Uses AbortController for cancellation. Timer is always cleared in a finally block.
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type | Default value |
|---|---|---|
fn | (signal) => Promise<T> | undefined |
ms | number | undefined |
operation | string | "query" |
Returns
Promise<T>