Skip to content

Column count and names #5

@BillBuilt

Description

@BillBuilt

Hello,

I'm way out of my normal wheelhouse here. I'm new to Swift and Xcode, so package management is something I have yet to dive into, so I apologize for my ignorance of the subject upfront.

It seems like this package is missing a couple of key components however, to help build out a more usable library.

If there were a method that could return the row's column count and also one to return the column name at index i, then it would be reasonably straightforward to write a DB manager that could return query results as an array of maps, indexed by column name, to then be used however is needed.

[0] -> {name:"value", amt: 123)
[1] -> {name:"other value", amt: 0)

I checked out the lib locally, added the 2 methods to it but have no idea how to actually use it so I was hoping I could request that something like this be added?

The 2 methods I came up with to add to the Row() class are below, however i was not able to test them (libsql_row_name and libsql_row_length already exist...)

	public func getColumnName(_ index: Int32) throws -> String {
		let result = libsql_row_name(self.inner, index)
		return result.ptr.assumingMemoryBound(to: UInt8.self).withMemoryRebound(to: Int8.self, capacity: Int(result.len)) {
			String(cString: $0)
		}
		
	}
	public func getColumnCount() throws -> Int32 {
		let result = libsql_row_length(self.inner)
		return result
		
	}

This would allow for more flexibility when writing queries since the fields can be in any order, rearranged at will, added/removed, etc w/o needing to refactor any rigid value mapping based on the "current" query and the column index value.

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions