Skip to content

Commit

Permalink
Merge pull request #96 from qiaoyuang/main
Browse files Browse the repository at this point in the history
Update to 1.3.2
  • Loading branch information
qiaoyuang authored Jun 18, 2024
2 parents 7a4c4a2 + dbff05f commit 4872fdd
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 8 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

- Date format: YYYY-MM-dd

## v1.3.2 / 2024-06-18

### All

* Update `Kotlin`'s version to `1.9.24`

### sqllin-dsl

* Now, you can annotate properties with `kotlinx.serialization.transmint` in your data classes to ignore these properties when serialization or deserialization and `Table` classes generation.

### sqllin-processor

* Update `KSP`'s version to `1.9.24-1.0.20`

## v1.3.1 / 2024-04-24

### sqllin-dsl
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
VERSION=1.3.1
VERSION=1.3.2
GROUP=com.ctrip.kotlin

kotlinVersion=1.9.23
kspVersion=1.9.23-1.0.20
kotlinVersion=1.9.24
kspVersion=1.9.24-1.0.20
serializationVersion=1.6.3
coroutinesVersion=1.8.0
androidxAnnotationVersion=1.7.1
Expand Down
2 changes: 1 addition & 1 deletion sqllin-dsl/doc/getting-start-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ data class Person(
将会使用类名作为表名,比如 `Person` 类的默认表名是"Person"。

_sqllin-dsl_ 中,对象序列化为 SQL 语句,或者从游标中反序列化依赖 _kotlinx.serialization_,所以你需要在你的 data class
上添加 `@Serializable` 注解。
上添加 `@Serializable` 注解。因此,如果你想在序列化或反序列化以及 `Table` 类生成的时候忽略某些属性,你可以给你的属性添加 `kotlinx.serialization.Transient` 注解。

## 接下来

Expand Down
3 changes: 2 additions & 1 deletion sqllin-dsl/doc/getting-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ The `@DBRow`'s param `tableName` represents the table name in Database, please e
the correct value. If you don't pass the parameter manually, _sqllin-processor_ will use the class
name as table name, for example, `Person`'s default table name is "Person".

In _sqllin-dsl_, objects are serialized to SQL and deserialized from cursor depend on _kotlinx.serialization_. So, you also need to add the `@Serializable` onto your data classes.
In _sqllin-dsl_, objects are serialized to SQL and deserialized from cursor depend on _kotlinx.serialization_. So, you also need to add the `@Serializable` onto your data classes. Therefore, if
you want to ignore some properties when serialization or deserialization and `Table` classes generation, you can annotate your properties with `kotlinx.serialization.Transient`.

## Next Step

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import com.ctrip.sqllin.dsl.sql.clause.OrderByWay.ASC
import com.ctrip.sqllin.dsl.sql.clause.OrderByWay.DESC
import com.ctrip.sqllin.dsl.sql.statement.SelectStatement
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlin.test.assertEquals
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.ctrip.sqllin.dsl

import com.ctrip.sqllin.dsl.annotation.DBRow
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient

/**
* Test whether the sqllin-processor could generate primitive type and String correctly
Expand All @@ -40,4 +41,5 @@ data class TestPrimitiveTypeForKSP(
val testBoolean: Boolean?,
val testChar: Char?,
val testString: String,
@Transient val testTransient: Int = 0,
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.ctrip.sqllin.processor

import com.google.devtools.ksp.getClassDeclarationByName
import com.google.devtools.ksp.processing.Dependencies
import com.google.devtools.ksp.processing.Resolver
import com.google.devtools.ksp.processing.SymbolProcessor
Expand All @@ -36,6 +37,7 @@ class ClauseProcessor(
private companion object {
const val ANNOTATION_DATABASE_ROW_NAME = "com.ctrip.sqllin.dsl.annotation.DBRow"
const val ANNOTATION_SERIALIZABLE = "kotlinx.serialization.Serializable"
const val ANNOTATION_TRANSIENT = "kotlinx.serialization.Transient"
}

@Suppress("UNCHECKED_CAST")
Expand All @@ -44,7 +46,7 @@ class ClauseProcessor(
val invalidateDBRowClasses = allDBRowClasses.filter { !it.validate() }.toList()

val validateDBRowClasses = allDBRowClasses.filter { it.validate() } as Sequence<KSClassDeclaration>
val serializableType = resolver.getClassDeclarationByName(resolver.getKSNameFromString(ANNOTATION_SERIALIZABLE))!!.asStarProjectedType()
val serializableType = resolver.getClassDeclarationByName(ANNOTATION_SERIALIZABLE)!!.asStarProjectedType()

for (classDeclaration in validateDBRowClasses) {

Expand Down Expand Up @@ -80,7 +82,10 @@ class ClauseProcessor(
writer.write(" override fun kSerializer() = $className.serializer()\n\n")

writer.write(" inline operator fun <R> invoke(block: $objectName.(table: $objectName) -> R): R = this.block(this)\n\n")
classDeclaration.getAllProperties().forEachIndexed { index, property ->
val transientName = resolver.getClassDeclarationByName(ANNOTATION_TRANSIENT)!!.asStarProjectedType()
classDeclaration.getAllProperties().filter { classDeclaration ->
!classDeclaration.annotations.any { ksAnnotation -> ksAnnotation.annotationType.resolve().isAssignableFrom(transientName) }
}.forEachIndexed { index, property ->
val clauseElementTypeName = getClauseElementTypeStr(property) ?: return@forEachIndexed
val propertyName = property.simpleName.asString()
val elementName = "$className.serializer().descriptor.getElementName($index)"
Expand Down

0 comments on commit 4872fdd

Please sign in to comment.