Skip to content
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

Add @Statement macro #60

Merged
merged 9 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore:
- Sources/VendoredConnectionPoolModule/*
33 changes: 12 additions & 21 deletions Benchmarks/Package.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "bf919706c87a06ed1de06d4174a92e575d6393b41272bd8e776b44aedbb4dd15",
"originHash" : "4709ea0e148a99e46d2d966ab682e23fd487f2b5f594a1d88115218e80a8cc62",
"pins" : [
{
"identity" : "hdrhistogram-swift",
Expand Down Expand Up @@ -28,15 +28,6 @@
"version" : "1.0.0"
}
},
{
"identity" : "postgres-nio",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/postgres-nio.git",
"state" : {
"revision" : "5c268768890b062803a49f1358becc478f954265",
"version" : "1.21.5"
}
},
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -69,8 +60,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "ee97538f5b81ae89698fd95938896dec5217b148",
"version" : "1.1.1"
"revision" : "671108c96644956dddcd89dd59c203dcdb36cec7",
"version" : "1.1.4"
}
},
{
Expand All @@ -91,15 +82,6 @@
"version" : "1.6.1"
}
},
{
"identity" : "swift-metrics",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-metrics.git",
"state" : {
"revision" : "e0165b53d49b413dd987526b641e05e246782685",
"version" : "2.5.0"
}
},
{
"identity" : "swift-nio",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -145,6 +127,15 @@
"version" : "2.6.0"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swiftlang/swift-syntax.git",
"state" : {
"revision" : "cb53fa1bd3219b0b23ded7dfdd3b2baff266fd25",
"version" : "600.0.0"
}
},
{
"identity" : "swift-system",
"kind" : "remoteSourceControl",
Expand Down
21 changes: 15 additions & 6 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "9bf03ff58ce34478e66aaee630e491823326fd06",
"version" : "1.1.3"
"revision" : "671108c96644956dddcd89dd59c203dcdb36cec7",
"version" : "1.1.4"
}
},
{
"identity" : "swift-crypto",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-crypto.git",
"state" : {
"revision" : "9f95b4d033a4edd3814b48608db3f2ca90c7218b",
"version" : "3.7.0"
"revision" : "ffca28be3c9c6a86a579949d23f68818a4b9b5d8",
"version" : "3.8.0"
}
},
{
Expand All @@ -50,8 +50,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio.git",
"state" : {
"revision" : "9746cf80e29edfef2a39924a66731249223f42a3",
"version" : "2.72.0"
"revision" : "1b33db2dea6a64d5b619b9e888175133c6d7f410",
"version" : "2.73.0"
}
},
{
Expand Down Expand Up @@ -81,6 +81,15 @@
"version" : "2.6.1"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swiftlang/swift-syntax.git",
"state" : {
"revision" : "cb53fa1bd3219b0b23ded7dfdd3b2baff266fd25",
"version" : "600.0.0"
}
},
{
"identity" : "swift-system",
"kind" : "remoteSourceControl",
Expand Down
34 changes: 29 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
// Copyright 2024 Timo Zacherl
// SPDX-License-Identifier: Apache-2.0

import CompilerPluginSupport
import PackageDescription

let package = Package(
name: "oracle-nio",
platforms: [.macOS(.v13), .iOS(.v16), .tvOS(.v16), .watchOS(.v9), .visionOS(.v1)],
products: [
.library(name: "OracleNIO", targets: ["OracleNIO"])
.library(name: "OracleNIO", targets: ["OracleNIO"]),
.library(name: "OracleNIOMacros", targets: ["OracleNIOMacros"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-log.git", from: "1.5.4"),
Expand All @@ -19,14 +21,18 @@ let package = Package(
.package(url: "https://github.com/apple/swift-collections.git", from: "1.1.3"),
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.2.0"),
.package(url: "https://github.com/swift-server/swift-service-lifecycle.git", from: "2.6.0"),
.package(
url: "https://github.com/swiftlang/swift-syntax.git",
"509.0.0-latest"..."600.0.0-latest"),
],
targets: [
.target(
name: "VendoredConnectionPoolModule",
name: "_ConnectionPoolModule",
dependencies: [
.product(name: "Atomics", package: "swift-atomics"),
.product(name: "DequeModule", package: "swift-collections"),
]
],
path: "Sources/VendoredConnectionPoolModule"
),
.target(name: "_PBKDF2", dependencies: [.product(name: "Crypto", package: "swift-crypto")]),
.testTarget(name: "_PBKDF2Tests", dependencies: ["_PBKDF2"]),
Expand All @@ -43,7 +49,7 @@ let package = Package(
.product(name: "Crypto", package: "swift-crypto"),
.product(name: "_CryptoExtras", package: "swift-crypto"),
.product(name: "ServiceLifecycle", package: "swift-service-lifecycle"),
"_PBKDF2", "VendoredConnectionPoolModule",
"_PBKDF2", "_ConnectionPoolModule",
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency=complete"),
Expand All @@ -59,8 +65,26 @@ let package = Package(
),
.testTarget(
name: "IntegrationTests",
dependencies: ["OracleNIO"],
dependencies: ["OracleNIO", "OracleNIOMacros"],
resources: [.process("Data")]
),
.target(
name: "OracleNIOMacros",
dependencies: ["OracleNIO", "OracleNIOMacrosPlugin"]
),
.macro(
name: "OracleNIOMacrosPlugin",
dependencies: [
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
]
),
.testTarget(
name: "OracleNIOMacrosTests",
dependencies: [
.product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"),
"OracleNIOMacrosPlugin",
]
),
]
)
16 changes: 15 additions & 1 deletion Sources/OracleNIO/Connection/OracleConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import class Foundation.ProcessInfo
/// ## Usage
///
/// Now you can use the connection to run queries on your database using
/// ``OracleConnection/execute(_:options:logger:file:line:)``.
/// ``OracleConnection/execute(_:options:logger:file:line:)-vguo``.
///
/// @Snippet(path: "oracle-nio/Snippets/OracleConnection", slice: "use")
///
Expand Down Expand Up @@ -474,6 +474,20 @@ extension OracleConnection {
}
}

/// Execute a prepared statement.
public func execute<Statement: OraclePreparedStatement, Row>(
_ statement: Statement,
options: StatementOptions = .init(),
logger: Logger? = nil,
file: String = #fileID, line: Int = #line
) async throws -> AsyncThrowingMapSequence<OracleRowSequence, Row> where Row == Statement.Row {
let sendableStatement = try OracleStatement(
unsafeSQL: Statement.sql, binds: statement.makeBindings())
let stream: OracleRowSequence = try await execute(
sendableStatement, options: options, logger: logger, file: file, line: line)
return stream.map { try statement.decodeRow($0) }
}

func execute(
cursor: Cursor,
options: StatementOptions = .init(),
Expand Down
2 changes: 1 addition & 1 deletion Sources/OracleNIO/Data/LOB.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ extension LOB {
///
/// - Parameters:
/// - chunkSize: The size of a single chunk of data read from the database.
/// If empty, ``chunkSize`` will be used.
/// If empty, a sensible default will be used.
/// - connection: The connection used the stream the buffer from.
/// This has to be the same one the LOB reference was created on.
/// - Returns: An async sequence used to iterate over
Expand Down
7 changes: 5 additions & 2 deletions Sources/OracleNIO/Documentation.docc/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Oracle Database 12.1 or later.
- ``OracleCell``
- ``OracleColumn``
- ``StatementOptions``
- ``OraclePreparedStatement``
- ``Statement(_:)``

### Encoding and Decoding

Expand All @@ -58,15 +60,16 @@ Oracle Database 12.1 or later.
- ``OracleDecodable``
- ``OracleDecodingContext``
- ``OracleCodable``
- ``OracleJSONEncoder``
- ``OracleJSONDecoder``
- ``OracleDataType``
- ``OracleDataTypeNumber``
- ``OracleNumber``
- ``OracleRef``
- ``Cursor``
- ``RowID``
- ``IntervalDS``
- ``OracleJSON``
- ``OracleVectorProtocol``
- ``OracleVectorBinary``
- ``OracleVectorInt8``
- ``OracleVectorFloat32``
- ``OracleVectorFloat64``
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# PL/SQL Stored Procedures

You can call PL/SQL stored procedures, functions and anonymous blocks from OracleNIO using ``OracleConnection/execute(_:options:logger:file:line:)``.
You can call PL/SQL stored procedures, functions and anonymous blocks from OracleNIO using ``OracleConnection/execute(_:options:logger:file:line:)-vguo``.

## Overview

Expand Down
15 changes: 12 additions & 3 deletions Sources/OracleNIO/OracleCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ extension OracleCell {
/// Decode the cell into a Swift type, that conforms to ``OracleDecodable``.
///
/// - Parameters:
/// - _: The Swift type, which conforms to ``OracleDecodable``, to decode from the cell's
/// - : The Swift type, which conforms to ``OracleDecodable``, to decode from the cell's
/// ``OracleCell/bytes`` values.
/// - context: A ``OracleDecodingContext`` to supply a custom
/// ``OracleJSONDecoder`` for decoding JSON fields.
/// - context: A ``OracleDecodingContext`` to supply custom properties for decoding.
/// - file: The source file in which this methods was called. Used in the error case in
/// ``OracleDecodingError``.
/// - line: The source file line in which this method was called. Used in the error case in
Expand Down Expand Up @@ -77,6 +76,16 @@ extension OracleCell {
}
}

/// Decode the cell into a Swift type, that conforms to ``OracleDecodable``.
///
/// - Parameters:
/// - : The Swift type, which conforms to ``OracleDecodable``, to decode from the cell's
/// ``OracleCell/bytes`` values.
/// - file: The source file in which this methods was called. Used in the error case in
/// ``OracleDecodingError``.
/// - line: The source file line in which this method was called. Used in the error case in
/// ``OracleDecodingError``.
/// - Returns: A decoded Swift type.
@inlinable
public func decode<T: OracleDecodable>(
_: T.Type, file: String = #fileID, line: Int = #line
Expand Down
7 changes: 3 additions & 4 deletions Sources/OracleNIO/OracleCodable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,14 @@ public protocol OracleDecodable: Sendable {
///
/// This is an escape hatch to prevent a cycle in the conformance of the Optional type to
/// ``OracleDecodable``.
/// `String?` should be OracleDecodable, `String??` should not be ORacleDecodable.
/// `String?` should be OracleDecodable, `String??` should not be OracleDecodable.
associatedtype _DecodableType: OracleDecodable = Self

/// Create an entity from the `ByteBuffer` in Oracle wire format.
/// - Parameters:
/// - byteBuffer: A `ByteBuffer` to decode. The `ByteBuffer` is sliced in such a way that it is expected that the complete buffer is consumed for decoding.
/// - buffer: A `ByteBuffer` to decode. The `ByteBuffer` is sliced in such a way that it is expected that the complete buffer is consumed for decoding.
/// - type: The oracle data type. Depending on this type the `ByteBuffer`'s bytes need to be interpreted in different ways.
/// - format: The oracle wire format.
/// - context: A `OracleDecodingContext` providing context for decoding. This includes a `JSONDecoder` to use when decoding json and metadata to create better errors.
/// - context: A `OracleDecodingContext` providing context for decoding.
init(
from buffer: inout ByteBuffer,
type: OracleDataType,
Expand Down
Loading
Loading