-
Notifications
You must be signed in to change notification settings - Fork 5
Reduce usage of "Any" #154
base: main
Are you sure you want to change the base?
Conversation
|
Hi @hiimtmac, Thanks for your interest in There is actually a way to use mixed parameter types even in the current version: func testMixedTypeParam() throws {
let params: [String: Any] = [
"1": "One",
"2": KuzuInt64Wrapper(value: 2),
]
let preparedStatement = try conn.prepare("RETURN $1, $2")
let result = try conn.execute(preparedStatement, params)
XCTAssert(result.hasNext())
let row = try result.getNext()!
XCTAssertEqual(try! row.getValue(0) as! String, "One")
XCTAssertEqual(try! row.getValue(1) as! Int64, 2)
}However, I do agree that your approach of allowing primitive types is more erganomic and intuitive. I am a bit concerned about the compatibility though due to the use of upcoming feature and bumping min version to 6.0 |
|
Happy to bump it back down to 5.9 (not using any specific features from 6.0 and anything I did builds fine with 5.9 - just figured with 6.2 released may as well). I can also remove the |
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.
Pull Request Overview
This PR introduces a typed encoding/decoding system to reduce usage of "Any" types in the kuzu-swift library, enabling heterogeneous parameter binding in prepared statements. The changes allow users to pass parameters of different types in the same dictionary without generic type constraints.
Key changes:
- Adds
@_spi(Typed)protocolsKuzuEncodableandKuzuDecodablefor type-safe value conversion - Introduces a new
execute_method that accepts[String: any KuzuEncodable]parameters - Includes comprehensive type system support for primitives, collections, and complex Kuzu types
Reviewed Changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/kuzu-swiftTests/TypedTests.swift | Test suite demonstrating typed parameter binding and value extraction |
| Sources/Kuzu/KuzuEncodable.swift | Encoding protocols and implementations for Swift types to Kuzu values |
| Sources/Kuzu/KuzuDecodable.swift | Decoding protocols and implementations for Kuzu values to Swift types |
| Sources/Kuzu/Types+Extensions.swift | Core type definitions and data type mappings |
| Sources/Kuzu/Connection+Extensions.swift | New execute_ method using typed parameters |
| Sources/Kuzu/FlatTuple+Extensions.swift | Typed subscript accessors for result tuples |
| Package.swift | Swift 6.0 upgrade and ExistentialAny feature enablement |
| Multiple source files | Import visibility changes from @_implementationOnly to public |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| let blobSize = strlen(cBlobValue) | ||
| let blobData = Data(bytes: cBlobValue, count: blobSize) |
Copilot
AI
Sep 26, 2025
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.
Using strlen on binary data is incorrect as it will stop at the first null byte. Use the actual blob size from the Kuzu API instead.
| let blobSize = strlen(cBlobValue) | |
| let blobData = Data(bytes: cBlobValue, count: blobSize) | |
| let blobSize = kuzu_value_get_blob_size(container.ptr) | |
| let blobData = Data(bytes: cBlobValue, count: Int(blobSize)) |
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.
That function doesn't exist
|
@mewim I reverted the |
Hello! Thank you for this project, Kuzu is great.
I'm not sure if I was "holding it wrong" but it seems the existing execute
Is limiting in that T can only be one type, so I havent found a way to nicely bind arguments of heterogeneous types. For example:
I added some functionality (guarded for now under
@_spi(Typed)) for encoding and decoding types, which allows for encoding/decoding on linux to follow the same paths as the Darwin platforms (no need for the wrapper types). You can see usage in theTypedTests.swifttest file.If this is something of interest to the maintainers Im happy to adjust as needed to your liking!