Repository navigation
feat(javascript): make driver optional when uri or profile is provided - #4537
Conversation
…file is provided Allow creating AdbcDatabase without an explicit driver field when the driver can be inferred from databaseOptions: - databaseOptions.uri with a URI scheme (e.g. "sqlite::memory:") - databaseOptions.uri with a profile:// URI - databaseOptions.profile with a bare profile name
| Some(db_opts) => driver.new_database_with_opts(db_opts)?, | ||
| None => driver.new_database()?, | ||
| let database = match opts.driver { | ||
| Some(ref driver) if driver.contains(':') => { |
There was a problem hiding this comment.
I think in C++ we look for :// (this does catch out sqlite: without the recent changes to also accept sqlite://). Wouldn't this catch Windows-style paths?
There was a problem hiding this comment.
It does catch Windows-style paths. However it's then directly passed into the Rust driver manager which is responsible for resolving it.
This part here is basically just compensating for Rust not having a single entrypoint.
|
These should both work, but they error: const db = new AdbcDatabase({
driver: 'sqlite',
databaseOptions: { profile: 'my_profile' },
});const db = new AdbcDatabase({
driver: 'sqlite',
databaseOptions: { uri: 'profile://my_profile' },
});In other driver managers, code like this succeeds as long as the driver passed as an argument doesn't disagree with the driver set in the connection profile. |
There was a problem hiding this comment.
These should both work, but they error:
const db = new AdbcDatabase({ driver: 'sqlite', databaseOptions: { profile: 'my_profile' }, });const db = new AdbcDatabase({ driver: 'sqlite', databaseOptions: { uri: 'profile://my_profile' }, });In other driver managers, code like this succeeds as long as the driver passed as an argument doesn't disagree with the driver set in the connection profile.
Noted. Updated this to ensure these forms are accepted. However the remaining gap of detecting and erroring on disagreeing drivers probably is best handled in the Rust driver manager. I'll file a separate issue for that. edit: updated with this validation
| Some(db_opts) => driver.new_database_with_opts(db_opts)?, | ||
| None => driver.new_database()?, | ||
| let database = match opts.driver { | ||
| Some(ref driver) if driver.contains(':') => { |
There was a problem hiding this comment.
It does catch Windows-style paths. However it's then directly passed into the Rust driver manager which is responsible for resolving it.
This part here is basically just compensating for Rust not having a single entrypoint.
|
The Rust API makes this driver-mismatch condition less likely because normal usage involves choosing either |
Yeah it's worth raising. The Rust API requires the caller to know which entrypoint to use beforehand which differs from the other driver manager implementations. |
Could you please open an issue? Thanks! |
lidavidm
left a comment
There was a problem hiding this comment.
We should probably align the two better if we can, yes
Summary
Allows creating
AdbcDatabasewithout an explicitdriveroption whendatabaseOptions.uricontains a URI that identifies the driver, or whendatabaseOptions.profilespecifies a connection profileBefore
After
Specifying more than one profile resolution path results in an error
Test Plan
Closes #4533