-
Notifications
You must be signed in to change notification settings - Fork 0
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
#35: Refactor the core for more logical structure #36
Merged
benedeki
merged 19 commits into
master
from
feature/35-refactor-the-core-for-more-logical-structure
Jun 13, 2023
Merged
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
384948d
#35: Refactor the core for more logical structure
benedeki 6af747a
* work in progress
benedeki e033a35
* Still work in progress, already builds, just one step remains, but …
benedeki 8304276
* reshaped to shape of Shapeless
benedeki 58e045d
* Massive refactoring finally working
benedeki feefd55
Merge remote-tracking branch 'remotes/origin/master' into feature/35-…
benedeki 54ae61a
* removed println from code
benedeki 7e39608
* example test in `DatasetSchemaSuite` ignored
benedeki 0857701
* added documentation
benedeki a93d969
Apply suggestions from code review
benedeki b894411
* further PR comments addressed
benedeki 071dce1
* New line
benedeki 4a47099
Update core/src/test/scala/za/co/absa/fadb/statushandling/StatusExcep…
benedeki 6e32cb3
* Little fixes
benedeki e72e9e9
* replaced T type for I
benedeki 795fea3
Apply suggestions from code review
benedeki 54cb3a2
Merge branch 'master' into feature/35-refactor-the-core-for-more-logi…
benedeki a3380c6
* addressed PR comments
benedeki 8b97a75
Update examples/src/main/scala/za/co/absa/fadb/examples/enceladus/Dat…
benedeki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright 2022 ABSA Group Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package za.co.absa.fadb | ||
|
||
import scala.concurrent.ExecutionContext.Implicits.global | ||
import scala.concurrent.Future | ||
import scala.language.higherKinds | ||
|
||
/** | ||
* A basis to represent a database executor | ||
*/ | ||
trait DBEngine { | ||
|
||
/** | ||
* A type representing the (SQL) query within the engine | ||
* @tparam X - the return type of the query | ||
*/ | ||
type QueryType[X] <: Query[X] | ||
|
||
/** | ||
* The actual query executioner of the queries of the engine | ||
* @param query - the query to execute | ||
* @tparam R - return the of the query | ||
* @return - sequence of the results of database query | ||
*/ | ||
protected def run[R](query: QueryType[R]): Future[Seq[R]] | ||
|
||
/** | ||
* Public method to execute when query is expected to return multiple results | ||
* @param query - the query to execute | ||
* @tparam R - return the of the query | ||
* @return - sequence of the results of database query | ||
*/ | ||
def execute[R](query: QueryType[R]): Future[Seq[R]] = run(query) | ||
|
||
/** | ||
* Public method to execute when query is expected to return exactly one row | ||
* @param query - the query to execute | ||
* @tparam R - return the of the query | ||
* @return - sequence of the results of database query | ||
*/ | ||
def unique[R](query: QueryType[R]): Future[R] = { | ||
run(query).map(_.head) | ||
} | ||
|
||
/** | ||
* Public method to execute when query is expected to return one or no results | ||
* @param query - the query to execute | ||
* @tparam R - return the of the query | ||
* @return - sequence of the results of database query | ||
*/ | ||
|
||
def option[R](query: QueryType[R]): Future[Option[R]] = { | ||
lsulak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
run(query).map(_.headOption) | ||
} | ||
} | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking about whether to name this as
executeOne
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like 'execute' as prefix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I on the other hand like them distinguished. 😉 Easier to read. and also nicely binds to the successor classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think
option
is easier to read. It's not intuitive. We are actually executing a SQL query here.In regards to the
unique
... it's kind of better, but still, I don't really like it that much.Let's have an inspiration from some most famous DB libraries out there. For example SQLAlchemy. There are functions like
fetchOne
,executeMany
etc - https://peps.python.org/pep-0249/#executemany and I think that's much better, because it not only says what the result kind of should be, but also it says about what is actually happening. Does it make sense?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, Will think about the names 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed to do the renames as part of #34
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay