-
-
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
8 changed files
with
418 additions
and
5 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,48 @@ | ||
package files.howtos | ||
|
||
import utils.* | ||
import Bundle.*, Tags.* | ||
|
||
object MapToObject extends HowToPage { | ||
|
||
override def pageSettings = | ||
super.pageSettings.withTitle("Map Results To Objects") | ||
|
||
override def blogSettings = | ||
super.blogSettings.withSections(firstSection) | ||
|
||
val firstSection = Section( | ||
"How To Map Flat Rows To Objects", | ||
frag( | ||
s""" | ||
You can do arbitrary SQL commands here. | ||
The most common one is `UPDATE`-ing some rows: | ||
```scala | ||
// returns number of affected rows | ||
def updateCustomers: Int = ctx.run { | ||
sql${Consts.tq} | ||
UPDATE customers | ||
SET name = 'whatever' | ||
WHERE name LIKE 'xyz_%' | ||
${Consts.tq}.update() | ||
} | ||
``` | ||
|
||
--- | ||
|
||
But of course you can do other commands as well: | ||
```scala | ||
def createTable: Unit = ctx.run { | ||
sql${Consts.tq} | ||
CREATE TABLE customers( | ||
id SERIAL PRIMARY KEY, | ||
name VARCHAR | ||
) | ||
${Consts.tq}.update() | ||
} | ||
``` | ||
|
||
""".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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package ba.sake.squery.h2 | ||
|
||
import java.{sql => jsql} | ||
import java.util.UUID | ||
import ba.sake.squery.read.* | ||
|
||
given SqlRead[UUID] with { | ||
def readByName(jRes: jsql.ResultSet, colName: String): Option[UUID] = | ||
Option(jRes.getObject(colName, classOf[UUID])) | ||
|
||
def readByIdx(jRes: jsql.ResultSet, colIdx: Int): Option[UUID] = | ||
Option(jRes.getObject(colIdx, classOf[UUID])) | ||
} |
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,15 @@ | ||
package ba.sake.squery.h2 | ||
|
||
import java.{sql => jsql} | ||
import java.util.UUID | ||
import ba.sake.squery.write.* | ||
|
||
given SqlWrite[UUID] with { | ||
def write( | ||
ps: jsql.PreparedStatement, | ||
idx: Int, | ||
valueOpt: Option[UUID] | ||
): Unit = valueOpt match | ||
case Some(value) => ps.setObject(idx, value) | ||
case None => ps.setNull(idx, jsql.Types.OTHER) | ||
} |
Oops, something went wrong.