Skip to content

Class: Attachment ​

Defined in: packages/core/src/api/attachment.ts:29

An open database attachment. Obtain via connect() or createDatabase().

Properties ​

PropertyModifierTypeDefined in
optionsreadonlyResolvedOptionspackages/core/src/api/attachment.ts:45

Accessors ​

dbHandle ​

Get Signature ​

ts
get dbHandle(): number;

Defined in: packages/core/src/api/attachment.ts:66

Server-side database handle on the current connection.

Returns ​

number


generation ​

Get Signature ​

ts
get generation(): number;

Defined in: packages/core/src/api/attachment.ts:80

Reconnect epoch: 0 until the first reconnect(), +1 per reconnect. Transactions, prepared statements and lazy blobs remember the generation they were created in and throw once it moves past them.

Returns ​

number


handshake ​

Get Signature ​

ts
get handshake(): HandshakeResult;

Defined in: packages/core/src/api/attachment.ts:61

Handshake of the current wire connection.

Returns ​

HandshakeResult


isAlive ​

Get Signature ​

ts
get isAlive(): boolean;

Defined in: packages/core/src/api/attachment.ts:427

True while the connection is usable (socket open, not detached).

Returns ​

boolean


protocolVersion ​

Get Signature ​

ts
get protocolVersion(): number;

Defined in: packages/core/src/api/attachment.ts:202

Negotiated protocol version (13 = FB3 … 16 = FB4/5).

Returns ​

number


roundTrips ​

Get Signature ​

ts
get roundTrips(): number;

Defined in: packages/core/src/api/attachment.ts:110

Packet flushes performed on this connection so far (≈ round trips). Cumulative across reconnect(). Useful for performance assertions and diagnostics.

Returns ​

number


wire ​

Get Signature ​

ts
get wire(): WireConnection;

Defined in: packages/core/src/api/attachment.ts:56

Wire connection currently in use (swapped by reconnect()).

Returns ​

WireConnection


wireCompressed ​

Get Signature ​

ts
get wireCompressed(): boolean;

Defined in: packages/core/src/api/attachment.ts:215

Returns ​

boolean


wireCryptPlugin ​

Get Signature ​

ts
get wireCryptPlugin(): string | null;

Defined in: packages/core/src/api/attachment.ts:211

Negotiated wire-crypt plugin (Arc4/ChaCha/ChaCha64), or null.

Returns ​

string | null


wireEncrypted ​

Get Signature ​

ts
get wireEncrypted(): boolean;

Defined in: packages/core/src/api/attachment.ts:206

Returns ​

boolean

Methods ​

[asyncDispose]() ​

ts
asyncDispose: Promise<void>;

Defined in: packages/core/src/api/attachment.ts:458

await using db = await connect(…) → disconnects at scope exit.

Returns ​

Promise<void>


clearStatementCache() ​

ts
clearStatementCache(): Promise<void>;

Defined in: packages/core/src/api/attachment.ts:446

Drop every cached prepared statement and release the server handles NOW (the deferred op_free_statements ride one op_ping round trip). Prepared statements pin table metadata, so run this before DDL like recreate table — otherwise it fails with "object ... is in use".

Returns ​

Promise<void>


disconnect() ​

ts
disconnect(): Promise<void>;

Defined in: packages/core/src/api/attachment.ts:462

Returns ​

Promise<void>


dropDatabase() ​

ts
dropDatabase(): Promise<void>;

Defined in: packages/core/src/api/attachment.ts:478

Drops the attached database file on the server, then closes.

Returns ​

Promise<void>


events() ​

ts
events(names): Promise<EventListener>;

Defined in: packages/core/src/api/attachment.ts:393

Subscribe to Firebird POST_EVENT notifications. Returns a started EventListener (an EventEmitter): .on(name, count => …) per event, .on('post', (name, count) => …) for any, .on('error', …). Call .close() when done. Uses a separate async channel, so it does not block queries on this connection.

ts
const ev = await db.events(['order_placed']);
ev.on('order_placed', (count) => refresh());

Parameters ​

ParameterType
namesstring[]

Returns ​

Promise<EventListener>


execute() ​

ts
execute(
   sql, 
   params?, 
options?): Promise<number>;

Defined in: packages/core/src/api/attachment.ts:320

Run a single statement in its own transaction; returns affected count.

Parameters ​

ParameterTypeDefault value
sqlstringundefined
paramsQueryParams[]
options?QueryOptionsundefined

Returns ​

Promise<number>


executeBatch() ​

ts
executeBatch(
   sql, 
   rows, 
options?): Promise<BatchResult>;

Defined in: packages/core/src/api/attachment.ts:341

Run one DML statement against MANY parameter rows in bulk via the wire batch API (Firebird 4+): all rows travel to the server in one round trip per ~8 MiB cycle, instead of one per row. Runs in its own transaction — committed on success (with continueOnError, the successful rows).

Rows are positional arrays or @name objects; the connection must not be used for other statements while an async rows source is consumed.

ts
const r = await db.executeBatch(
  'insert into orders (id, total) values (?, ?)',
  [[1, '9.99'], [2, '15.00'], [3, '7.50']],
);
r.rowsAffected; // 3

Parameters ​

ParameterType
sqlstring
rowsBatchRows
options?BatchOptions

Returns ​

Promise<BatchResult>


executeScript() ​

ts
executeScript(script, options?): Promise<ScriptExecutionResult>;

Defined in: packages/core/src/api/attachment.ts:377

Parse and execute a multi-statement Firebird script (handles SET TERM, PSQL bodies, comments, strings). See ExecuteScriptOptions for transaction scoping and error handling.

Parameters ​

ParameterType
scriptstring
options?ExecuteScriptOptions

Returns ​

Promise<ScriptExecutionResult>


ping() ​

ts
ping(): Promise<void>;

Defined in: packages/core/src/api/attachment.ts:432

Cheap liveness check via op_ping (one round trip).

Returns ​

Promise<void>


prepare() ​

ts
prepare(sql): Promise<PreparedStatement>;

Defined in: packages/core/src/api/attachment.ts:272

Prepare a statement for repeated execution (pinned outside the LRU cache). Close it when done.

Parameters ​

ParameterType
sqlstring

Returns ​

Promise<PreparedStatement>


query() ​

ts
query<T>(
   sql, 
   params?, 
options?): Promise<T[]>;

Defined in: packages/core/src/api/attachment.ts:255

Run a single statement in its own transaction and return the rows. Type rows via the generic: db.query<{ ID: number }>('select id from t'). (Compile-time shaping only — no runtime validation.)

Type Parameters ​

Type ParameterDefault type
TRow

Parameters ​

ParameterTypeDefault value
sqlstringundefined
paramsQueryParams[]
options?QueryOptionsundefined

Returns ​

Promise<T[]>


queryOne() ​

ts
queryOne<T>(
   sql, 
   params?, 
options?): Promise<T | undefined>;

Defined in: packages/core/src/api/attachment.ts:264

Run a statement and return the FIRST row, or undefined when the result is empty. The whole result set is still fetched — put FIRST 1 (or a unique predicate) in the SQL when the query could match many rows.

Type Parameters ​

Type ParameterDefault type
TRow

Parameters ​

ParameterTypeDefault value
sqlstringundefined
paramsQueryParams[]
options?QueryOptionsundefined

Returns ​

Promise<T | undefined>


queryStream() ​

ts
queryStream<T>(
   sql, 
   params?, 
options?): AsyncGenerator<T>;

Defined in: packages/core/src/api/attachment.ts:405

Type Parameters ​

Type ParameterDefault type
TRow

Parameters ​

ParameterTypeDefault value
sqlstringundefined
paramsQueryParams[]
options?QueryOptionsundefined

Returns ​

AsyncGenerator<T>


reconnect() ​

ts
reconnect(): Promise<void>;

Defined in: packages/core/src/api/attachment.ts:178

Tear down the wire connection and re-attach to the same database with the same options — on the SAME Attachment object, so every holder of the reference (a pool, a script executor) keeps working. Everything created before the reconnect is dead: Transactions, PreparedStatements, lazy Blob handles and event listeners throw a clear "attachment was reconnected" error when used (event listeners get an 'error' event). The statement cache and inline-blob cache start fresh; roundTrips keeps counting cumulatively.

If establishing the new connection fails, the attachment is left closed (isAlive is false) but not detached — reconnect() can be retried.

Returns ​

Promise<void>


run() ​

ts
run<T>(
   sql, 
   params?, 
options?): Promise<QueryResult<T>>;

Defined in: packages/core/src/api/attachment.ts:294

Run a single statement in its own transaction; returns rows + count.

Type Parameters ​

Type ParameterDefault type
TRow

Parameters ​

ParameterTypeDefault value
sqlstringundefined
paramsQueryParams[]
options?QueryOptionsundefined

Returns ​

Promise<QueryResult<T>>


startTransaction() ​

ts
startTransaction(options?): Promise<Transaction>;

Defined in: packages/core/src/api/attachment.ts:223

Start an explicit transaction. Options merge field-by-field over the connection's defaultTransaction (see FirebirdConnectionOptions).

Parameters ​

ParameterType
options?TransactionOptions

Returns ​

Promise<Transaction>


transaction() ​

ts
transaction<T>(fn, options?): Promise<T>;

Defined in: packages/core/src/api/attachment.ts:232

Run fn inside a transaction: commits on success, rolls back on error.

Type Parameters ​

Type Parameter
T

Parameters ​

ParameterType
fn(tx) => Promise<T>
options?TransactionOptions

Returns ​

Promise<T>


open() ​

ts
static open(raw, mode?): Promise<Attachment>;

Defined in: packages/core/src/api/attachment.ts:121

Parameters ​

ParameterTypeDefault value
rawConnectInputundefined
mode"create" | "attach"'attach'

Returns ​

Promise<Attachment>

MIT Licensed. Contains data derived from the Firebird project under IDPL/IPL.