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

Add query execution utilities #18

Closed
wants to merge 2 commits into from
Closed

Conversation

yhabteab
Copy link
Member

@yhabteab yhabteab commented May 27, 2024

No description provided.

@cla-bot cla-bot bot added the cla/signed CLA is signed by all contributors of a PR label May 27, 2024
@yhabteab yhabteab force-pushed the query-builder branch 2 times, most recently from 13775df to 9cfb220 Compare May 27, 2024 13:39
@yhabteab yhabteab force-pushed the query-builder branch 2 times, most recently from 474ff25 to 3e9722f Compare May 28, 2024 10:16
@yhabteab yhabteab requested a review from Al2Klimov May 28, 2024 15:09
database/db.go Outdated Show resolved Hide resolved
database/db.go Outdated Show resolved Hide resolved
database/db.go Outdated Show resolved Hide resolved
database/utils.go Outdated Show resolved Hide resolved
database/utils.go Outdated Show resolved Hide resolved
database/utils.go Outdated Show resolved Hide resolved
database/contracts.go Show resolved Hide resolved
database/contracts.go Outdated Show resolved Hide resolved
Comment on lines 63 to 68
// TxOrDB is just a helper interface that can represent a *[sqlx.Tx] or *[DB] instance.
type TxOrDB interface {
sqlx.ExtContext
sqlx.PreparerContext

PrepareNamedContext(ctx context.Context, query string) (*sqlx.NamedStmt, error)
}
Copy link
Member

Choose a reason for hiding this comment

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

Also the whole thing seems just a subset of DB&Tx. I personally would unexport and move it...

Copy link
Member Author

Choose a reason for hiding this comment

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

Wouldn't you also want to use this interface type elsewhere where a DB or Tx is required?

Copy link
Member

Choose a reason for hiding this comment

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

First of all: (Where) Do you actually plan to pass a DB into your new function?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't have any (yet), I was just trying to say that it's not that special and one can use it anywhere else if they need to.

Copy link
Member

Choose a reason for hiding this comment

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

For me the last insert ID makes only sense for immediate subsequent processing – which just screams transaction. So I'd just allow Tx as parameter for now unless/until someone finds an actual use case with DB. (But then I'd:

  1. unexport the interface OR
  2. aggregate there all interfaces and non-interface methods both Tx and DB implement.)

@@ -43,6 +45,49 @@ func SplitOnDupId[T IDer]() com.BulkChunkSplitPolicy[T] {
}
}

// InsertObtainID executes the given query and fetches the last inserted ID.
Copy link
Member

Choose a reason for hiding this comment

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

... here due to how special it is.

@lippserd lippserd self-requested a review August 14, 2024 10:47
Copy link
Member

@lippserd lippserd left a comment

Choose a reason for hiding this comment

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

Please split pr the into two.

@yhabteab
Copy link
Member Author

The commits are split into their own PRs so that this is no longer necessary.

@yhabteab yhabteab closed this Aug 14, 2024
@yhabteab yhabteab deleted the icinga-notifications branch August 14, 2024 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla/signed CLA is signed by all contributors of a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants