-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split
stringutil.Wrap
into two functions
- Loading branch information
1 parent
4153191
commit 6371fdb
Showing
9 changed files
with
71 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package sql |
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,14 @@ | ||
package sql | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/artie-labs/transfer/lib/stringutil" | ||
) | ||
|
||
func QuoteLiteral(value string) string { | ||
// When there is quote wrapping `foo -> 'foo'`, we'll need to escape `'` so the value compiles. | ||
// However, if there are no quote wrapping, we should not need to escape. | ||
return fmt.Sprintf("'%s'", strings.ReplaceAll(stringutil.EscapeBackslashes(value), "'", `\'`)) | ||
} |
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,42 @@ | ||
package sql | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestQuoteLiteral(t *testing.T) { | ||
type _testCase struct { | ||
name string | ||
colVal string | ||
expectedString string | ||
} | ||
|
||
testCases := []_testCase{ | ||
{ | ||
name: "string", | ||
colVal: "hello", | ||
expectedString: "'hello'", | ||
}, | ||
{ | ||
name: "string that requires escaping", | ||
colVal: "bobby o'reilly", | ||
expectedString: `'bobby o\'reilly'`, | ||
}, | ||
{ | ||
name: "string with line breaks", | ||
colVal: "line1 \n line 2", | ||
expectedString: "'line1 \n line 2'", | ||
}, | ||
{ | ||
name: "string with existing backslash", | ||
colVal: `hello \ there \ hh`, | ||
expectedString: `'hello \\ there \\ hh'`, | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
assert.Equal(t, testCase.expectedString, QuoteLiteral(testCase.colVal), testCase.name) | ||
} | ||
} |
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