-
Notifications
You must be signed in to change notification settings - Fork 16
feat: add databaseInitialized attribute to @Column macro to force optional on Draft properties #36
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: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,11 +34,13 @@ public macro Table(_ name: String? = nil) = | |
/// - representableType: A type that represents the property type in a query expression. For types | ||
/// that don't have a single representation in SQL, like `Date` and `UUID`. | ||
/// - primaryKey: The column is its table's auto-incrementing primary key. | ||
/// - databaseInitialized: The column has a default value and is not needed in an insert statement. | ||
@attached(accessor, names: named(willSet)) | ||
public macro Column( | ||
_ name: String? = nil, | ||
as representableType: (any QueryRepresentable.Type)? = nil, | ||
primaryKey: Bool = false | ||
primaryKey: Bool? = nil, | ||
databaseInitialized: Bool? = nil | ||
Comment on lines
+42
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the spirit of the above comment, I think these parameters could stay |
||
) = | ||
#externalMacro( | ||
module: "StructuredQueriesMacros", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,4 +37,13 @@ extension PatternBindingSyntax { | |
optionalized.typeAnnotation?.type = optionalType | ||
return optionalized | ||
} | ||
|
||
func isOptional() -> Bool { | ||
// x: Optional<T> or x: T? | ||
if self.typeAnnotation?.type.isOptionalType == true { return true } | ||
// Missing cases | ||
// x = Optional<T>.some(_) | ||
// x = fnReturningOptionalType() | ||
Comment on lines
+44
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this helper mostly here to mark these cases as todos? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I forgot to mention in the PR description, but I was wondering if it's worth it trying to do anything to figure out if a type is actually Optional or not. I was getting in a rabbit hole and left it as is to not waste too much time and get some input. It doesn't seem worth it IMO, but I left there to inform that |
||
return false | ||
} | ||
} |
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.
One idea to simplify the diagnostics you added in the macro for nonsensical combinations of these two parameters would be to instead introduce an overload of
@Column
that simply takes thedatabaseInitialized
parameter. That way it's impossible to invoke@Column
with both parameters.