Docs: DocC prepared statements examples + PostgresCodable schema hints; fix tuple decoding in test#594
Docs: DocC prepared statements examples + PostgresCodable schema hints; fix tuple decoding in test#594zamderax wants to merge 6 commits intovapor:mainfrom
Conversation
gwynne
left a comment
There was a problem hiding this comment.
Several initial nits. I haven't bothered including notes on every single line where double-backticks were missing or - Note:-style callouts were used instead of > Note:, it'd take me a lot longer to do that in the PR interface than it'd take anyone to just fix it in Xcode or such.
| /// - Throws: The error of the decoding implementation. See also `PSQLDecodable` protocol for this. | ||
| /// - Returns: The decoded value of Type T. | ||
| func decode<T: PostgresDecodable, JSONDecoder: PostgresJSONDecoder>( | ||
| public func decode<T: PostgresDecodable, JSONDecoder: PostgresJSONDecoder>( |
| /// - Throws: The error of the decoding implementation. See also `PSQLDecodable` protocol for this. | ||
| /// - Returns: The decoded value of Type T. | ||
| func decode<T: PostgresDecodable, JSONDecoder: PostgresJSONDecoder>( | ||
| public func decode<T: PostgresDecodable, JSONDecoder: PostgresJSONDecoder>( |
| /// } | ||
| /// ``` | ||
| /// | ||
| /// - Note: `PostgresNonThrowingEncodable` is a variant that doesn't throw, allowing usage without `try`. |
There was a problem hiding this comment.
| /// - Note: `PostgresNonThrowingEncodable` is a variant that doesn't throw, allowing usage without `try`. | |
| /// > Note: ``PostgresNonThrowingEncodable`` is a variant that doesn't throw, allowing usage without `try`. |
| /// A type that can decode itself from a postgres wire binary representation. | ||
| /// | ||
| /// If you want to conform a type to PostgresDecodable you must implement the decode method. | ||
| /// Conform your custom types to `PostgresDecodable` to enable them to be decoded from query results. |
There was a problem hiding this comment.
| /// Conform your custom types to `PostgresDecodable` to enable them to be decoded from query results. | |
| /// Conform your custom types to ``PostgresDecodable`` to enable them to be decoded from query results. |
| /// | ||
| /// ## Conforming Built-in Types | ||
| /// | ||
| /// Many standard Swift types already conform to `PostgresDecodable`: |
There was a problem hiding this comment.
| /// Many standard Swift types already conform to `PostgresDecodable`: | |
| /// Many standard Swift types already conform to ``PostgresDecodable``: |
| /// // Returns nil if the database value is NULL | ||
| /// ``` | ||
| /// | ||
| /// - Note: The `_DecodableType` associated type is an implementation detail for Optional handling. |
There was a problem hiding this comment.
| /// - Note: The `_DecodableType` associated type is an implementation detail for Optional handling. | |
| /// > Note: The `_DecodableType` associated type is an implementation detail for `Optional` handling. |
| /// - Note: String interpolation is the recommended approach for simple queries as it automatically handles parameter counting and binding. | ||
| /// - Warning: Always use parameter binding for user input. Never concatenate user input directly into SQL strings. |
There was a problem hiding this comment.
| /// - Note: String interpolation is the recommended approach for simple queries as it automatically handles parameter counting and binding. | |
| /// - Warning: Always use parameter binding for user input. Never concatenate user input directly into SQL strings. | |
| /// > Note: String interpolation is the recommended approach for simple queries as it automatically handles parameter counting and binding. | |
| /// | |
| /// > Warning: Always use parameter binding for user input. Never concatenate user input directly into SQL strings. |
|
Great I made a bunch of commits to address these. |
| @@ -0,0 +1,442 @@ | |||
| # PostgresCodable | |||
There was a problem hiding this comment.
This is a pretty, pretty great doc!
In an ideal case we would put the swift sections into Snippets to ensure they continue to build.
- Added a new section on manual query construction using `PostgresBindings` in the README.md. - Introduced a new `PostgresCodable` documentation file detailing how to encode and decode custom Swift types. - Enhanced the `PostgresQuery` documentation with examples of string interpolation and dynamic query building. - Updated `.gitignore` to include `.derivedData`. - Added integration tests for JSONB encoding and decoding functionality in `PostgresClientTests.swift`.
- Updated `decode` methods in `PostgresRandomAccessRow` to be public for better accessibility. - Modified documentation examples to utilize `makeRandomAccess()` for decoding rows, ensuring consistency and clarity. - Added new examples demonstrating the use of Codable structs with JSONB in the documentation. - Introduced integration tests for JSONB encoding/decoding functionality, validating the round-trip of nested Codable structs.
…ansaction; tests: decode multi-column rows via tuple in PostgresCodable test
- Replace row.makeRandomAccess() pattern with direct tuple decoding - Remove misleading "better performance" claim from withConnection docs - Add PostgresCodable conformance to UserProfile example
c1db220 to
abc514b
Compare
|
Thanks Fabian, I made some adjustments based on your comments |
PostgresPreparedStatementand demonstrates usage with.queryand.withTransaction.PostgresCodabledocs with minimal SQL schemas for each code snippet so readers know exactly what tables/columns are expected.Sources/PostgresNIO/Docs.docc/prepared-statement.md: New end‑to‑end examplesInsertUserandLoadUserprepared statements.querycallswithTransactionfor atomic sequencesSources/PostgresNIO/Docs.docc/postgres-codable.md: Add inline SQL schema hints for the examplesUsercodable,Company(JSONB),location(POINT), and enum/raw‑value examplesTests/IntegrationTests/PostgresCodableTests.swift: Decode multi‑column rows via tuple and then construct the model (avoids unsupported direct struct decoding)