Skip to content
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
6 changes: 3 additions & 3 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/apple/swift-log", from: "1.6.0"),
.package(url: "https://github.com/vapor/postgres-nio", from: "1.27.0"),
.package(url: "https://github.com/feather-framework/feather-database", exact: "1.0.0-beta.3"),
.package(url: "https://github.com/feather-framework/feather-database", exact: "1.0.0-beta.4"),
// [docc-plugin-placeholder]
],
targets: [
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

Postgres driver implementation for the abstract [Feather Database](https://github.com/feather-framework/feather-database) Swift API package.

[![Release: 1.0.0-beta.2](https://img.shields.io/badge/Release-1%2E0%2E0--beta%2E2-F05138)](https://github.com/feather-framework/feather-postgres-database/releases/tag/1.0.0-beta.2)
[
![Release: 1.0.0-beta.3](https://img.shields.io/badge/Release-1%2E0%2E0--beta%2E3-F05138)
](
https://github.com/feather-framework/feather-postgres-database/releases/tag/1.0.0-beta.3
)

## Features

Expand Down Expand Up @@ -33,7 +37,7 @@ Postgres driver implementation for the abstract [Feather Database](https://githu
Add the dependency to your `Package.swift`:

```swift
.package(url: "https://github.com/feather-framework/feather-postgres-database", exact: "1.0.0-beta.2"),
.package(url: "https://github.com/feather-framework/feather-postgres-database", exact: "1.0.0-beta.3"),
```

Then add `FeatherPostgresDatabase` to your target dependencies:
Expand Down
38 changes: 32 additions & 6 deletions Sources/FeatherPostgresDatabase/PostgresDatabaseConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,38 @@
import FeatherDatabase
import PostgresNIO

extension DatabaseQuery {

fileprivate func toPostgresQuery() -> PostgresQuery {
var postgresUnsafeSQL = sql
var postgresBindings: PostgresBindings = .init()

for binding in bindings {
/// postgres binding index starts with 1
let idx = binding.index + 1
postgresUnsafeSQL =
postgresUnsafeSQL
.replacing("{{\(idx)}}", with: "$\(idx)")

switch binding.binding {
case .int(let value):
postgresBindings.append(value)
case .double(let value):
postgresBindings.append(value)
case .string(let value):
postgresBindings.append(value)
}
}

return .init(
unsafeSQL: postgresUnsafeSQL,
binds: postgresBindings
)
}
}

public struct PostgresDatabaseConnection: DatabaseConnection {

public typealias Query = PostgresDatabaseQuery
public typealias RowSequence = PostgresDatabaseRowSequence

var connection: PostgresConnection
Expand All @@ -26,15 +55,12 @@ public struct PostgresDatabaseConnection: DatabaseConnection {
/// - Returns: A query result containing the returned rows.
@discardableResult
public func run<T: Sendable>(
query: Query,
query: DatabaseQuery,
_ handler: (RowSequence) async throws -> T = { $0 }
) async throws(DatabaseError) -> T {
do {
let sequence = try await connection.query(
.init(
unsafeSQL: query.sql,
binds: query.bindings
),
query.toPostgresQuery(),
logger: logger
)

Expand Down
159 changes: 0 additions & 159 deletions Sources/FeatherPostgresDatabase/PostgresDatabaseQuery.swift

This file was deleted.