-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow attach/detach db to IModelDb connection #7530
Open
khanaffan
wants to merge
24
commits into
master
Choose a base branch
from
affanK/attach-detach-file
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
a17f8fa
add interface method and test
khanaffan d7b4351
Update test
khanaffan a920743
rush extract-api
khanaffan 52b5cba
rush changes
khanaffan e603c27
lint
khanaffan 8e9dc21
Merge branch 'master' into affanK/attach-detach-file
khanaffan f3a1d9f
Merge branch 'master' into affanK/attach-detach-file
khanaffan 68f7417
Merge branch 'master' of https://github.com/iTwin/itwinjs-core into a…
khanaffan b064f7a
add test
khanaffan 3b14578
Merge branch 'master' of https://github.com/iTwin/itwinjs-core into a…
khanaffan 3c4984a
fix test
khanaffan a9a804f
undo cloud sqlite test
khanaffan 941735e
Merge branch 'master' of https://github.com/iTwin/itwinjs-core into a…
khanaffan c2187f2
add unit test
khanaffan a2dde85
close file at the end of the function
khanaffan 740fd4e
update next version md
khanaffan 59f0ce8
Update docs/changehistory/NextVersion.md
khanaffan 7e363b2
Update docs/changehistory/NextVersion.md
khanaffan edcfafd
Update core/backend/src/ECDb.ts
khanaffan 2547b69
Update core/backend/src/ECDb.ts
khanaffan 23450c0
Update core/backend/src/IModelDb.ts
khanaffan 6aea062
Update core/backend/src/IModelDb.ts
khanaffan 41472bd
Merge branch 'master' into affanK/attach-detach-file
khanaffan 29bfd7b
Merge branch 'master' into affanK/attach-detach-file
khanaffan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
common/changes/@itwin/core-backend/affanK-attach-detach-file_2025-01-08-18-59.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "@itwin/core-backend", | ||
"comment": "Allow attach/detach db", | ||
"type": "none" | ||
} | ||
], | ||
"packageName": "@itwin/core-backend" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -365,7 +365,22 @@ export abstract class IModelDb extends IModel { | |
}); | ||
} | ||
} | ||
|
||
/** | ||
* Attach an iModel file to this connection and load and register its schemas. | ||
* @param fileName IModel file name | ||
* @param alias identifier for the attached file. This identifer is used a tablespace executing ECSQL queries. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as for ECDb regarding "a tablespace". |
||
*/ | ||
public attachDb(fileName: string, alias: string): void { | ||
this[_nativeDb].attachDb(fileName, alias); | ||
} | ||
/** | ||
* Detach the attached file from this connection. The attached file is closed and its schemas are unregistered. | ||
* @param alias identifer that was used in the call to [[attachDb]] | ||
*/ | ||
public detachDb(alias: string): void { | ||
this.clearCaches(); | ||
this[_nativeDb].detachDb(alias); | ||
} | ||
/** Close this IModel, if it is currently open, and save changes if it was opened in ReadWrite mode. */ | ||
public close(): void { | ||
if (!this.isOpen) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Bentley Systems, Incorporated. All rights reserved. | ||
* See LICENSE.md in the project root for license terms and full copyright notice. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { expect } from "chai"; | ||
import { SnapshotDb } from "../IModelDb"; | ||
import { IModelTestUtils } from "./IModelTestUtils"; | ||
|
||
describe("Attach/Detach Db", () => { | ||
it("attach simulation db", async () => { | ||
const masterFile = IModelTestUtils.resolveAssetFile("sim-master.bim"); | ||
const simulationFile = IModelTestUtils.resolveAssetFile("sim-attach.ecdb"); | ||
|
||
const master = SnapshotDb.openFile(masterFile); | ||
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`; | ||
|
||
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 | ||
}, | ||
{ | ||
'Time From Start (s)': 10800, | ||
'Pipe with Max Flow': 'CO-3', | ||
'Max Flow (L/s)': 73.66891955141061 | ||
}, | ||
{ | ||
'Time From Start (s)': 14400, | ||
'Pipe with Max Flow': 'CO-3', | ||
'Max Flow (L/s)': 98.03457129303487 | ||
}, | ||
{ | ||
'Time From Start (s)': 18000, | ||
'Pipe with Max Flow': 'CO-3', | ||
'Max Flow (L/s)': 79.73721449443349 | ||
}, | ||
{ | ||
'Time From Start (s)': 21600, | ||
'Pipe with Max Flow': 'CO-4', | ||
'Max Flow (L/s)': 91.99697459812566 | ||
}, | ||
{ | ||
'Time From Start (s)': 25200, | ||
'Pipe with Max Flow': 'CO-3', | ||
'Max Flow (L/s)': 97.3640516154515 | ||
}, | ||
{ | ||
'Time From Start (s)': 28800, | ||
'Pipe with Max Flow': 'CO-3', | ||
'Max Flow (L/s)': 82.92153917380564 | ||
}, | ||
{ | ||
'Time From Start (s)': 32400, | ||
'Pipe with Max Flow': 'CO-3', | ||
'Max Flow (L/s)': 93.43596024800935 | ||
}, | ||
{ | ||
'Time From Start (s)': 36000, | ||
'Pipe with Max Flow': 'CO-1', | ||
'Max Flow (L/s)': 93.38944851040705 | ||
}, | ||
{ | ||
'Time From Start (s)': 39600, | ||
'Pipe with Max Flow': 'CO-2', | ||
'Max Flow (L/s)': 96.89678313985426 | ||
}, | ||
{ | ||
'Time From Start (s)': 43200, | ||
'Pipe with Max Flow': 'CO-4', | ||
'Max Flow (L/s)': 68.37554676909588 | ||
}, | ||
{ | ||
'Time From Start (s)': 46800, | ||
'Pipe with Max Flow': 'CO-4', | ||
'Max Flow (L/s)': 40.71067873689955 | ||
}, | ||
{ | ||
'Time From Start (s)': 50400, | ||
'Pipe with Max Flow': 'CO-2', | ||
'Max Flow (L/s)': 94.95603088826243 | ||
}, | ||
{ | ||
'Time From Start (s)': 54000, | ||
'Pipe with Max Flow': 'CO-3', | ||
'Max Flow (L/s)': 90.30742518949977 | ||
}, | ||
{ | ||
'Time From Start (s)': 57600, | ||
'Pipe with Max Flow': 'CO-2', | ||
'Max Flow (L/s)': 96.32532799368296 | ||
}, | ||
{ | ||
'Time From Start (s)': 61200, | ||
'Pipe with Max Flow': 'CO-3', | ||
'Max Flow (L/s)': 98.7241157161529 | ||
}, | ||
{ | ||
'Time From Start (s)': 64800, | ||
'Pipe with Max Flow': 'CO-1', | ||
'Max Flow (L/s)': 76.65530275985837 | ||
}, | ||
{ | ||
'Time From Start (s)': 68400, | ||
'Pipe with Max Flow': 'CO-2', | ||
'Max Flow (L/s)': 61.81109058119374 | ||
}, | ||
{ | ||
'Time From Start (s)': 72000, | ||
'Pipe with Max Flow': 'CO-3', | ||
'Max Flow (L/s)': 98.37332278792479 | ||
}, | ||
{ | ||
'Time From Start (s)': 75600, | ||
'Pipe with Max Flow': 'CO-3', | ||
'Max Flow (L/s)': 70.55434454594996 | ||
}, | ||
{ | ||
'Time From Start (s)': 79200, | ||
'Pipe with Max Flow': 'CO-2', | ||
'Max Flow (L/s)': 84.03731418990937 | ||
}, | ||
{ | ||
'Time From Start (s)': 82800, | ||
'Pipe with Max Flow': 'CO-2', | ||
'Max Flow (L/s)': 96.3267817742375 | ||
} | ||
]; | ||
expect(rows).to.deep.equal(expected); | ||
master.close(); | ||
}); | ||
|
||
}); |
Binary file not shown.
Binary file not shown.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what "a tablespace" is supposed to mean. Maybe you meant "as tablespace", but I don't recognize the term "tablespace". I know what this parameter does, but I don't know the proper way to describe it.