-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
107 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package files.howtos | ||
|
||
import utils.* | ||
import Bundle.*, Tags.* | ||
|
||
object InterpolateLiteralStrings extends HowToPage { | ||
|
||
override def pageSettings = | ||
super.pageSettings.withTitle("Interpolate literal strings") | ||
|
||
override def blogSettings = | ||
super.blogSettings.withSections(firstSection) | ||
|
||
val firstSection = Section( | ||
"How To Interpolate Literal Strings?", | ||
s""" | ||
You can use `inline val` (literal type) string values in your queries: | ||
```scala | ||
inline val columns = "id, name, age" | ||
sql${Consts.tq} | ||
SELECT $${columns} | ||
FROM customers | ||
${Consts.tq}.readRows[Customer]() | ||
``` | ||
|
||
This will **not** make a `?` parameter, it will directly insert the literal string. | ||
Same as if you wrote this: | ||
```scala | ||
sql${Consts.tq} | ||
SELECT id, name, age | ||
FROM customers | ||
${Consts.tq}.readRows[Customer]() | ||
``` | ||
""".md | ||
) | ||
} |
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,45 @@ | ||
package files.howtos | ||
|
||
import utils.* | ||
import Bundle.*, Tags.* | ||
|
||
object Transactions extends HowToPage { | ||
|
||
override def pageSettings = | ||
super.pageSettings.withTitle("Transactions") | ||
|
||
override def blogSettings = | ||
super.blogSettings.withSections(firstSection) | ||
|
||
val firstSection = Section( | ||
"How To Run Transactions?", | ||
frag( | ||
s""" | ||
We use the `runTransaction` to run queries inside of a transaction: | ||
```scala | ||
ctx.runTransaction { | ||
sql" | ||
INSERT INTO customers(name) | ||
VALUES (1, 'abc') | ||
".insert() | ||
sql" | ||
INSERT INTO customers(name) | ||
VALUES (1, 'def') | ||
".insert() | ||
} | ||
``` | ||
If one of the queries fails, the transaction will be rolled back, nothing will happen. | ||
|
||
--- | ||
The `runTransaction` uses the *default JDBC driver* transaction isolation (depends on db). | ||
If you want to explicitly set the transaction isolation you can use the `runTransactionWithIsolation` function: | ||
```scala | ||
ctx.runTransactionWithIsolation(TransactionIsolation.Serializable) { | ||
// queries here | ||
} | ||
``` | ||
|
||
""".md | ||
) | ||
) | ||
} |
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