-
-
Notifications
You must be signed in to change notification settings - Fork 68
Introduce KSP compiler for generating columns via @Selectable annotation
#769
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
base: master
Are you sure you want to change the base?
Conversation
| val types = hashMapOf<String, String>() | ||
| symbols.forEach { symbol -> | ||
| val className = symbol.simpleName.asString() | ||
| val qualifiedName = symbol.simpleName.asString() //Kotlin JS doesn't support qualified names |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name clashes could be possible due to only using the simple name, but we cannot use qualified names because of Kotlin JS support.
|
Awesome @jan-tennert let me try to get roughly the same API in Swift before merging this ok? But it looks awesome. |
|
@grdsdev Update on this? |
1e3f6de to
f93b1fc
Compare
|
@grdsdev Would it be possible to merge this as experimental? I think a lot of people would love to try this out. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What kind of change does this PR introduce?
Feature
What is the new behavior?
New KSP compiler module which processes
@Selectableannotated data classes. I kept the KSP compiler more general, so if we ever want to add a new annotation, we can just use this module.How it works
Add the KSP compiler
Annotate your data models with
@Selectable:addSelectableTypes()method in the PostgrestConfig: (you need atleast one class annotated with@Selectablefor it to appear)install(Postgrest) { addSelectableTypes() }Design details
There are 6 annotations:
@Selectable- Data classes will be processed by the compiler and columns will be generated based of the constructor parameters.@ColumnName- Used to specify the actual column name when the parameter name differs. For foreign columns, this can be either the column name or foreign table.@JsonPath- Used to specify a Json Path to query a JSON column@Foreign- Used for foreign columns so the compiler knows that it has to generate nested columns@ApplyFunction- Used to apply an aggregate function@Cast- Used to cast a column to a type. If no type is specified, then auto casting will be attempted (e.g. if the parameter type is aStringthen the column will be cast to atext)Todo:
[ ] Find a solution for spreading embedded resources- Will be unsupported for nowkotlin-compile-testingin the futureImplementation
There is a new Postgrest config property
columnRegistrywhich stores column data under the full class name for annotated data classes. The KSP compiler fills this registry when the generatedaddSelectableTypes()method is called.Example for the generated method [Not visible normally]:
Additional context
See discussion in #761