Skip to content

Commit

Permalink
Support bulk table schema queries
Browse files Browse the repository at this point in the history
...
  • Loading branch information
helje5 committed Dec 2, 2024
1 parent 9c0f562 commit 5424797
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
7 changes: 7 additions & 0 deletions Sources/PostgreSQLAdaptor/PostgreSQLAdaptorChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,13 @@ open class PostgreSQLAdaptorChannel : AdaptorChannel, SmartDescription {
return try PostgreSQLModelFetch(channel: self)
.describeEntityWithTableName(table)
}
@inlinable
public func describeEntitiesWithTableNames(_ tableNames: [ String ])
throws -> [ Entity ]
{
return try PostgreSQLModelFetch(channel: self)
.describeEntitiesWithTableNames(tableNames)
}


// MARK: - Insert w/ auto-increment support
Expand Down
12 changes: 8 additions & 4 deletions Sources/PostgreSQLAdaptor/PostgreSQLModelFetch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// ZeeQL3Apache
//
// Created by Helge Hess on 14/04/17.
// Copyright © 2017 ZeeZide GmbH. All rights reserved.
// Copyright © 2017-2024 ZeeZide GmbH. All rights reserved.
//

import ZeeQL
Expand Down Expand Up @@ -106,7 +106,7 @@ open class PostgreSQLModelFetch: AdaptorModelFetch {
}

public func describeEntitiesWithTableNames(_ tables: [ String ]) throws
-> [ Entity ]
-> [ Entity ]
{
guard !tables.isEmpty else { return [] }

Expand Down Expand Up @@ -294,11 +294,14 @@ open class PostgreSQLModelFetch: AdaptorModelFetch {
}

public func describeEntityWithTableName(_ table: String) throws -> Entity {
guard let entity = try describeEntitiesWithTableNames([table]).first
else { throw Error.DidNotFindTable(table) }
guard let entity = try describeEntitiesWithTableNames([table]).first else {
throw Error.DidNotFindTable(table)
}
return entity
}

// This is not used anymore, but rather `describeEntitiesWithTableNames`
#if false
func _fetchPGColumnsOfTable(_ table: String) throws -> [ AdaptorRecord ] {
/* Sample result:
* attnum | colname | exttype | attlen | attnotnull
Expand All @@ -324,6 +327,7 @@ open class PostgreSQLModelFetch: AdaptorModelFetch {
" AND c.relname='\(table)' ORDER BY attnum;";
return try channel.querySQL(sql)
}
#endif

func _fetchPGPrimaryKeyNamesOfTable(_ table: String) throws -> [ String ] {
guard !table.isEmpty else { return [] }
Expand Down

0 comments on commit 5424797

Please sign in to comment.