Skip to content
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

Insert 'USING TTL' and 'TIMESTAMP' into the UPDATE sql #16

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class TableWriter[T] private (

val ifNotExistsSpec = if (writeConf.ifNotExists) "IF NOT EXISTS " else ""

s"INSERT INTO ${quote(keyspaceName)}.${quote(tableName)} ($columnSpec) VALUES ($valueSpec) $ifNotExistsSpec$optionsSpec".trim
}

private lazy val optionsSpec: String = {
val ttlSpec = writeConf.ttl match {
case TTLOption(PerRowWriteOptionValue(placeholder)) => Some(s"""TTL :$placeholder""")
case TTLOption(StaticWriteOptionValue(value)) => Some(s"TTL $value")
Expand All @@ -57,9 +61,7 @@ class TableWriter[T] private (
}

val options = List(ttlSpec, timestampSpec).flatten
val optionsSpec = if (options.nonEmpty) s"USING ${options.mkString(" AND ")}" else ""

s"INSERT INTO ${quote(keyspaceName)}.${quote(tableName)} ($columnSpec) VALUES ($valueSpec) $ifNotExistsSpec$optionsSpec".trim
if (options.nonEmpty) s"USING ${options.mkString(" AND ")}" else ""
}

private def deleteQueryTemplate(deleteColumns: ColumnSelector): String = {
Expand Down Expand Up @@ -136,7 +138,7 @@ class TableWriter[T] private (
}
val whereClause = quotedColumnNames(primaryKey).map(c => s"$c = :$c").mkString(" AND ")

s"UPDATE ${quote(keyspaceName)}.${quote(tableName)} SET $setClause WHERE $whereClause $optionalClause"
s"UPDATE ${quote(keyspaceName)}.${quote(tableName)} $optionsSpec SET $setClause WHERE $whereClause $optionalClause"
}

private val isCounterUpdate =
Expand Down