Skip to content

Commit f6c7cc2

Browse files
authored
Rework (#1)
- service -> component
1 parent 37c84c8 commit f6c7cc2

9 files changed

Lines changed: 84 additions & 66 deletions

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
MIT License
22

33
Copyright (c) 2018-2022 Tibor Bödecs
4-
Copyright (c) 2022-2023 Binary Birds Ltd.
4+
Copyright (c) 2022-2024 Binary Birds Ltd.
55

66
Permission is hereby granted, free of charge, to any person
77
obtaining a copy of this software and associated documentation

Package.resolved

Lines changed: 26 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ let package = Package(
1414
.library(name: "FeatherRelationalDatabaseDriverPostgres", targets: ["FeatherRelationalDatabaseDriverPostgres"]),
1515
],
1616
dependencies: [
17-
.package(url: "https://github.com/feather-framework/feather-relational-database", .upToNextMinor(from: "0.1.1")),
18-
.package(url: "https://github.com/vapor/postgres-kit", from: "2.12.0"),
17+
.package(url: "https://github.com/feather-framework/feather-relational-database", .upToNextMinor(from: "0.2.0")),
18+
.package(url: "https://github.com/vapor/postgres-kit", from: "2.0.0"),
1919
],
2020
targets: [
2121
.target(

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Feather SQL Database
22

3-
An abstract sql-database service for Feather CMS.
3+
An abstract sql-database component for Feather CMS.
44

55
## Getting started
66

Sources/FeatherRelationalDatabaseDriverPostgres/Driver/PostgresRelationalDatabaseService.swift renamed to Sources/FeatherRelationalDatabaseDriverPostgres/Driver/PostgresRelationalDatabaseComponent.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
//
2-
// File 2.swift
3-
//
2+
// PostgresRelationalDatabaseComponent.swift
3+
// PostgresRelationalDatabaseDriverPostgres
44
//
55
// Created by Tibor Bodecs on 03/12/2023.
66
//
77

8-
import FeatherService
8+
import FeatherComponent
99
import FeatherRelationalDatabase
1010
import SQLKit
1111
import PostgresKit
1212
@preconcurrency import AsyncKit
1313

1414
@dynamicMemberLookup
15-
struct PostgresRelationalDatabaseService: RelationalDatabaseService {
15+
struct PostgresRelationalDatabaseComponent: RelationalDatabaseComponent {
1616

17-
public let config: ServiceConfig
17+
public let config: ComponentConfig
1818
let pool: EventLoopGroupConnectionPool<PostgresConnectionSource>
1919

2020
subscript<T>(
21-
dynamicMember keyPath: KeyPath<PostgresRelationalDatabaseServiceContext, T>
21+
dynamicMember keyPath: KeyPath<PostgresRelationalDatabaseComponentContext, T>
2222
) -> T {
23-
let context = config.context as! PostgresRelationalDatabaseServiceContext
23+
let context = config.context as! PostgresRelationalDatabaseComponentContext
2424
return context[keyPath: keyPath]
2525
}
2626

2727
init(
28-
config: ServiceConfig,
28+
config: ComponentConfig,
2929
pool: EventLoopGroupConnectionPool<PostgresConnectionSource>
3030
) {
3131
self.config = config
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// PostgresRelationalDatabaseComponentBuilder.swift
3+
// PostgresRelationalDatabaseDriverPostgres
4+
//
5+
// Created by Tibor Bodecs on 18/11/2023.
6+
//
7+
8+
import FeatherComponent
9+
import AsyncKit
10+
import PostgresKit
11+
12+
struct PostgresRelationalDatabaseComponentBuilder: ComponentBuilder {
13+
14+
let context: PostgresRelationalDatabaseComponentContext
15+
let pool: EventLoopGroupConnectionPool<PostgresConnectionSource>
16+
17+
init(context: PostgresRelationalDatabaseComponentContext) {
18+
self.context = context
19+
20+
self.pool = EventLoopGroupConnectionPool(
21+
source: context.connectionSource,
22+
on: context.eventLoopGroup
23+
)
24+
}
25+
26+
func build(using config: ComponentConfig) throws -> Component {
27+
PostgresRelationalDatabaseComponent(config: config, pool: pool)
28+
}
29+
30+
func shutdown() throws {
31+
pool.shutdown()
32+
}
33+
}

Sources/FeatherRelationalDatabaseDriverPostgres/Driver/PostgresRelationalDatabaseServiceContext.swift renamed to Sources/FeatherRelationalDatabaseDriverPostgres/Driver/PostgresRelationalDatabaseComponentContext.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
//
2-
// SQLDatabaseContext.swift
3-
// FeatherServiceTests
2+
// PostgresRelationalDatabaseComponentContext.swift
3+
// PostgresRelationalDatabaseDriverPostgres
44
//
55
// Created by Tibor Bodecs on 18/11/2023.
66
//
77

8-
import FeatherService
8+
import FeatherComponent
99
@preconcurrency import PostgresKit
1010

11-
public struct PostgresRelationalDatabaseServiceContext: ServiceContext {
11+
public struct PostgresRelationalDatabaseComponentContext: ComponentContext {
1212

1313
let eventLoopGroup: EventLoopGroup
1414
let connectionSource: PostgresConnectionSource
@@ -21,7 +21,7 @@ public struct PostgresRelationalDatabaseServiceContext: ServiceContext {
2121
self.connectionSource = connectionSource
2222
}
2323

24-
public func make() throws -> ServiceBuilder {
25-
PostgresRelationalDatabaseServiceBuilder(context: self)
24+
public func make() throws -> ComponentBuilder {
25+
PostgresRelationalDatabaseComponentBuilder(context: self)
2626
}
2727
}

Sources/FeatherRelationalDatabaseDriverPostgres/Driver/PostgresRelationalDatabaseServiceBuilder.swift

Lines changed: 0 additions & 33 deletions
This file was deleted.

Tests/FeatherRelationalDatabaseDriverPostgresTests/FeatherRelationalDatabaseDriverPostgresTests.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//
2-
// FeatherSQLDatabaseTests.swift
3-
// FeatherSQLDatabaseTests
2+
// FeatherRelationalDatabaseDriverPostgresTests.swift
3+
// FeatherRelationalDatabaseDriverPostgresTests
44
//
55
// Created by Tibor Bodecs on 2023. 01. 16..
66
//
77

88
import NIO
99
import XCTest
10-
import FeatherService
10+
import FeatherComponent
1111
import FeatherRelationalDatabase
1212
import FeatherRelationalDatabaseDriverPostgres
1313
import PostgresKit
@@ -32,7 +32,7 @@ final class FeatherRelationalDatabaseDriverPostgresTests: XCTestCase {
3232

3333
func testExample() async throws {
3434
do {
35-
let registry = ServiceRegistry()
35+
let registry = ComponentRegistry()
3636

3737
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
3838
let threadPool = NIOThreadPool(numberOfThreads: 1)
@@ -51,15 +51,15 @@ final class FeatherRelationalDatabaseDriverPostgresTests: XCTestCase {
5151
)
5252

5353
try await registry.addRelationalDatabase(
54-
PostgresRelationalDatabaseServiceContext(
54+
PostgresRelationalDatabaseComponentContext(
5555
eventLoopGroup: eventLoopGroup,
5656
connectionSource: connectionSource
5757
)
5858
)
5959

6060
try await registry.run()
61-
let dbService = try await registry.relationalDatabase()
62-
let db = try await dbService.connection()
61+
let dbComponent = try await registry.relationalDatabase()
62+
let db = try await dbComponent.connection()
6363

6464
do {
6565

0 commit comments

Comments
 (0)