Skip to content

Commit d62963e

Browse files
committed
Hold onto a column's default value
We should retain this info for folks that want to dynamically generate certain queries, like `CREATE TABLE` statements.
1 parent aaf9d71 commit d62963e

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

Sources/StructuredQueriesCore/PrimaryKeyed.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ where QueryValue: PrimaryKeyedTable {
2525
/// A type representing this table's primary key.
2626
///
2727
/// For auto-incrementing tables, this is typically `Int`.
28-
associatedtype PrimaryKey: QueryBindable where PrimaryKey.QueryValue == PrimaryKey
28+
associatedtype PrimaryKey: QueryBindable
29+
where PrimaryKey.QueryValue == PrimaryKey, PrimaryKey.QueryValue.QueryOutput: Sendable
2930

3031
/// The column representing this table's primary key.
3132
var primaryKey: TableColumn<QueryValue, PrimaryKey> { get }

Sources/StructuredQueriesCore/TableColumn.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ public protocol TableColumnExpression<Root, Value>: QueryExpression where Value
99
/// The name of the table column.
1010
var name: String { get }
1111

12+
/// The default value of the table column.
13+
var defaultValue: Value.QueryOutput? { get }
14+
1215
/// The table model key path associated with this table column.
1316
var keyPath: KeyPath<Root, Value.QueryOutput> { get }
1417

@@ -24,10 +27,13 @@ public protocol TableColumnExpression<Root, Value>: QueryExpression where Value
2427
public struct TableColumn<Root: Table, Value: QueryRepresentable & QueryBindable>:
2528
TableColumnExpression,
2629
Sendable
27-
{
30+
where Value.QueryOutput: Sendable {
2831
public typealias QueryValue = Value
2932

3033
public let name: String
34+
35+
public let defaultValue: Value.QueryOutput?
36+
3137
let _keyPath: KeyPath<Root, Value.QueryOutput> & Sendable
3238

3339
public var keyPath: KeyPath<Root, Value.QueryOutput> {
@@ -37,18 +43,20 @@ public struct TableColumn<Root: Table, Value: QueryRepresentable & QueryBindable
3743
public init(
3844
_ name: String,
3945
keyPath: KeyPath<Root, Value.QueryOutput> & Sendable,
40-
default: Value.QueryOutput? = nil
46+
default defaultValue: Value.QueryOutput? = nil
4147
) {
4248
self.name = name
49+
self.defaultValue = defaultValue
4350
self._keyPath = keyPath
4451
}
4552

4653
public init(
4754
_ name: String,
4855
keyPath: KeyPath<Root, Value.QueryOutput> & Sendable,
49-
default: Value? = nil
56+
default defaultValue: Value? = nil
5057
) where Value == Value.QueryOutput {
5158
self.name = name
59+
self.defaultValue = defaultValue
5260
self._keyPath = keyPath
5361
}
5462

0 commit comments

Comments
 (0)