detachDb Method
Detach the attached file from this connection. The attached file is closed and its schemas are unregistered.
detachDb(alias: string): void
@note There are some reserve tablespace names that cannot be used. They are 'main', 'schema_sync_db', 'ecchange' & 'temp'
@example
async function attachSimulationDb(masterFile: LocalFileName, simulationFile: LocalFileName): Promise<void> {
const master = SnapshotDb.openFile(masterFile);
// attach simulation db
master.attachDb(simulationFile, "SimDb");
const ecsql = `
SELECT ts.TimeFromStart [Time From Start (s)],
p.UserLabel [Pipe with Max Flow],
MAX(ltvrr.Flow) [Max Flow (L/s)]
FROM
SimDb.simrescore.TimeStep ts
INNER JOIN SimDb.stmswrres.BasicFlowResultRecord ltvrr ON ts.ECInstanceId = ltvrr.TimeStep.Id
INNER JOIN swrhyd.Pipe p ON p.ECInstanceId = ltvrr.ElementId
GROUP BY
ts.ECInstanceId
HAVING
MAX(ltvrr.Flow) > 1 LIMIT 3`;
const reader = master.createQueryReader(ecsql);
const rows = [];
while (await reader.step()) {
rows.push(reader.current.toRow());
}
const expected = [
{
'Time From Start (s)': 0,
'Pipe with Max Flow': 'CO-4',
'Max Flow (L/s)': 66.14359584163114
},
{
'Time From Start (s)': 3600,
'Pipe with Max Flow': 'CO-4',
'Max Flow (L/s)': 78.33925707748288
},
{
'Time From Start (s)': 7200,
'Pipe with Max Flow': 'CO-3',
'Max Flow (L/s)': 85.32875334207684
},
];
expect(rows).to.deep.equal(expected);
// detach attached db
master.detachDb("SimDb");
master.close();
}
| Parameter | Type | Description |
|---|---|---|
| alias | string | identifer that was used in the call to attachDb |
Returns - void
Defined in
- core/backend/src/IModelDb.ts Line 564
Last Updated: 24 January, 2026
Found something wrong, missing, or unclear on this page? Raise an issue in our repo.