-
-
Notifications
You must be signed in to change notification settings - Fork 87
feat: add PostgresRowSequence.getColumns() to get column metadata #577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/// Information of a column. | ||
// | ||
// This type has the same definition as `RowDescription.column`, we need to keep | ||
// that type private so we defines this type. | ||
public struct PostgresColumn: Hashable, Sendable { | ||
/// The column name. | ||
public let name: String | ||
|
||
/// If the field can be identified as a column of a specific table, the object ID of the table; otherwise zero. | ||
public let tableOID: Int32 | ||
|
||
/// If the field can be identified as a column of a specific table, the attribute number of the column; otherwise zero. | ||
public let columnAttributeNumber: Int16 | ||
|
||
/// The object ID of the field's data type. | ||
public let dataType: PostgresDataType | ||
|
||
/// The data type size (see pg_type.typlen). Note that negative values denote variable-width types. | ||
public let dataTypeSize: Int16 | ||
|
||
/// The type modifier (see pg_attribute.atttypmod). The meaning of the modifier is type-specific. | ||
public let dataTypeModifier: Int32 | ||
|
||
/// The format being used for the field. Currently will be text or binary. In a RowDescription returned | ||
/// from the statement variant of Describe, the format code is not yet known and will always be text. | ||
public let format: PostgresFormat | ||
|
||
|
||
internal init( | ||
name: String, | ||
tableOID: Int32, | ||
columnAttributeNumber: Int16, | ||
dataType: PostgresDataType, | ||
dataTypeSize: Int16, | ||
dataTypeModifier: Int32, | ||
format: PostgresFormat | ||
) { | ||
self.name = name | ||
self.tableOID = tableOID | ||
self.columnAttributeNumber = columnAttributeNumber | ||
self.dataType = dataType | ||
self.dataTypeSize = dataTypeSize | ||
self.dataTypeModifier = dataTypeModifier | ||
self.format = format | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,21 @@ public struct PostgresRowSequence: AsyncSequence, Sendable { | |
columns: self.columns | ||
) | ||
} | ||
|
||
/// Get the column information of the query results. | ||
public func getColumns() -> [PostgresColumn] { | ||
self.columns.map { column in | ||
PostgresColumn( | ||
name: column.name, | ||
tableOID: column.tableOID, | ||
columnAttributeNumber: column.columnAttributeNumber, | ||
dataType: column.dataType, | ||
dataTypeSize: column.dataTypeSize, | ||
dataTypeModifier: column.dataTypeModifier, | ||
format: column.format | ||
) | ||
} | ||
} | ||
Comment on lines
+30
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an O(n) call. Where Example:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we do the above we can just add a get only property: var columns: PostgresColumns {
PostgresColumns(underlying: self.columns)
} |
||
} | ||
|
||
extension PostgresRowSequence { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we back this with a
RowDescription.Column
please. Instead of let properties please lets use computed properties.Example: