File tree 2 files changed +38
-1
lines changed
2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ public class SchemaReader {
25
25
. map { ( row: Row ) -> ColumnDefinition in
26
26
ColumnDefinition (
27
27
name: row [ TableInfoTable . nameColumn] ,
28
- primaryKey: row [ TableInfoTable . primaryKeyColumn] == 1 ?
28
+ primaryKey: ( row [ TableInfoTable . primaryKeyColumn] ?? 0 ) > 0 ?
29
29
try parsePrimaryKey ( column: row [ TableInfoTable . nameColumn] ) : nil ,
30
30
type: ColumnDefinition . Affinity ( row [ TableInfoTable . typeColumn] ) ,
31
31
nullable: row [ TableInfoTable . notNullColumn] == 0 ,
Original file line number Diff line number Diff line change @@ -90,6 +90,43 @@ class SchemaReaderTests: SQLiteTestCase {
90
90
)
91
91
}
92
92
93
+ func test_columnDefinitions_composite_primary_keys( ) throws {
94
+ try db. run ( """
95
+ CREATE TABLE t (
96
+ col1 INTEGER,
97
+ col2 INTEGER,
98
+ col3 INTEGER,
99
+ PRIMARY KEY (col1, col2)
100
+ );
101
+ """ )
102
+
103
+ XCTAssertEqual (
104
+ try schemaReader. columnDefinitions ( table: " t " ) , [
105
+ ColumnDefinition (
106
+ name: " col1 " ,
107
+ primaryKey: . init( autoIncrement: false ) ,
108
+ type: . INTEGER,
109
+ nullable: true ,
110
+ defaultValue: . NULL,
111
+ references: nil ) ,
112
+ ColumnDefinition (
113
+ name: " col2 " ,
114
+ primaryKey: . init( autoIncrement: false ) ,
115
+ type: . INTEGER,
116
+ nullable: true ,
117
+ defaultValue: . NULL,
118
+ references: nil ) ,
119
+ ColumnDefinition (
120
+ name: " col3 " ,
121
+ primaryKey: nil ,
122
+ type: . INTEGER,
123
+ nullable: true ,
124
+ defaultValue: . NULL,
125
+ references: nil )
126
+ ]
127
+ )
128
+ }
129
+
93
130
func test_indexDefinitions_no_index( ) throws {
94
131
let indexes = try schemaReader. indexDefinitions ( table: " users " )
95
132
XCTAssertTrue ( indexes. isEmpty)
You can’t perform that action at this time.
0 commit comments