Skip to content

Commit 4872fdd

Browse files
authored
Merge pull request #96 from qiaoyuang/main
Update to 1.3.2
2 parents 7a4c4a2 + dbff05f commit 4872fdd

File tree

7 files changed

+29
-8
lines changed

7 files changed

+29
-8
lines changed

CHANGELOG.md

+14
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

33
- Date format: YYYY-MM-dd
44

5+
## v1.3.2 / 2024-06-18
6+
7+
### All
8+
9+
* Update `Kotlin`'s version to `1.9.24`
10+
11+
### sqllin-dsl
12+
13+
* 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.
14+
15+
### sqllin-processor
16+
17+
* Update `KSP`'s version to `1.9.24-1.0.20`
18+
519
## v1.3.1 / 2024-04-24
620

721
### sqllin-dsl

gradle.properties

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
VERSION=1.3.1
1+
VERSION=1.3.2
22
GROUP=com.ctrip.kotlin
33

4-
kotlinVersion=1.9.23
5-
kspVersion=1.9.23-1.0.20
4+
kotlinVersion=1.9.24
5+
kspVersion=1.9.24-1.0.20
66
serializationVersion=1.6.3
77
coroutinesVersion=1.8.0
88
androidxAnnotationVersion=1.7.1

sqllin-dsl/doc/getting-start-cn.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ data class Person(
154154
将会使用类名作为表名,比如 `Person` 类的默认表名是"Person"。
155155

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

159159
## 接下来
160160

sqllin-dsl/doc/getting-start.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ The `@DBRow`'s param `tableName` represents the table name in Database, please e
164164
the correct value. If you don't pass the parameter manually, _sqllin-processor_ will use the class
165165
name as table name, for example, `Person`'s default table name is "Person".
166166

167-
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.
167+
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
168+
you want to ignore some properties when serialization or deserialization and `Table` classes generation, you can annotate your properties with `kotlinx.serialization.Transient`.
168169

169170
## Next Step
170171

sqllin-dsl/src/commonTest/kotlin/com/ctrip/sqllin/dsl/CommonBasicTest.kt

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import com.ctrip.sqllin.dsl.sql.clause.OrderByWay.ASC
2424
import com.ctrip.sqllin.dsl.sql.clause.OrderByWay.DESC
2525
import com.ctrip.sqllin.dsl.sql.statement.SelectStatement
2626
import kotlinx.coroutines.Dispatchers
27-
import kotlinx.coroutines.delay
2827
import kotlinx.coroutines.launch
2928
import kotlinx.coroutines.runBlocking
3029
import kotlin.test.assertEquals

sqllin-dsl/src/commonTest/kotlin/com/ctrip/sqllin/dsl/TestPrimitiveTypeForKSP.kt

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package com.ctrip.sqllin.dsl
1818

1919
import com.ctrip.sqllin.dsl.annotation.DBRow
2020
import kotlinx.serialization.Serializable
21+
import kotlinx.serialization.Transient
2122

2223
/**
2324
* Test whether the sqllin-processor could generate primitive type and String correctly
@@ -40,4 +41,5 @@ data class TestPrimitiveTypeForKSP(
4041
val testBoolean: Boolean?,
4142
val testChar: Char?,
4243
val testString: String,
44+
@Transient val testTransient: Int = 0,
4345
)

sqllin-processor/src/main/kotlin/com/ctrip/sqllin/processor/ClauseProcessor.kt

+7-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.ctrip.sqllin.processor
1818

19+
import com.google.devtools.ksp.getClassDeclarationByName
1920
import com.google.devtools.ksp.processing.Dependencies
2021
import com.google.devtools.ksp.processing.Resolver
2122
import com.google.devtools.ksp.processing.SymbolProcessor
@@ -36,6 +37,7 @@ class ClauseProcessor(
3637
private companion object {
3738
const val ANNOTATION_DATABASE_ROW_NAME = "com.ctrip.sqllin.dsl.annotation.DBRow"
3839
const val ANNOTATION_SERIALIZABLE = "kotlinx.serialization.Serializable"
40+
const val ANNOTATION_TRANSIENT = "kotlinx.serialization.Transient"
3941
}
4042

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

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

4951
for (classDeclaration in validateDBRowClasses) {
5052

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

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

0 commit comments

Comments
 (0)