Introduce KSP compiler for generating columns via @Selectable annotation#769
Open
jan-tennert wants to merge 19 commits intomasterfrom
Open
Introduce KSP compiler for generating columns via @Selectable annotation#769jan-tennert wants to merge 19 commits intomasterfrom
@Selectable annotation#769jan-tennert wants to merge 19 commits intomasterfrom
Conversation
jan-tennert
commented
Oct 31, 2024
| 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 |
Collaborator
Author
There was a problem hiding this comment.
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. |
Collaborator
Author
|
@grdsdev Update on this? |
1e3f6de to
f93b1fc
Compare
Collaborator
Author
|
@grdsdev Would it be possible to merge this as experimental? I think a lot of people would love to try this out. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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