Skip to content

feat(javascript): make driver optional when uri or profile is provided - #4537

Merged
lidavidm merged 5 commits into
apache:mainfrom
kentkwu:gh-4533
Jul 19, 2026
Merged

lidavidm merged 5 commits into
apache:mainfrom
kentkwu:gh-4533

Conversation

@kentkwu

@kentkwu kentkwu commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Allows creating AdbcDatabase without an explicit driver option when databaseOptions.uri contains a URI that identifies the driver, or when databaseOptions.profile specifies a connection profile

Before

// before: driver was required
new AdbcDatabase({ driver: 'sqlite', databaseOptions: { uri: ':memory:' } })

After

// driver can be omitted when uri carries the scheme
new AdbcDatabase({ databaseOptions: { uri: 'sqlite::memory:' } })

// driver can be omitted with a bare profile name
new AdbcDatabase({ databaseOptions: { profile: 'my_profile' } })

// driver + profile key
new AdbcDatabase({ driver: 'sqlite', databaseOptions: { profile: 'my_profile' } })

// driver + profile via URI
new AdbcDatabase({ driver: 'sqlite', databaseOptions: { uri: 'profile://my_profile' } })

Specifying more than one profile resolution path results in an error

// will error
new AdbcDatabase({ databaseOptions: { profile: 'p1', uri: 'profile://p2' } })

// will error
new AdbcDatabase({ databaseOptions: { driver: 'postgres', profile: 'p1' }) // with p1 specifying different driver

Test Plan

npm build
npm test

Closes #4533

…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
@kentkwu kentkwu changed the title feat(javascript/driver-manager): make driver optional when uri or profile is provided feat(javascript): make driver optional when uri or profile is provided Jul 17, 2026
Comment thread javascript/src/client.rs Outdated
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(':') => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ianmcook

ianmcook commented Jul 17, 2026 •

Copy link
Copy Markdown
Member

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.

@kentkwu kentkwu left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread javascript/src/client.rs Outdated
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(':') => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ianmcook ianmcook left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ianmcook

ianmcook commented Jul 17, 2026 •

Copy link
Copy Markdown
Member

The Rust API makes this driver-mismatch condition less likely because normal usage involves choosing either ManagedDriver::load_from_name or ManagedDatabase::from_uri. @kentkwu do you think it's still worth opening an issue to look into this on the Rust side?

@kentkwu

kentkwu commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

The Rust API makes this driver-mismatch condition less likely because normal usage involves choosing either ManagedDriver::load_from_name or ManagedDatabase::from_uri. @kentkwu do you think it's still worth opening an issue to look into this on the Rust side?

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.

@ianmcook

Copy link
Copy Markdown
Member

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 lidavidm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably align the two better if we can, yes

@lidavidm
lidavidm merged commit 3e7f035 into apache:main Jul 19, 2026
13 checks passed
@lidavidm lidavidm added this to the ADBC Libraries 24 milestone Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

javascript: allow creating AdbcDatabase without driver if driver is otherwise specified

3 participants