-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add SetDefaultPrepared which controls query value interpolation
This switches the datasets' internal isPrepared bools into a custom type that resolves back into a bool when passed into the SQL builder. This could have also been a *bool but I wanted to avoid nil checks and potential sources of confusion if e.g. a child dataset happened to dereference and mutate the pointer's value.
- Loading branch information
1 parent
6c631e9
commit 51bcb84
Showing
11 changed files
with
139 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package goqu | ||
|
||
var ( | ||
// defaultPrepared is controlled by SetDefaultPrepared | ||
defaultPrepared bool | ||
) | ||
|
||
type prepared int | ||
|
||
const ( | ||
// zero value that defers to defaultPrepared | ||
preparedNoPreference prepared = iota | ||
|
||
// explicitly enabled via Prepared(true) on a dataset | ||
preparedEnabled | ||
|
||
// explicitly disabled via Prepared(false) on a dataset | ||
preparedDisabled | ||
) | ||
|
||
// Bool converts the ternary prepared state into a boolean. If the prepared | ||
// state is preparedNoPreference, the value depends on the last value that | ||
// SetDefaultPrepared was called with which is false by default. | ||
func (p prepared) Bool() bool { | ||
if p == preparedNoPreference { | ||
return defaultPrepared | ||
} else if p == preparedEnabled { | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
|
||
// preparedFromBool converts a bool from e.g. Prepared(true) into a prepared | ||
// const. | ||
func preparedFromBool(prepared bool) prepared { | ||
if prepared { | ||
return preparedEnabled | ||
} | ||
|
||
return preparedDisabled | ||
} | ||
|
||
// SetDefaultPrepared controls the default Prepared state of all datasets. If | ||
// set to true, any new dataset will use prepared queries by default. | ||
func SetDefaultPrepared(prepared bool) { | ||
defaultPrepared = prepared | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters