@@ -38,7 +38,7 @@ public class SchemaReader {
3838 public func objectDefinitions( name: String ? = nil ,
3939 type: ObjectDefinition . ObjectType ? = nil ,
4040 temp: Bool = false ) throws -> [ ObjectDefinition ] {
41- var query : QueryType = connection . schemaTable ( temp: temp)
41+ var query : QueryType = SchemaTable . get ( for : connection , temp: temp)
4242 if let name = name {
4343 query = query. where ( SchemaTable . nameColumn == name)
4444 }
@@ -125,22 +125,30 @@ public class SchemaReader {
125125 }
126126}
127127
128- private class SchemaTable {
129- internal static let name = Table ( " sqlite_schema " , database: " main " )
130- internal static let tempName = Table ( " sqlite_schema " , database: " temp " )
128+ private enum SchemaTable {
129+ private static let name = Table ( " sqlite_schema " , database: " main " )
130+ private static let tempName = Table ( " sqlite_schema " , database: " temp " )
131+ // legacy names (< 3.33.0)
132+ private static let masterName = Table ( " sqlite_master " )
133+ private static let tempMasterName = Table ( " sqlite_temp_master " )
131134
132- // legacy table names
133- internal static let masterName = Table ( " sqlite_master " )
134- internal static let tempMasterName = Table ( " sqlite_temp_master " )
135+ static func get( for connection: Connection , temp: Bool = false ) -> Table {
136+ if connection. supports ( . sqliteSchemaTable) {
137+ return temp ? SchemaTable . tempName : SchemaTable . name
138+ } else {
139+ return temp ? SchemaTable . tempMasterName : SchemaTable . masterName
140+ }
141+ }
135142
143+ // columns
136144 static let typeColumn = Expression < String > ( " type " )
137145 static let nameColumn = Expression < String > ( " name " )
138146 static let tableNameColumn = Expression < String > ( " tbl_name " )
139147 static let rootPageColumn = Expression < Int64 ? > ( " rootpage " )
140148 static let sqlColumn = Expression < String ? > ( " sql " )
141149}
142150
143- private class TableInfoTable {
151+ private enum TableInfoTable {
144152 static let idColumn = Expression < Int64 > ( " cid " )
145153 static let nameColumn = Expression < String > ( " name " )
146154 static let typeColumn = Expression < String > ( " type " )
@@ -149,7 +157,7 @@ private class TableInfoTable {
149157 static let primaryKeyColumn = Expression < Int64 ? > ( " pk " )
150158}
151159
152- private class IndexInfoTable {
160+ private enum IndexInfoTable {
153161 // The rank of the column within the index. (0 means left-most.)
154162 static let seqnoColumn = Expression < Int64 > ( " seqno " )
155163 // The rank of the column within the table being indexed.
@@ -159,7 +167,7 @@ private class IndexInfoTable {
159167 static let nameColumn = Expression < String ? > ( " name " )
160168}
161169
162- private class IndexListTable {
170+ private enum IndexListTable {
163171 // A sequence number assigned to each index for internal tracking purposes.
164172 static let seqColumn = Expression < Int64 > ( " seq " )
165173 // The name of the index
@@ -174,7 +182,7 @@ private class IndexListTable {
174182 static let partialColumn = Expression < Int64 > ( " partial " )
175183}
176184
177- private class ForeignKeyListTable {
185+ private enum ForeignKeyListTable {
178186 static let idColumn = Expression < Int64 > ( " id " )
179187 static let seqColumn = Expression < Int64 > ( " seq " )
180188 static let tableColumn = Expression < String > ( " table " )
@@ -184,13 +192,3 @@ private class ForeignKeyListTable {
184192 static let onDeleteColumn = Expression < String > ( " on_delete " )
185193 static let matchColumn = Expression < String > ( " match " )
186194}
187-
188- private extension Connection {
189- func schemaTable( temp: Bool = false ) -> Table {
190- if supports ( . sqliteSchemaTable) {
191- return temp ? SchemaTable . tempName : SchemaTable . name
192- } else {
193- return temp ? SchemaTable . tempMasterName : SchemaTable . masterName
194- }
195- }
196- }
0 commit comments