-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
Introduce KSP compiler for generating columns via @Selectable
annotation
#769
Open
jan-tennert
wants to merge
19
commits into
master
Choose a base branch
from
postgrest-column-ksp
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains 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
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 |
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. |
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
@Selectable
annotated 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:install(Postgrest) { addSelectableTypes() }
Design details
There are 6 annotations:
@Serializable
- 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 aString
then the column will be cast to atext
)Todo:
[ ] Find a solution for spreading embedded resources- Will be unsupported for nowkotlin-compile-testing
in the futureImplementation
There is a new Postgrest config property
columnRegistry
which 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