Skip to content
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

[Go][Format] initial attempt at wrapping adbc for database/sql #97

Merged
merged 6 commits into from
Aug 31, 2022

Conversation

zeroshade
Copy link
Member

Here's my first shot at creating the wrapper. After this I'll look into actually creating an implementation to write tests with.

However, I did come across one thing: There are Commit and Rollback methods for a connection, but there's nothing to actually begin a transaction. Nor anything specific for defining transaction options such as Isolation level or Read-Only etc.

For Go's sql package there needs to be a BeginTx method on a connection which also shouldn't require creating a new connection (ie: start a new connection with autocommit turned off?) So i'm not sure of the best way to implement this in the current framework we have.

@zeroshade zeroshade requested a review from lidavidm August 30, 2022 20:15
@lidavidm
Copy link
Member

See

AdbcValidateBeginCase(adbc_context, "Connection", "enable autocommit");
ADBCV_ASSERT_OK(&error,
AdbcConnectionSetOption(&connection, ADBC_CONNECTION_OPTION_AUTOCOMMIT,
ADBC_OPTION_VALUE_ENABLED, &error));
AdbcValidateBeginCase(adbc_context, "Connection", "disable autocommit");
ADBCV_ASSERT_OK(&error,
AdbcConnectionSetOption(&connection, ADBC_CONNECTION_OPTION_AUTOCOMMIT,
ADBC_OPTION_VALUE_DISABLED, &error));
AdbcValidateBeginCase(adbc_context, "Connection", "commit/rollback succeed");
ADBCV_ASSERT_OK(&error, AdbcConnectionCommit(&connection, &error));
ADBCV_ASSERT_OK(&error, AdbcConnectionRollback(&connection, &error));

Disabling autocommit begins a transaction; commit/rollback also begin a transaction; enabling autocommit also runs a commit.

@zeroshade
Copy link
Member Author

Gotcha, so the interfaces should allow setting options on an existing connection, not only setting options before initializing it. I'll make the adjustment.

@zeroshade
Copy link
Member Author

@lidavidm Do we have any constants for setting the Isolation level of the transactions yet? If not, the golang values are:

LevelDefault
LevelReadUncommitted
LevelReadCommitted
LeveWriteCommitted
LevelRepeatableRead
LevelSnapshot
LevelSerializable
LevelLinearizable

With the documentation that if a driver does not support a given isolation level, an error may be returned. This is in addition to a ReadOnly boolean option. Should we add constants for these?

@lidavidm
Copy link
Member

We don't, it probably makes sense to define them

@zeroshade
Copy link
Member Author

@lidavidm Added them to this PR, let me know if you have any comments / issues with them. Thanks!

adbc.h Outdated
Comment on lines 657 to 660
/// \brief The name of the canonical option for whether the current
/// transaction should be restricted to being a read-only transaction.
#define ADBC_CONNECTION_OPTION_TRANSACTION_READ_ONLY \
"adbc.connection.transaction.readonly"
Copy link
Member

Choose a reason for hiding this comment

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

Interesting, so Golang has you explicitly manage transactions. DBAPI/JDBC/ODBC have "auto commit on" and you implicitly manage transactions (by disabling autocommit, then calling commit/rollback). In these APIs, readonly is a property of the connection, not the transaction. Given that the rest of the APIs are patterned after DBAPI/JDBC/ODBC, I think this would make more sense as a connection property as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

Interesting, okay. I'll change the option to be adbc.connection.readonly instead of adbc.connection.transaction.readonly

Copy link
Member Author

Choose a reason for hiding this comment

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

updated, let me know if there's anything else you'd like me to modify.

go/adbc/sqldriver/driver.go Show resolved Hide resolved
@lidavidm lidavidm changed the title initial attempt at wrapping adbc for database/sql [Go][Format] initial attempt at wrapping adbc for database/sql Aug 31, 2022
@lidavidm lidavidm merged commit 81d42a6 into apache:main Aug 31, 2022
@zeroshade zeroshade deleted the golang-sql-pkg branch August 31, 2022 20:55
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.

2 participants