-
Notifications
You must be signed in to change notification settings - Fork 116
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 'format' function to PostgresModule #184 #415
Merged
jczuchnowski
merged 3 commits into
zio:master
from
TobiasPfeifer:feature/postgres-format-function
Apr 26, 2021
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
|
@@ -151,7 +151,105 @@ object FunctionDefSpec extends PostgresRunnableSpec with ShopSchema { | |
} yield assert(r.head)(equalTo(expected)) | ||
|
||
assertion.mapErrorCause(cause => Cause.stackless(cause.untraced)) | ||
} | ||
}, | ||
suite("format function")( | ||
testM("format0") { | ||
import Expr._ | ||
|
||
val query = select(Format0("Person")) from customers | ||
|
||
val expected = Seq( | ||
"Person", | ||
"Person", | ||
"Person", | ||
"Person", | ||
"Person" | ||
) | ||
|
||
val testResult = execute(query.to[String, String](identity)) | ||
collectAndCompare(expected, testResult) | ||
}, | ||
testM("format1") { | ||
import Expr._ | ||
|
||
val query = select(Format1("Person: %s", Customers.fName)) from customers | ||
|
||
val expected = Seq( | ||
"Person: Ronald", | ||
"Person: Terrence", | ||
"Person: Mila", | ||
"Person: Alana", | ||
"Person: Jose" | ||
) | ||
|
||
val testResult = execute(query.to[String, String](identity)) | ||
collectAndCompare(expected, testResult) | ||
}, | ||
testM("format2") { | ||
import Expr._ | ||
|
||
val query = select(Format2("Person: %s %s", Customers.fName, Customers.lName)) from customers | ||
|
||
val expected = Seq( | ||
"Person: Ronald Russell", | ||
"Person: Terrence Noel", | ||
"Person: Mila Paterso", | ||
"Person: Alana Murray", | ||
"Person: Jose Wiggins" | ||
) | ||
|
||
val testResult = execute(query.to[String, String](identity)) | ||
collectAndCompare(expected, testResult) | ||
}, | ||
testM("format3") { | ||
import Expr._ | ||
|
||
val query = select(Format3("Person: %s %s with double quoted %I ", Customers.fName, Customers.lName, "identi fier")) from customers | ||
|
||
val expected = Seq( | ||
s"""Person: Ronald Russell with double quoted "identi fier" """, | ||
s"""Person: Terrence Noel with double quoted "identi fier" """, | ||
s"""Person: Mila Paterso with double quoted "identi fier" """, | ||
s"""Person: Alana Murray with double quoted "identi fier" """, | ||
s"""Person: Jose Wiggins with double quoted "identi fier" """ | ||
) | ||
|
||
val testResult = execute(query.to[String, String](identity)) | ||
collectAndCompare(expected, testResult) | ||
}, | ||
testM("format4") { | ||
import Expr._ | ||
|
||
val query = select(Format4("Person: %s %s with null-literal %L and non-null-literal %L ", Customers.fName, Customers.lName, "FIXME: NULL", "literal")) from customers | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. couldn't find a solution to specify NULL There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, Options are not well supported at this point. |
||
|
||
val expected = Seq( | ||
s"""Person: Ronald Russell with null-literal 'FIXME: NULL' and non-null-literal 'literal' """, | ||
s"""Person: Terrence Noel with null-literal 'FIXME: NULL' and non-null-literal 'literal' """, | ||
s"""Person: Mila Paterso with null-literal 'FIXME: NULL' and non-null-literal 'literal' """, | ||
s"""Person: Alana Murray with null-literal 'FIXME: NULL' and non-null-literal 'literal' """, | ||
s"""Person: Jose Wiggins with null-literal 'FIXME: NULL' and non-null-literal 'literal' """ | ||
) | ||
|
||
val testResult = execute(query.to[String, String](identity)) | ||
collectAndCompare(expected, testResult) | ||
}, | ||
testM("format5") { | ||
import Expr._ | ||
|
||
val query = select(Format5("Person: %s %s with more arguments than placeholders: %I %L ", Customers.fName, Customers.lName, "identifier", Reverse(Customers.fName), "unused")) from customers | ||
|
||
val expected = Seq( | ||
s"""Person: Ronald Russell with more arguments than placeholders: identifier 'dlanoR' """, | ||
s"""Person: Terrence Noel with more arguments than placeholders: identifier 'ecnerreT' """, | ||
s"""Person: Mila Paterso with more arguments than placeholders: identifier 'aliM' """, | ||
s"""Person: Alana Murray with more arguments than placeholders: identifier 'analA' """, | ||
s"""Person: Jose Wiggins with more arguments than placeholders: identifier 'esoJ' """ | ||
) | ||
|
||
val testResult = execute(query.to[String, String](identity)) | ||
collectAndCompare(expected, testResult) | ||
} | ||
) | ||
), | ||
testM("abs") { | ||
val query = select(Abs(-3.14159)) from customers | ||
|
@@ -358,7 +456,7 @@ object FunctionDefSpec extends PostgresRunnableSpec with ShopSchema { | |
r <- testResult.runCollect | ||
} yield assert(r.head)( | ||
matchesRegex( | ||
"[A-Za-z]{3}\\s[A-Za-z]{3}\\s[0-9]{2}\\s(2[0-3]|[01][0-9]):[0-5][0-9]:[0-5][0-9].[0-9]{6}\\s[0-9]{4}\\s[A-Za-z]{3}" | ||
"[A-Za-z]{3}\\s[A-Za-z]{3}\\s[0-9]{2}\\s(2[0-3]|[01][0-9]):[0-5][0-9]:[0-5][0-9].[0-9]{6}\\s[0-9]{4}\\s[A-Za-z]{3,4}" | ||
) | ||
) | ||
assertion.mapErrorCause(cause => Cause.stackless(cause.untraced)) | ||
|
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.
varargs not available yet (see also 'concat' function)
Is there an open issue for varargs support? otherwise I would open an issue to track this (and might give it a try)
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.
Created issue here #439