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

sql,pg,engine: rework sql interfaces #601

Merged
merged 1 commit into from
Mar 15, 2024

Conversation

jchappelow
Copy link
Member

@jchappelow jchappelow commented Mar 13, 2024

Reduce sql interfaces, and clean up pg methods.

This change does:

  • rework all of the interfaces in common/sql/sql.go for clarity and versatility. See updated type docs there. Types and interfaces are generally defined from lowest to highest level of composition for easy of understanding.

  • With a *pg.DB, it was previously required to call Precommit before Commit, but made the type less able to effectively satisfy the simpler sql interfaces, and it was technically of no need if a commit ID (or 2pc) was not required. Now it is optional, simplifying it's use in contexts where these features are not relevant (only commit or rollback needed).

  • Remove AccessMode from the DB (and thus Tx) interfaces, making it an optional type assertion required by the engine for mutable actions. This wasn't totally necessary to change, but it was an awkward method for all other systems and their tests.

  • Remove many obsolete types and methods from internal/sql/pg/conn.go, mostly from when we had implicit sessions rather than transaction-scoped Executors.

  • The OuterTxMaker interface no longer collides with TxMaker, allowing *pg.DB to satisfy both.

  • Fix (*Pool).BeginReadTx beginning a RW txn instead of a RO txn.

  • Globally narrow the interfaces on function input arguments to what is actually required. This improves semantics and testability.

Many other less notable changes...

Some significant ugliness in the event store test setup (events_tests.go) is eliminated.

Comment on lines -215 to -227
dbVoting, err := dbtest.NewTestDB(t)
txVoting, _ := dbVoting.BeginTx(ctx)
err = voting.InitializeVoteStore(ctx, txVoting)
db, cleanup, err := dbtest.NewTestPool(ctx, []string{schemaName, "kwild_voting"}) // db is the event store specific connection
require.NoError(t, err)
_, err = txVoting.Precommit(ctx)
require.NoError(t, err)
err = txVoting.Commit(ctx)
require.NoError(t, err)
// defer // drop kwild_voting
defer func() {
dbVoting.AutoCommit(true)
dbVoting.Execute(ctx, `drop schema if exists kwild_voting cascade;`)
}()
Copy link
Member Author

Choose a reason for hiding this comment

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

This 13 line monstrosity is where I started looking for the issues with the pg and sql interfaces and concrete types.

@brennanjl
Copy link
Collaborator

lgtm, will let you merge since the first line says DO NOT MERGE

Reduce sql interfaces, and clean up pg methods.
@jchappelow jchappelow merged commit da35951 into kwilteam:main Mar 15, 2024
1 check passed
@jchappelow jchappelow deleted the pg-clean-test branch March 15, 2024 15:42
@jchappelow jchappelow added this to the v0.8.0 milestone May 2, 2024
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