Skip to content

Conversation

@stephencelis
Copy link
Member

@stephencelis stephencelis commented Apr 29, 2025

Currently, the various query representable wrappers must be used a very specific way when dealing with optionals, where the optional must be on the representation type, not the type being represented:

@Column(as: Date.ISO8601Representation?.self)  // ✅
var date: Date?

@Column(as: Date?.ISO8601Representation.self)  // ❌
var date: Date?

This PR adds a few helper type aliases to address this issue, so both now compile and do the right thing:

@Column(as: Date.ISO8601Representation?.self)  // ✅
var date: Date?

@Column(as: Date?.ISO8601Representation.self)  // ✅
var date: Date?

It also renames JSONRepresentation to Codable.JSONRepresentation, deprecating the former spelling. This also allows the optionality to be placed either place:

@Column(as: JSONRepresentation<Notes>?.self)  // ⚠️
var notes: Notes?

@Column(as: JSONRepresentation<Notes?>.self)  // ❌
var notes: Notes?

@Column(as: Notes.JSONRepresentation?.self)   // ✅
var notes: Notes?

@Column(as: Notes?.JSONRepresentation.self)   // ✅
var notes: Notes?

Currently, the various query representable wrappers must be used a very
specific way when dealing with optionals, where the optional must be on
the representation type, not the type being represented:

```swift
@column(as: Date.ISO8601Representation?.self)  // ✅
var date: Date?

@column(as: Date?.ISO8601Representation.self)  // ❌
var date: Date?
```

This PR adds a few helper type aliases to address this issue, so both
now compile and do the right thing:

```swift
@column(as: Date.ISO8601Representation?.self)  // ✅
var date: Date?

@column(as: Date?.ISO8601Representation.self)  // ✅
var date: Date?
```

It also renames `JSONRepresentation` to `Codable.JSONRepresentation`,
deprecating the former spelling. This also allows the optionality to be
placed either place:

```swift
@column(as: Notes.JSONRepresentation?.self)  // ✅
var notes: Notes?

@column(as: Notes?.JSONRepresentation.self)  // ✅
var notes: Notes?
```
@stephencelis stephencelis requested a review from mbrandonw April 29, 2025 23:49
@stephencelis stephencelis merged commit d79717f into main Apr 30, 2025
2 checks passed
@stephencelis stephencelis deleted the representation-cleanup branch April 30, 2025 15:44
coenttb pushed a commit to coenttb/swift-structured-queries-postgres that referenced this pull request Oct 14, 2025
Currently, the various query representable wrappers must be used a very
specific way when dealing with optionals, where the optional must be on
the representation type, not the type being represented:

```swift
@column(as: Date.ISO8601Representation?.self)  // ✅
var date: Date?

@column(as: Date?.ISO8601Representation.self)  // ❌
var date: Date?
```

This PR adds a few helper type aliases to address this issue, so both
now compile and do the right thing:

```swift
@column(as: Date.ISO8601Representation?.self)  // ✅
var date: Date?

@column(as: Date?.ISO8601Representation.self)  // ✅
var date: Date?
```

It also renames `JSONRepresentation` to `Codable.JSONRepresentation`,
deprecating the former spelling. This also allows the optionality to be
placed either place:

```swift
@column(as: Notes.JSONRepresentation?.self)  // ✅
var notes: Notes?

@column(as: Notes?.JSONRepresentation.self)  // ✅
var notes: Notes?
```
coenttb pushed a commit to coenttb/swift-structured-queries-postgres that referenced this pull request Oct 15, 2025
Currently, the various query representable wrappers must be used a very
specific way when dealing with optionals, where the optional must be on
the representation type, not the type being represented:

```swift
@column(as: Date.ISO8601Representation?.self)  // ✅
var date: Date?

@column(as: Date?.ISO8601Representation.self)  // ❌
var date: Date?
```

This PR adds a few helper type aliases to address this issue, so both
now compile and do the right thing:

```swift
@column(as: Date.ISO8601Representation?.self)  // ✅
var date: Date?

@column(as: Date?.ISO8601Representation.self)  // ✅
var date: Date?
```

It also renames `JSONRepresentation` to `Codable.JSONRepresentation`,
deprecating the former spelling. This also allows the optionality to be
placed either place:

```swift
@column(as: Notes.JSONRepresentation?.self)  // ✅
var notes: Notes?

@column(as: Notes?.JSONRepresentation.self)  // ✅
var notes: Notes?
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants